From a2d59516c8893167bbad85d05bf9984c345d3378 Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Mon, 4 Sep 2023 10:03:25 +0200 Subject: [PATCH 1/3] Add destinations command to display available destinations --- .gitignore | 2 ++ lib/kamal/cli/main.rb | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/.gitignore b/.gitignore index 6100dc738..cb7c50d1f 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ coverage/* .DS_Store gemfiles/*.lock + +.idea/ diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index 29218d9d3..f5dd63d20 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -10,6 +10,19 @@ def setup end end + desc 'destinations', 'List available destinations' + option :json, alias: '-j', type: :boolean, default: false, desc: 'Output as JSON' + def destinations + pattern = options[:config_file].gsub(/deploy\.yml/, 'deploy.*.yml') + list = Dir.glob(pattern).map { |f| File.basename(f, '.yml.erb').gsub(/^deploy\./, '') } + + if options[:json] + puts list.to_json + else + puts list + end + end + desc "deploy", "Deploy app to servers" option :skip_push, aliases: "-P", type: :boolean, default: false, desc: "Skip image build and push" def deploy From b21117c381afa51f3a1db89f6450752937f4db4a Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Mon, 2 Oct 2023 10:27:05 +0200 Subject: [PATCH 2/3] Fix PR comments --- .gitignore | 2 -- lib/kamal/cli/main.rb | 8 ++++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index cb7c50d1f..6100dc738 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,3 @@ coverage/* .DS_Store gemfiles/*.lock - -.idea/ diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index f5dd63d20..f8cdc851a 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -10,11 +10,11 @@ def setup end end - desc 'destinations', 'List available destinations' - option :json, alias: '-j', type: :boolean, default: false, desc: 'Output as JSON' + desc "destinations", "List available destinations" + option :json, alias: "-j", type: :boolean, default: false, desc: "Output as JSON" def destinations - pattern = options[:config_file].gsub(/deploy\.yml/, 'deploy.*.yml') - list = Dir.glob(pattern).map { |f| File.basename(f, '.yml.erb').gsub(/^deploy\./, '') } + pattern = options[:config_file].gsub(/deploy\.yml/, "deploy.*.yml") + list = Dir.glob(pattern).map { |f| File.basename(f, ".yml.erb").gsub(/^deploy\./, "") } if options[:json] puts list.to_json From d0fab4731c10dcfa6fde6da5fa1673e0aa92b17a Mon Sep 17 00:00:00 2001 From: Fran Zekan Date: Mon, 25 Dec 2023 11:20:06 +0100 Subject: [PATCH 3/3] Add tests + fix alias --- lib/kamal/cli/main.rb | 13 ++++++++++--- test/cli/main_test.rb | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/lib/kamal/cli/main.rb b/lib/kamal/cli/main.rb index 372dc3830..89307623c 100644 --- a/lib/kamal/cli/main.rb +++ b/lib/kamal/cli/main.rb @@ -16,10 +16,17 @@ def setup end desc "destinations", "List available destinations" - option :json, alias: "-j", type: :boolean, default: false, desc: "Output as JSON" + option :json, aliases: "-j", type: :boolean, default: false, desc: "Output as JSON" def destinations - pattern = options[:config_file].gsub(/deploy\.yml/, "deploy.*.yml") - list = Dir.glob(pattern).map { |f| File.basename(f, ".yml.erb").gsub(/^deploy\./, "") } + pattern = if options[:config_file].end_with? ".erb" + options[:config_file].gsub(/\.yml\.erb/, ".*.yml.erb") + else + options[:config_file].gsub(/\.yml/, ".*.yml") + end + + list = Dir.glob(pattern).map do |f| + File.basename(f, ".yml.erb").gsub(/\.yml\.erb/, "").gsub(/\.yml/, "").gsub(/^\w*\./, "") + end if options[:json] puts list.to_json diff --git a/test/cli/main_test.rb b/test/cli/main_test.rb index 8b152d52c..903e297e6 100644 --- a/test/cli/main_test.rb +++ b/test/cli/main_test.rb @@ -10,6 +10,22 @@ class CliMainTest < CliTestCase run_command("setup") end + test "destinations" do + run_command("destinations", config_file: "deploy_for_dest").tap do |output| + assert_equal "mars\nworld", output + end + end + + test "destinations --json" do + run_command("destinations", "--json", config_file: "deploy_for_dest").tap do |output| + assert_equal '["mars","world"]', output + end + + run_command("destinations", "-j", config_file: "deploy_for_dest").tap do |output| + assert_equal '["mars","world"]', output + end + end + test "deploy" do invoke_options = { "config_file" => "test/fixtures/deploy_simple.yml", "version" => "999", "skip_hooks" => false }