Skip to content

Commit

Permalink
added experimental functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Dec 9, 2023
1 parent 9b2fb2f commit 19872ee
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
32 changes: 32 additions & 0 deletions experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package carapace

import (
"encoding/json"

"github.com/rsteube/carapace/internal/config"
"github.com/rsteube/carapace/internal/export"
"github.com/rsteube/carapace/pkg/x"
"github.com/spf13/cobra"
)

func init() {
x.ClearStorage = func() {
storage = make(_storage)
}

x.Complete = func(cmd *cobra.Command, args ...string) (*export.Export, error) {
initHelpCompletion(cmd)
action, context := traverse(cmd, args[2:])

if err := config.Load(); err != nil {
return nil, err
}

output := action.Invoke(context).value("export", "")
var e export.Export
if err := json.Unmarshal([]byte(output), &e); err != nil {
return nil, err
}
return &e, nil
}
}
10 changes: 10 additions & 0 deletions pkg/x/x.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Package x contains experimental functions
package x

import (
"github.com/rsteube/carapace/internal/export"
"github.com/spf13/cobra"
)

var ClearStorage func()
var Complete func(cmd *cobra.Command, args ...string) (*export.Export, error)

0 comments on commit 19872ee

Please sign in to comment.