Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix supporting of nested subcommands #165

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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