Skip to content

Commit

Permalink
Merge pull request #955 from rsteube/experimental
Browse files Browse the repository at this point in the history
added experimental functions
  • Loading branch information
rsteube authored Dec 14, 2023
2 parents 0fcdd81 + 19872ee commit 27e49f3
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 27e49f3

Please sign in to comment.