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

feat: Add destinations command #442

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
20 changes: 20 additions & 0 deletions lib/kamal/cli/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def setup
end
end

desc "destinations", "List available destinations"
option :json, aliases: "-j", type: :boolean, default: false, desc: "Output as JSON"
def destinations
Zeko369 marked this conversation as resolved.
Show resolved Hide resolved
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
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
Expand Down
16 changes: 16 additions & 0 deletions test/cli/main_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down