Skip to content

Commit

Permalink
2024.05.03-19:44
Browse files Browse the repository at this point in the history
  • Loading branch information
slankdev committed May 3, 2024
1 parent 361cd1e commit 8854cca
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/vtyang/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,9 @@ func TestPrototype(t *testing.T) {
YangPath: "./testdata/yang/basic",
OutputFile: "./testdata/output/TestPrototype.txt",
Inputs: []string{
"hidden-command-test1",
//"hidden-command-test1",
"configure",
"eval-completion set values crypto",
},
})
}
Expand Down
37 changes: 37 additions & 0 deletions pkg/vtyang/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"
"time"

"github.com/k0kubun/pp"
"github.com/nsf/jsondiff"
"github.com/openconfig/goyang/pkg/yang"
"github.com/pkg/errors"
Expand Down Expand Up @@ -163,6 +164,12 @@ func installCommandsDefault(mode CliMode) {
}
fmt.Fprintf(stdout, "%s\n", string(out))
})

installCommandNoCompletion(mode, "eval-completion", func(args []string) {
clistr := strings.Join(args[1:], " ") + " "
result := doCompletion(clistr, len(clistr))
pp.Println(result)
})
}

func installCommandNoCompletion(mode CliMode, match string,
Expand Down Expand Up @@ -595,6 +602,36 @@ func completer(line string, pos int) (string, []string, string) {
return pre, names, line[pos:]
}

type CompletionResult struct {
// Status
Status string
// Items
Items []CompletionItem `json:",omitempty"`
}

type CompletionItem struct {
Word string `json:",omitempty"`
Helper string `json:",omitempty"`
}

func doCompletion(line string, pos int) CompletionResult {
tree := getCommandNodeCurrent().tree
nodes := tree.Completion(line, pos)

items := []CompletionItem{}
for _, node := range nodes {
items = append(items, CompletionItem{
Word: node.Name,
Helper: node.Description,
})
}
res := CompletionResult{
Items: items,
}
return res
}

// TODO: kore kore
func completionLister(line string, pos int) {
tree := getCommandNodeCurrent().tree
nodes := tree.Completion(line, pos)
Expand Down

0 comments on commit 8854cca

Please sign in to comment.