From 4bbad3120ca14a8184924f80aa3a90b812ce300a Mon Sep 17 00:00:00 2001 From: Misha Merkushin Date: Tue, 7 Nov 2023 15:34:33 +0300 Subject: [PATCH] fix: support nested subcommands --- lib/dip/interaction_tree.rb | 4 ++-- spec/lib/dip/commands/list_spec.rb | 22 +++++++++++++++++++--- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/lib/dip/interaction_tree.rb b/lib/dip/interaction_tree.rb index b49cd5c..1cca14f 100644 --- a/lib/dip/interaction_tree.rb +++ b/lib/dip/interaction_tree.rb @@ -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 diff --git a/spec/lib/dip/commands/list_spec.rb b/spec/lib/dip/commands/list_spec.rb index 36ea49b..44394c5 100644 --- a/spec/lib/dip/commands/list_spec.rb +++ b/spec/lib/dip/commands/list_spec.rb @@ -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 @@ -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