Skip to content

Commit ae5dd23

Browse files
fix: common options are not forwarded to other commands (#207)
1 parent ccc8706 commit ae5dd23

File tree

12 files changed

+51
-15
lines changed

12 files changed

+51
-15
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ CPLN_ORG=your-org-for-tests bundle exec rspec --tag slow
6464
2. Use the `--trace` option to see full logging of HTTP requests. Warning, this will display keys to your logs or console.
6565
1. Add a breakpoint (`debugger`) to any line of code you want to debug.
6666
2. Modify the `lib/command/test.rb` file to trigger the code you want to test. To simulate a command, you can use
67-
`Cpflow::Cli.start` (e.g., `Cpflow::Cli.start(["deploy-image", "-a", "my-app-name"])` would be the same as running
67+
`run_cpflow_command` (e.g., `run_cpflow_command("deploy-image", "-a", "my-app-name")` would be the same as running
6868
`cpflow deploy-image -a my-app-name`).
6969
3. Run the `test` command in your test app with a `.controlplane` directory.
7070

lib/command/base.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ def run_command_in_latest_image(command, title:)
527527
progress.puts("Running #{title}...\n\n")
528528

529529
begin
530-
Cpflow::Cli.start(["run", "-a", config.app, "--image", "latest", "--", command])
530+
run_cpflow_command("run", "-a", config.app, "--image", "latest", "--", command)
531531
rescue SystemExit => e
532532
progress.puts
533533

@@ -536,5 +536,19 @@ def run_command_in_latest_image(command, title:)
536536
progress.puts("Finished running #{title}.\n\n")
537537
end
538538
end
539+
540+
def run_cpflow_command(command, *args)
541+
common_args = []
542+
543+
self.class.common_options.each do |option|
544+
value = config.options[option[:name]]
545+
next if value.nil?
546+
547+
name = "--#{option[:name].to_s.tr('_', '-')}"
548+
common_args.push(name, value)
549+
end
550+
551+
Cpflow::Cli.start([command, *common_args, *args])
552+
end
539553
end
540554
end

lib/command/cleanup_stale_apps.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def confirm_delete
7373
end
7474

7575
def delete_app(app)
76-
Cpflow::Cli.start(["delete", "-a", app, "--yes"])
76+
run_cpflow_command("delete", "-a", app, "--yes")
7777
end
7878
end
7979
end

lib/command/maintenance_off.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def call # rubocop:disable Metrics/MethodLength
3939
cp.fetch_workload!(maintenance_workload)
4040

4141
# Start all other workloads
42-
Cpflow::Cli.start(["ps:start", "-a", config.app, "--wait"])
42+
run_cpflow_command("ps:start", "-a", config.app, "--wait")
4343

4444
progress.puts
4545

@@ -54,7 +54,7 @@ def call # rubocop:disable Metrics/MethodLength
5454
progress.puts
5555

5656
# Stop maintenance workload
57-
Cpflow::Cli.start(["ps:stop", "-a", config.app, "-w", maintenance_workload, "--wait"])
57+
run_cpflow_command("ps:stop", "-a", config.app, "-w", maintenance_workload, "--wait")
5858

5959
progress.puts("\nMaintenance mode disabled for app '#{config.app}'.")
6060
end

lib/command/maintenance_on.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def call # rubocop:disable Metrics/MethodLength
3939
cp.fetch_workload!(maintenance_workload)
4040

4141
# Start maintenance workload
42-
Cpflow::Cli.start(["ps:start", "-a", config.app, "-w", maintenance_workload, "--wait"])
42+
run_cpflow_command("ps:start", "-a", config.app, "-w", maintenance_workload, "--wait")
4343

4444
progress.puts
4545

@@ -54,7 +54,7 @@ def call # rubocop:disable Metrics/MethodLength
5454
progress.puts
5555

5656
# Stop all other workloads
57-
Cpflow::Cli.start(["ps:stop", "-a", config.app, "--wait"])
57+
run_cpflow_command("ps:stop", "-a", config.app, "--wait")
5858

5959
progress.puts("\nMaintenance mode enabled for app '#{config.app}'.")
6060
end

lib/command/no_command.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ class NoCommand < Base
1414

1515
def call
1616
if config.options[:version]
17-
Cpflow::Cli.start(["version"])
17+
run_cpflow_command("version")
1818
else
19-
Cpflow::Cli.start(["help"])
19+
run_cpflow_command("help")
2020
end
2121
end
2222
end

lib/command/promote_app_from_upstream.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ def call
2525
private
2626

2727
def copy_image_from_upstream
28-
Cpflow::Cli.start(["copy-image-from-upstream", "-a", config.app, "-t", config.options[:upstream_token]])
28+
run_cpflow_command("copy-image-from-upstream", "-a", config.app, "-t", config.options[:upstream_token])
2929
progress.puts
3030
end
3131

3232
def deploy_image
3333
args = []
3434
args.push("--run-release-phase") if config.current[:release_script]
35-
Cpflow::Cli.start(["deploy-image", "-a", config.app, *args])
35+
run_cpflow_command("deploy-image", "-a", config.app, *args)
3636
end
3737
end
3838
end

lib/command/run.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def run_non_interactive_v1 # rubocop:disable Metrics/MethodLength
306306
exit(ExitCode::SUCCESS)
307307
end
308308

309-
Cpflow::Cli.start(["logs", *app_workload_replica_args])
309+
run_cpflow_command("logs", *app_workload_replica_args)
310310
end
311311
Process.detach(logs_pid)
312312

lib/command/setup_app.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def call # rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength
4242

4343
args = []
4444
args.push("--add-app-identity") unless skip_secrets_setup
45-
Cpflow::Cli.start(["apply-template", *templates, "-a", config.app, *args])
45+
run_cpflow_command("apply-template", *templates, "-a", config.app, *args)
4646

4747
bind_identity_to_policy unless skip_secrets_setup
4848
run_post_creation_hook unless config.options[:skip_post_creation_hook]

lib/command/test.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ class Test < Base
1616
def call
1717
# Modify this method to trigger the code you want to test.
1818
# You can use `debugger` to debug.
19-
# You can use `Cpflow::Cli.start` to simulate a command
20-
# (e.g., `Cpflow::Cli.start(["deploy-image", "-a", "my-app-name"])`).
19+
# You can use `run_cpflow_command` to simulate a command
20+
# (e.g., `run_cpflow_command("deploy-image", "-a", "my-app-name")`).
2121
end
2222
end
2323
end

0 commit comments

Comments
 (0)