From 1f83b5f6bea5630fb24f342b1ef9643844b10f3e Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 28 Mar 2023 18:04:14 +0200 Subject: [PATCH] Fix failure to pass on class options to subcommands --- lib/mrsk/cli/base.rb | 6 +++++- test/cli/app_test.rb | 7 +++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/mrsk/cli/base.rb b/lib/mrsk/cli/base.rb index ede29a5c..ee1851bf 100644 --- a/lib/mrsk/cli/base.rb +++ b/lib/mrsk/cli/base.rb @@ -27,7 +27,7 @@ module Mrsk::Cli def initialize(*) super load_envs - initialize_commander(options) + initialize_commander(options_with_subcommand_class_options) end private @@ -39,6 +39,10 @@ module Mrsk::Cli end end + def options_with_subcommand_class_options + options.merge(@_initializer.last[:class_options] || {}) + end + def initialize_commander(options) MRSK.tap do |commander| if options[:verbose] diff --git a/test/cli/app_test.rb b/test/cli/app_test.rb index 41d7ffd0..2dc5ad64 100644 --- a/test/cli/app_test.rb +++ b/test/cli/app_test.rb @@ -121,6 +121,13 @@ class CliAppTest < CliTestCase end end + + test "version through main" do + stdouted { Mrsk::Cli::Main.start(["app", "version", "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1"]) }.tap do |output| + assert_match "docker ps --filter label=service=app --format \"{{.Names}}\" | sed 's/-/\\n/g' | tail -n 1", output + end + end + private def run_command(*command) stdouted { Mrsk::Cli::App.start([*command, "-c", "test/fixtures/deploy_with_accessories.yml", "--hosts", "1.1.1.1"]) }