Skip to content

Commit

Permalink
Merge pull request #165 from bibendi/fix/nested-subcommands
Browse files Browse the repository at this point in the history
Fix supporting of nested subcommands
  • Loading branch information
bibendi authored Nov 7, 2023
2 parents 71de51e + 4bbad31 commit 5619e49
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions lib/dip/interaction_tree.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ def expand(name, entry, tree: {})
cmd = build_command(entry)

tree[name] = cmd
base_cmd = entry.select { |k, _| k != :subcommands }

entry[:subcommands]&.each do |sub_name, sub_entry|
sub_command_defaults!(sub_entry)

expand("#{name} #{sub_name}", entry.deep_merge(sub_entry), tree: tree)
expand("#{name} #{sub_name}", base_cmd.deep_merge(sub_entry), tree: tree)
end

tree
Expand Down
22 changes: 19 additions & 3 deletions spec/lib/dip/commands/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@
service: "web"
}
}
},
test: {
description: "Fire smoke test",
subcommands: {
foo: {
description: "Test Foo locally",
subcommands: {
stage: {
description: "Test Foo on staging"
}
}
}
}
}
}
end
Expand All @@ -26,9 +39,12 @@

it "prints all run commands" do
expected_output = <<~OUT
bash #
rails # Run Rails command
rails s # Run Rails server
bash #
rails # Run Rails command
rails s # Run Rails server
test # Fire smoke test
test foo # Test Foo locally
test foo stage # Test Foo on staging
OUT

expect { cli.start "ls".shellsplit }.to output(expected_output).to_stdout
Expand Down

0 comments on commit 5619e49

Please sign in to comment.