Skip to content

Commit

Permalink
2024.05.05-16:09
Browse files Browse the repository at this point in the history
  • Loading branch information
slankdev committed May 5, 2024
1 parent 6780999 commit b294f37
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/vtyang/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func TestBasicEvalCli01(t *testing.T) {
"eval-cli values items item2",
"eval-cli values items item2 hoge",
"eval-cli values items item2 hoge fuga",
"eval-cli values items item2 hoge fuga des",
},
})
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/vtyang/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,19 @@ func installCommandsDefault(mode CliMode) {
})

installCommandNoCompletion(mode, "eval-cli", func(args []string) {
xpath, val, err := ParseXPathArgs2(dbm, args[1:], true)
xpath, val, tail, err := ParseXPathCli(dbm, args[1:], []string{}, true)
if err != nil {
fmt.Fprintf(stdout, "Error: %s\n", err.Error())
return
}
out, err := json.MarshalIndent(struct {
XPath XPath
Value *DBValue `json:",omitempty"`
Tail []string `json:",omitempty"`
}{
XPath: xpath,
Value: val,
Tail: tail,
}, "", " ")
if err != nil {
fmt.Fprintf(stdout, "Error: %s\n", err.Error())
Expand Down
59 changes: 59 additions & 0 deletions pkg/vtyang/testdata/output/TestBasicEvalCli01.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,62 @@
]
}
}
{
"XPath": {
"Words": [
{
"Module": "main",
"Word": "values",
"Keys": null,
"Dbtype": "container",
"Dbvaluetype": 0
},
{
"Module": "main",
"Word": "items",
"Keys": null,
"Dbtype": "container",
"Dbvaluetype": 0
},
{
"Module": "main",
"Word": "item2",
"Keys": {
"name": {
"Type": 18,
"Int8": 0,
"Int16": 0,
"Int32": 0,
"Int64": 0,
"Uint8": 0,
"Uint16": 0,
"Uint32": 0,
"Uint64": 0,
"String": "hoge",
"Boolean": false,
"Decimal64": 0
},
"type": {
"Type": 18,
"Int8": 0,
"Int16": 0,
"Int32": 0,
"Int64": 0,
"Uint8": 0,
"Uint16": 0,
"Uint32": 0,
"Uint64": 0,
"String": "fuga",
"Boolean": false,
"Decimal64": 0
}
},
"Dbtype": "list",
"Dbvaluetype": 0
}
]
},
"Tail": [
"des"
]
}
13 changes: 13 additions & 0 deletions pkg/vtyang/xpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,19 @@ func ParseXPathArgsLongestMatches(dbm *DatabaseManager,
return &xpath, fullmatch, nil
}

func ParseXPathCli(dbm *DatabaseManager, args []string, tail []string, setmode bool,
) (XPath, *DBValue, []string, error) {
if len(args) == 0 {
return XPath{}, nil, tail, nil
}
xpath, val, err := ParseXPathArgs2(dbm, args, setmode)
if err != nil {
tail = append(tail, args[len(args)-1])
return ParseXPathCli(dbm, args[:len(args)-1], tail, setmode)
}
return xpath, val, tail, nil
}

func ParseXPathArgs2(dbm *DatabaseManager, args []string, setmode bool) (XPath, *DBValue, error) {
var xpath XPath
var val *DBValue
Expand Down

0 comments on commit b294f37

Please sign in to comment.