Skip to content

Commit

Permalink
feat: supports the new oneof syntax in commands.json
Browse files Browse the repository at this point in the history
  • Loading branch information
rueian committed Oct 15, 2023
1 parent 57dc9af commit 1e68303
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
21 changes: 17 additions & 4 deletions hack/cmds/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,18 @@ func (n *node) GoStructs() (out []goStruct) {
}

if len(n.Arg.Block) > 0 {
panic("GoStructs should not be called on Block node")
if n.Arg.Type != "oneof" {
panic("GoStructs should not be called on Block node")
}
for child := makeChildNodes(n, n.Arg.Block); child != nil; child = child.Next {
if child.Child != nil {
for _, b := range blockEntries(child) {
out = append(out, b.GoStructs()...)
}
} else {
out = append(out, child.GoStructs()...)
}
}
} else if len(n.Arg.Enum) > 0 {
for _, e := range n.Arg.Enum {
s := goStruct{
Expand Down Expand Up @@ -299,7 +310,7 @@ func (n *node) NextNodes() (nodes []*node) {
parent := n
for parent != nil {
next := parent.Next
for next != nil {
for next != nil && next.Parent.Arg.Type != "oneof" {
nodes = append(nodes, next)
if !next.Arg.Optional {
return nodes
Expand Down Expand Up @@ -926,8 +937,10 @@ func makeChildNodes(parent *node, args []argument) (first *node) {
nodes = append(nodes, &node{Parent: parent, Arg: arg})
}
for i, node := range nodes {
node.Child = makeChildNodes(node, node.Arg.Block)
if len(node.Arg.Block) != 0 && node.Arg.Command != "" {
if node.Arg.Type != "oneof" {
node.Child = makeChildNodes(node, node.Arg.Block)
}
if node.Child != nil && node.Arg.Command != "" {
if node.Child.Arg.Optional {
panic("unexpected block command with optional child")
}
Expand Down
11 changes: 8 additions & 3 deletions internal/cmds/gen_connection.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions internal/cmds/gen_connection_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1e68303

Please sign in to comment.