diff --git a/docs/stackit.md b/docs/stackit.md index 7c7484487..eaa87cd07 100644 --- a/docs/stackit.md +++ b/docs/stackit.md @@ -20,27 +20,41 @@ stackit [flags] -h, --help Help for "stackit" -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") -v, --version Show "stackit" version ``` ### SEE ALSO +* [stackit argus](./stackit_argus.md) - Provides functionality for Argus * [stackit argus](./stackit_argus.md) - Provides functionality for Argus * [stackit auth](./stackit_auth.md) - Provides authentication functionality * [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options * [stackit curl](./stackit_curl.md) - Executes an authenticated HTTP request to an endpoint * [stackit dns](./stackit_dns.md) - Provides functionality for DNS * [stackit logme](./stackit_logme.md) - Provides functionality for LogMe +* [stackit logme](./stackit_logme.md) - Provides functionality for LogMe * [stackit mariadb](./stackit_mariadb.md) - Provides functionality for MariaDB +* [stackit mariadb](./stackit_mariadb.md) - Provides functionality for MariaDB +* [stackit mongodbflex](./stackit_mongodbflex.md) - Provides functionality for MongoDB Flex * [stackit mongodbflex](./stackit_mongodbflex.md) - Provides functionality for MongoDB Flex * [stackit object-storage](./stackit_object-storage.md) - Provides functionality regarding Object Storage +* [stackit object-storage](./stackit_object-storage.md) - Provides functionality regarding Object Storage +* [stackit opensearch](./stackit_opensearch.md) - Provides functionality for OpenSearch * [stackit opensearch](./stackit_opensearch.md) - Provides functionality for OpenSearch * [stackit organization](./stackit_organization.md) - Provides functionality regarding organizations +* [stackit organization](./stackit_organization.md) - Provides functionality regarding organizations +* [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex * [stackit postgresflex](./stackit_postgresflex.md) - Provides functionality for PostgreSQL Flex * [stackit project](./stackit_project.md) - Provides functionality regarding projects * [stackit rabbitmq](./stackit_rabbitmq.md) - Provides functionality for RabbitMQ +* [stackit rabbitmq](./stackit_rabbitmq.md) - Provides functionality for RabbitMQ +* [stackit redis](./stackit_redis.md) - Provides functionality for Redis * [stackit redis](./stackit_redis.md) - Provides functionality for Redis * [stackit secrets-manager](./stackit_secrets-manager.md) - Provides functionality for Secrets Manager +* [stackit secrets-manager](./stackit_secrets-manager.md) - Provides functionality for Secrets Manager +* [stackit service-account](./stackit_service-account.md) - Provides functionality for service accounts * [stackit service-account](./stackit_service-account.md) - Provides functionality for service accounts * [stackit ske](./stackit_ske.md) - Provides functionality for SKE +* [stackit ske](./stackit_ske.md) - Provides functionality for SKE diff --git a/docs/stackit_argus.md b/docs/stackit_argus.md index dce4469af..659b1dc36 100644 --- a/docs/stackit_argus.md +++ b/docs/stackit_argus.md @@ -23,6 +23,7 @@ stackit argus [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance.md b/docs/stackit_argus_instance.md index 48adf9968..3d20a2787 100644 --- a/docs/stackit_argus_instance.md +++ b/docs/stackit_argus_instance.md @@ -23,6 +23,7 @@ stackit argus instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance_create.md b/docs/stackit_argus_instance_create.md index ad53baa75..3e5057767 100644 --- a/docs/stackit_argus_instance_create.md +++ b/docs/stackit_argus_instance_create.md @@ -36,6 +36,7 @@ stackit argus instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance_delete.md b/docs/stackit_argus_instance_delete.md index c49d5ec41..b8a250569 100644 --- a/docs/stackit_argus_instance_delete.md +++ b/docs/stackit_argus_instance_delete.md @@ -30,6 +30,7 @@ stackit argus instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance_describe.md b/docs/stackit_argus_instance_describe.md index a32807df0..17ea60e21 100644 --- a/docs/stackit_argus_instance_describe.md +++ b/docs/stackit_argus_instance_describe.md @@ -33,6 +33,7 @@ stackit argus instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance_list.md b/docs/stackit_argus_instance_list.md index 4cdbdc76b..0929847ec 100644 --- a/docs/stackit_argus_instance_list.md +++ b/docs/stackit_argus_instance_list.md @@ -37,6 +37,7 @@ stackit argus instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_instance_update.md b/docs/stackit_argus_instance_update.md index 8fcae4c69..96ad284b9 100644 --- a/docs/stackit_argus_instance_update.md +++ b/docs/stackit_argus_instance_update.md @@ -39,6 +39,7 @@ stackit argus instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_argus_plans.md b/docs/stackit_argus_plans.md index ef4f1f1ad..2e6a0d1b8 100644 --- a/docs/stackit_argus_plans.md +++ b/docs/stackit_argus_plans.md @@ -37,6 +37,7 @@ stackit argus plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_auth.md b/docs/stackit_auth.md index 46572d3dc..fa4410b72 100644 --- a/docs/stackit_auth.md +++ b/docs/stackit_auth.md @@ -23,6 +23,7 @@ stackit auth [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_auth_activate-service-account.md b/docs/stackit_auth_activate-service-account.md index caeedbb47..2d43479ae 100644 --- a/docs/stackit_auth_activate-service-account.md +++ b/docs/stackit_auth_activate-service-account.md @@ -43,6 +43,7 @@ stackit auth activate-service-account [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_auth_login.md b/docs/stackit_auth_login.md index 0972fa9ff..4b6de3dc0 100644 --- a/docs/stackit_auth_login.md +++ b/docs/stackit_auth_login.md @@ -30,6 +30,7 @@ stackit auth login [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_config.md b/docs/stackit_config.md index 5bc626dcc..caa3cb4d5 100644 --- a/docs/stackit_config.md +++ b/docs/stackit_config.md @@ -23,6 +23,7 @@ stackit config [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_config_list.md b/docs/stackit_config_list.md index a07eae30d..bec7341ff 100644 --- a/docs/stackit_config_list.md +++ b/docs/stackit_config_list.md @@ -36,6 +36,7 @@ stackit config list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_config_set.md b/docs/stackit_config_set.md index 3b92975dc..a6aaf0c4a 100644 --- a/docs/stackit_config_set.md +++ b/docs/stackit_config_set.md @@ -55,6 +55,7 @@ stackit config set [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_config_unset.md b/docs/stackit_config_unset.md index b69ab2449..d60cbb881 100644 --- a/docs/stackit_config_unset.md +++ b/docs/stackit_config_unset.md @@ -46,6 +46,7 @@ stackit config unset [flags] --service-account-custom-endpoint SKE API base URL. If unset, uses the default base URL --session-time-limit Maximum time before authentication is required again. If unset, defaults to 2h --ske-custom-endpoint SKE API base URL. If unset, uses the default base URL + --verbosity Verbosity of the CLI ``` ### Options inherited from parent commands diff --git a/docs/stackit_curl.md b/docs/stackit_curl.md index f85017d18..6a9a20839 100644 --- a/docs/stackit_curl.md +++ b/docs/stackit_curl.md @@ -45,6 +45,7 @@ stackit curl URL [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns.md b/docs/stackit_dns.md index 42ea0023d..9303cf1b7 100644 --- a/docs/stackit_dns.md +++ b/docs/stackit_dns.md @@ -23,6 +23,7 @@ stackit dns [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set.md b/docs/stackit_dns_record-set.md index 430588a75..2d139fead 100644 --- a/docs/stackit_dns_record-set.md +++ b/docs/stackit_dns_record-set.md @@ -23,6 +23,7 @@ stackit dns record-set [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set_create.md b/docs/stackit_dns_record-set_create.md index bfb839729..188fd7fff 100644 --- a/docs/stackit_dns_record-set_create.md +++ b/docs/stackit_dns_record-set_create.md @@ -36,6 +36,7 @@ stackit dns record-set create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set_delete.md b/docs/stackit_dns_record-set_delete.md index 2788044ab..20efa762c 100644 --- a/docs/stackit_dns_record-set_delete.md +++ b/docs/stackit_dns_record-set_delete.md @@ -31,6 +31,7 @@ stackit dns record-set delete RECORD_SET_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set_describe.md b/docs/stackit_dns_record-set_describe.md index 9a1d10b46..460fcef18 100644 --- a/docs/stackit_dns_record-set_describe.md +++ b/docs/stackit_dns_record-set_describe.md @@ -34,6 +34,7 @@ stackit dns record-set describe RECORD_SET_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set_list.md b/docs/stackit_dns_record-set_list.md index af5db51e1..d3022de88 100644 --- a/docs/stackit_dns_record-set_list.md +++ b/docs/stackit_dns_record-set_list.md @@ -50,6 +50,7 @@ stackit dns record-set list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_record-set_update.md b/docs/stackit_dns_record-set_update.md index 88f1c649b..02a46c259 100644 --- a/docs/stackit_dns_record-set_update.md +++ b/docs/stackit_dns_record-set_update.md @@ -35,6 +35,7 @@ stackit dns record-set update RECORD_SET_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone.md b/docs/stackit_dns_zone.md index a1f3be24c..8ec757d39 100644 --- a/docs/stackit_dns_zone.md +++ b/docs/stackit_dns_zone.md @@ -23,6 +23,7 @@ stackit dns zone [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone_create.md b/docs/stackit_dns_zone_create.md index 7d33dc0b3..2b8f6c52e 100644 --- a/docs/stackit_dns_zone_create.md +++ b/docs/stackit_dns_zone_create.md @@ -46,6 +46,7 @@ stackit dns zone create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone_delete.md b/docs/stackit_dns_zone_delete.md index 24229b09d..6828c9af5 100644 --- a/docs/stackit_dns_zone_delete.md +++ b/docs/stackit_dns_zone_delete.md @@ -30,6 +30,7 @@ stackit dns zone delete ZONE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone_describe.md b/docs/stackit_dns_zone_describe.md index 3423b55d9..f25be20a4 100644 --- a/docs/stackit_dns_zone_describe.md +++ b/docs/stackit_dns_zone_describe.md @@ -33,6 +33,7 @@ stackit dns zone describe ZONE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone_list.md b/docs/stackit_dns_zone_list.md index 117a5db3f..9c5dfa8bb 100644 --- a/docs/stackit_dns_zone_list.md +++ b/docs/stackit_dns_zone_list.md @@ -46,6 +46,7 @@ stackit dns zone list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_dns_zone_update.md b/docs/stackit_dns_zone_update.md index 4fae3a043..35d6d91c5 100644 --- a/docs/stackit_dns_zone_update.md +++ b/docs/stackit_dns_zone_update.md @@ -40,6 +40,7 @@ stackit dns zone update ZONE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme.md b/docs/stackit_logme.md index e8f608799..7e5f8358f 100644 --- a/docs/stackit_logme.md +++ b/docs/stackit_logme.md @@ -23,6 +23,7 @@ stackit logme [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_credentials.md b/docs/stackit_logme_credentials.md index f36d81fa8..231a0c710 100644 --- a/docs/stackit_logme_credentials.md +++ b/docs/stackit_logme_credentials.md @@ -23,6 +23,7 @@ stackit logme credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_credentials_create.md b/docs/stackit_logme_credentials_create.md index 8f16774a4..305170c26 100644 --- a/docs/stackit_logme_credentials_create.md +++ b/docs/stackit_logme_credentials_create.md @@ -35,6 +35,7 @@ stackit logme credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_credentials_delete.md b/docs/stackit_logme_credentials_delete.md index bf8f3c99a..5fef29f7e 100644 --- a/docs/stackit_logme_credentials_delete.md +++ b/docs/stackit_logme_credentials_delete.md @@ -31,6 +31,7 @@ stackit logme credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_credentials_describe.md b/docs/stackit_logme_credentials_describe.md index 5f59b5290..e7b25c6b5 100644 --- a/docs/stackit_logme_credentials_describe.md +++ b/docs/stackit_logme_credentials_describe.md @@ -34,6 +34,7 @@ stackit logme credentials describe CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_credentials_list.md b/docs/stackit_logme_credentials_list.md index aa4738e1f..9eeaa1917 100644 --- a/docs/stackit_logme_credentials_list.md +++ b/docs/stackit_logme_credentials_list.md @@ -38,6 +38,7 @@ stackit logme credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance.md b/docs/stackit_logme_instance.md index 23ddaad8d..2ea19539f 100644 --- a/docs/stackit_logme_instance.md +++ b/docs/stackit_logme_instance.md @@ -23,6 +23,7 @@ stackit logme instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance_create.md b/docs/stackit_logme_instance_create.md index ba315784b..1a2866bf0 100644 --- a/docs/stackit_logme_instance_create.md +++ b/docs/stackit_logme_instance_create.md @@ -48,6 +48,7 @@ stackit logme instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance_delete.md b/docs/stackit_logme_instance_delete.md index 2a9ac994e..5cb5f98e0 100644 --- a/docs/stackit_logme_instance_delete.md +++ b/docs/stackit_logme_instance_delete.md @@ -30,6 +30,7 @@ stackit logme instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance_describe.md b/docs/stackit_logme_instance_describe.md index cad16a54f..4aa4e2c65 100644 --- a/docs/stackit_logme_instance_describe.md +++ b/docs/stackit_logme_instance_describe.md @@ -33,6 +33,7 @@ stackit logme instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance_list.md b/docs/stackit_logme_instance_list.md index 556975244..ab637f5db 100644 --- a/docs/stackit_logme_instance_list.md +++ b/docs/stackit_logme_instance_list.md @@ -37,6 +37,7 @@ stackit logme instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_instance_update.md b/docs/stackit_logme_instance_update.md index afac87e8f..88e0ebec7 100644 --- a/docs/stackit_logme_instance_update.md +++ b/docs/stackit_logme_instance_update.md @@ -44,6 +44,7 @@ stackit logme instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_logme_plans.md b/docs/stackit_logme_plans.md index 82a2290a1..28b848cc4 100644 --- a/docs/stackit_logme_plans.md +++ b/docs/stackit_logme_plans.md @@ -37,6 +37,7 @@ stackit logme plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb.md b/docs/stackit_mariadb.md index d7c2c7daa..2b7709a60 100644 --- a/docs/stackit_mariadb.md +++ b/docs/stackit_mariadb.md @@ -23,6 +23,7 @@ stackit mariadb [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_credentials.md b/docs/stackit_mariadb_credentials.md index d32ee88ab..e8f0285e2 100644 --- a/docs/stackit_mariadb_credentials.md +++ b/docs/stackit_mariadb_credentials.md @@ -23,6 +23,7 @@ stackit mariadb credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_credentials_create.md b/docs/stackit_mariadb_credentials_create.md index 6d995122e..315fca3fd 100644 --- a/docs/stackit_mariadb_credentials_create.md +++ b/docs/stackit_mariadb_credentials_create.md @@ -35,6 +35,7 @@ stackit mariadb credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_credentials_delete.md b/docs/stackit_mariadb_credentials_delete.md index 38c15d7c8..22975aaa7 100644 --- a/docs/stackit_mariadb_credentials_delete.md +++ b/docs/stackit_mariadb_credentials_delete.md @@ -31,6 +31,7 @@ stackit mariadb credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_credentials_describe.md b/docs/stackit_mariadb_credentials_describe.md index 7e341c47f..6e0875f03 100644 --- a/docs/stackit_mariadb_credentials_describe.md +++ b/docs/stackit_mariadb_credentials_describe.md @@ -34,6 +34,7 @@ stackit mariadb credentials describe CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_credentials_list.md b/docs/stackit_mariadb_credentials_list.md index b88ba0085..6aa015e99 100644 --- a/docs/stackit_mariadb_credentials_list.md +++ b/docs/stackit_mariadb_credentials_list.md @@ -38,6 +38,7 @@ stackit mariadb credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance.md b/docs/stackit_mariadb_instance.md index 877fca711..1c2c698e2 100644 --- a/docs/stackit_mariadb_instance.md +++ b/docs/stackit_mariadb_instance.md @@ -23,6 +23,7 @@ stackit mariadb instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance_create.md b/docs/stackit_mariadb_instance_create.md index bbc0ddcac..07e1fbf3e 100644 --- a/docs/stackit_mariadb_instance_create.md +++ b/docs/stackit_mariadb_instance_create.md @@ -48,6 +48,7 @@ stackit mariadb instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance_delete.md b/docs/stackit_mariadb_instance_delete.md index f5ee1cde5..4d2bb23f9 100644 --- a/docs/stackit_mariadb_instance_delete.md +++ b/docs/stackit_mariadb_instance_delete.md @@ -30,6 +30,7 @@ stackit mariadb instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance_describe.md b/docs/stackit_mariadb_instance_describe.md index 53502fafc..55ebbe66e 100644 --- a/docs/stackit_mariadb_instance_describe.md +++ b/docs/stackit_mariadb_instance_describe.md @@ -33,6 +33,7 @@ stackit mariadb instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance_list.md b/docs/stackit_mariadb_instance_list.md index cf7e68bdd..d4619f56f 100644 --- a/docs/stackit_mariadb_instance_list.md +++ b/docs/stackit_mariadb_instance_list.md @@ -37,6 +37,7 @@ stackit mariadb instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_instance_update.md b/docs/stackit_mariadb_instance_update.md index e6056f920..6a7349d99 100644 --- a/docs/stackit_mariadb_instance_update.md +++ b/docs/stackit_mariadb_instance_update.md @@ -44,6 +44,7 @@ stackit mariadb instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mariadb_plans.md b/docs/stackit_mariadb_plans.md index 461a3255e..7b1093f29 100644 --- a/docs/stackit_mariadb_plans.md +++ b/docs/stackit_mariadb_plans.md @@ -37,6 +37,7 @@ stackit mariadb plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex.md b/docs/stackit_mongodbflex.md index 0c37c699d..ace82c1e0 100644 --- a/docs/stackit_mongodbflex.md +++ b/docs/stackit_mongodbflex.md @@ -23,6 +23,7 @@ stackit mongodbflex [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance.md b/docs/stackit_mongodbflex_instance.md index 19812fbcd..c83b6df65 100644 --- a/docs/stackit_mongodbflex_instance.md +++ b/docs/stackit_mongodbflex_instance.md @@ -23,6 +23,7 @@ stackit mongodbflex instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance_create.md b/docs/stackit_mongodbflex_instance_create.md index e8303cc04..b17228451 100644 --- a/docs/stackit_mongodbflex_instance_create.md +++ b/docs/stackit_mongodbflex_instance_create.md @@ -46,6 +46,7 @@ stackit mongodbflex instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance_delete.md b/docs/stackit_mongodbflex_instance_delete.md index e76b5ab16..ef97025ed 100644 --- a/docs/stackit_mongodbflex_instance_delete.md +++ b/docs/stackit_mongodbflex_instance_delete.md @@ -30,6 +30,7 @@ stackit mongodbflex instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance_describe.md b/docs/stackit_mongodbflex_instance_describe.md index 2c8279416..a59b2eb36 100644 --- a/docs/stackit_mongodbflex_instance_describe.md +++ b/docs/stackit_mongodbflex_instance_describe.md @@ -33,6 +33,7 @@ stackit mongodbflex instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance_list.md b/docs/stackit_mongodbflex_instance_list.md index 84cd06230..d3312d8e2 100644 --- a/docs/stackit_mongodbflex_instance_list.md +++ b/docs/stackit_mongodbflex_instance_list.md @@ -37,6 +37,7 @@ stackit mongodbflex instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_instance_update.md b/docs/stackit_mongodbflex_instance_update.md index 5bd740a6e..3eecbfd0f 100644 --- a/docs/stackit_mongodbflex_instance_update.md +++ b/docs/stackit_mongodbflex_instance_update.md @@ -43,6 +43,7 @@ stackit mongodbflex instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_options.md b/docs/stackit_mongodbflex_options.md index e202e1800..dbbeeacd1 100644 --- a/docs/stackit_mongodbflex_options.md +++ b/docs/stackit_mongodbflex_options.md @@ -41,6 +41,7 @@ stackit mongodbflex options [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user.md b/docs/stackit_mongodbflex_user.md index df8035128..51827aef3 100644 --- a/docs/stackit_mongodbflex_user.md +++ b/docs/stackit_mongodbflex_user.md @@ -23,6 +23,7 @@ stackit mongodbflex user [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_create.md b/docs/stackit_mongodbflex_user_create.md index c9f3438ab..94621555f 100644 --- a/docs/stackit_mongodbflex_user_create.md +++ b/docs/stackit_mongodbflex_user_create.md @@ -40,6 +40,7 @@ stackit mongodbflex user create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_delete.md b/docs/stackit_mongodbflex_user_delete.md index d9528fa6c..03a7c53bf 100644 --- a/docs/stackit_mongodbflex_user_delete.md +++ b/docs/stackit_mongodbflex_user_delete.md @@ -32,6 +32,7 @@ stackit mongodbflex user delete USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_describe.md b/docs/stackit_mongodbflex_user_describe.md index c155eb2a4..569a874d7 100644 --- a/docs/stackit_mongodbflex_user_describe.md +++ b/docs/stackit_mongodbflex_user_describe.md @@ -36,6 +36,7 @@ stackit mongodbflex user describe USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_list.md b/docs/stackit_mongodbflex_user_list.md index 59b10490e..80fad69cd 100644 --- a/docs/stackit_mongodbflex_user_list.md +++ b/docs/stackit_mongodbflex_user_list.md @@ -38,6 +38,7 @@ stackit mongodbflex user list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_reset-password.md b/docs/stackit_mongodbflex_user_reset-password.md index be16467e6..7bbafa059 100644 --- a/docs/stackit_mongodbflex_user_reset-password.md +++ b/docs/stackit_mongodbflex_user_reset-password.md @@ -32,6 +32,7 @@ stackit mongodbflex user reset-password USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_mongodbflex_user_update.md b/docs/stackit_mongodbflex_user_update.md index b97404cc5..88569af79 100644 --- a/docs/stackit_mongodbflex_user_update.md +++ b/docs/stackit_mongodbflex_user_update.md @@ -33,6 +33,7 @@ stackit mongodbflex user update USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage.md b/docs/stackit_object-storage.md index d6405ba0c..99334ff5b 100644 --- a/docs/stackit_object-storage.md +++ b/docs/stackit_object-storage.md @@ -23,6 +23,7 @@ stackit object-storage [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_bucket.md b/docs/stackit_object-storage_bucket.md index 2b6bdd595..5dfeb2779 100644 --- a/docs/stackit_object-storage_bucket.md +++ b/docs/stackit_object-storage_bucket.md @@ -23,6 +23,7 @@ stackit object-storage bucket [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_bucket_create.md b/docs/stackit_object-storage_bucket_create.md index 9da2f95f9..dc871a85c 100644 --- a/docs/stackit_object-storage_bucket_create.md +++ b/docs/stackit_object-storage_bucket_create.md @@ -30,6 +30,7 @@ stackit object-storage bucket create BUCKET_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_bucket_delete.md b/docs/stackit_object-storage_bucket_delete.md index 37164afa7..c8ab145cb 100644 --- a/docs/stackit_object-storage_bucket_delete.md +++ b/docs/stackit_object-storage_bucket_delete.md @@ -30,6 +30,7 @@ stackit object-storage bucket delete BUCKET_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_bucket_describe.md b/docs/stackit_object-storage_bucket_describe.md index b6fba771d..ae222de14 100644 --- a/docs/stackit_object-storage_bucket_describe.md +++ b/docs/stackit_object-storage_bucket_describe.md @@ -33,6 +33,7 @@ stackit object-storage bucket describe BUCKET_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_bucket_list.md b/docs/stackit_object-storage_bucket_list.md index 1a29d8424..c81b231ae 100644 --- a/docs/stackit_object-storage_bucket_list.md +++ b/docs/stackit_object-storage_bucket_list.md @@ -37,6 +37,7 @@ stackit object-storage bucket list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials-group.md b/docs/stackit_object-storage_credentials-group.md index 10f8390d6..3ac563bd6 100644 --- a/docs/stackit_object-storage_credentials-group.md +++ b/docs/stackit_object-storage_credentials-group.md @@ -23,6 +23,7 @@ stackit object-storage credentials-group [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials-group_create.md b/docs/stackit_object-storage_credentials-group_create.md index f349b9ddf..78cc1622f 100644 --- a/docs/stackit_object-storage_credentials-group_create.md +++ b/docs/stackit_object-storage_credentials-group_create.md @@ -31,6 +31,7 @@ stackit object-storage credentials-group create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials-group_delete.md b/docs/stackit_object-storage_credentials-group_delete.md index ca82db090..c5911f62d 100644 --- a/docs/stackit_object-storage_credentials-group_delete.md +++ b/docs/stackit_object-storage_credentials-group_delete.md @@ -30,6 +30,7 @@ stackit object-storage credentials-group delete CREDENTIALS_GROUP_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials-group_list.md b/docs/stackit_object-storage_credentials-group_list.md index e6e2b8761..f8f46bad0 100644 --- a/docs/stackit_object-storage_credentials-group_list.md +++ b/docs/stackit_object-storage_credentials-group_list.md @@ -37,6 +37,7 @@ stackit object-storage credentials-group list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials.md b/docs/stackit_object-storage_credentials.md index 30d360d85..90756eb17 100644 --- a/docs/stackit_object-storage_credentials.md +++ b/docs/stackit_object-storage_credentials.md @@ -23,6 +23,7 @@ stackit object-storage credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials_create.md b/docs/stackit_object-storage_credentials_create.md index 3cecb8be8..155eb44f5 100644 --- a/docs/stackit_object-storage_credentials_create.md +++ b/docs/stackit_object-storage_credentials_create.md @@ -35,6 +35,7 @@ stackit object-storage credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials_delete.md b/docs/stackit_object-storage_credentials_delete.md index bae6b99b1..9d001664a 100644 --- a/docs/stackit_object-storage_credentials_delete.md +++ b/docs/stackit_object-storage_credentials_delete.md @@ -31,6 +31,7 @@ stackit object-storage credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_credentials_list.md b/docs/stackit_object-storage_credentials_list.md index 8882936f7..d826dfa11 100644 --- a/docs/stackit_object-storage_credentials_list.md +++ b/docs/stackit_object-storage_credentials_list.md @@ -38,6 +38,7 @@ stackit object-storage credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_disable.md b/docs/stackit_object-storage_disable.md index 0e7044700..99ba5da28 100644 --- a/docs/stackit_object-storage_disable.md +++ b/docs/stackit_object-storage_disable.md @@ -30,6 +30,7 @@ stackit object-storage disable [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_object-storage_enable.md b/docs/stackit_object-storage_enable.md index dc8632eb6..a602d4c10 100644 --- a/docs/stackit_object-storage_enable.md +++ b/docs/stackit_object-storage_enable.md @@ -30,6 +30,7 @@ stackit object-storage enable [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch.md b/docs/stackit_opensearch.md index bcf2794e6..d2f78e396 100644 --- a/docs/stackit_opensearch.md +++ b/docs/stackit_opensearch.md @@ -23,6 +23,7 @@ stackit opensearch [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_credentials.md b/docs/stackit_opensearch_credentials.md index 24b8227b7..e288e9381 100644 --- a/docs/stackit_opensearch_credentials.md +++ b/docs/stackit_opensearch_credentials.md @@ -23,6 +23,7 @@ stackit opensearch credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_credentials_create.md b/docs/stackit_opensearch_credentials_create.md index c4908e3ef..c69f3b34b 100644 --- a/docs/stackit_opensearch_credentials_create.md +++ b/docs/stackit_opensearch_credentials_create.md @@ -35,6 +35,7 @@ stackit opensearch credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_credentials_delete.md b/docs/stackit_opensearch_credentials_delete.md index 06e579ad3..c752aad12 100644 --- a/docs/stackit_opensearch_credentials_delete.md +++ b/docs/stackit_opensearch_credentials_delete.md @@ -31,6 +31,7 @@ stackit opensearch credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_credentials_describe.md b/docs/stackit_opensearch_credentials_describe.md index 61d8f185f..b34b9c49a 100644 --- a/docs/stackit_opensearch_credentials_describe.md +++ b/docs/stackit_opensearch_credentials_describe.md @@ -34,6 +34,7 @@ stackit opensearch credentials describe CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_credentials_list.md b/docs/stackit_opensearch_credentials_list.md index e42d946f1..5ebc46f3e 100644 --- a/docs/stackit_opensearch_credentials_list.md +++ b/docs/stackit_opensearch_credentials_list.md @@ -38,6 +38,7 @@ stackit opensearch credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance.md b/docs/stackit_opensearch_instance.md index 96ec64f73..d29b9ea95 100644 --- a/docs/stackit_opensearch_instance.md +++ b/docs/stackit_opensearch_instance.md @@ -23,6 +23,7 @@ stackit opensearch instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance_create.md b/docs/stackit_opensearch_instance_create.md index 285522c68..8711afd6d 100644 --- a/docs/stackit_opensearch_instance_create.md +++ b/docs/stackit_opensearch_instance_create.md @@ -48,6 +48,7 @@ stackit opensearch instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance_delete.md b/docs/stackit_opensearch_instance_delete.md index dca9867fb..ce69edff2 100644 --- a/docs/stackit_opensearch_instance_delete.md +++ b/docs/stackit_opensearch_instance_delete.md @@ -30,6 +30,7 @@ stackit opensearch instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance_describe.md b/docs/stackit_opensearch_instance_describe.md index 5e6919b84..e7412f39d 100644 --- a/docs/stackit_opensearch_instance_describe.md +++ b/docs/stackit_opensearch_instance_describe.md @@ -33,6 +33,7 @@ stackit opensearch instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance_list.md b/docs/stackit_opensearch_instance_list.md index 9d51e57a2..4b87294ad 100644 --- a/docs/stackit_opensearch_instance_list.md +++ b/docs/stackit_opensearch_instance_list.md @@ -37,6 +37,7 @@ stackit opensearch instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_instance_update.md b/docs/stackit_opensearch_instance_update.md index d8d1fd7af..82f67acee 100644 --- a/docs/stackit_opensearch_instance_update.md +++ b/docs/stackit_opensearch_instance_update.md @@ -44,6 +44,7 @@ stackit opensearch instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_opensearch_plans.md b/docs/stackit_opensearch_plans.md index 600e4adff..a8a3d26ce 100644 --- a/docs/stackit_opensearch_plans.md +++ b/docs/stackit_opensearch_plans.md @@ -37,6 +37,7 @@ stackit opensearch plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization.md b/docs/stackit_organization.md index 241e52d9b..1cfb74417 100644 --- a/docs/stackit_organization.md +++ b/docs/stackit_organization.md @@ -24,6 +24,7 @@ stackit organization [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_member.md b/docs/stackit_organization_member.md index 07f96a117..6d4cc4708 100644 --- a/docs/stackit_organization_member.md +++ b/docs/stackit_organization_member.md @@ -23,6 +23,7 @@ stackit organization member [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_member_add.md b/docs/stackit_organization_member_add.md index 0cdf77dc8..c70ae9ca6 100644 --- a/docs/stackit_organization_member_add.md +++ b/docs/stackit_organization_member_add.md @@ -36,6 +36,7 @@ stackit organization member add SUBJECT [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_member_list.md b/docs/stackit_organization_member_list.md index 59c92f66b..bfc63fa69 100644 --- a/docs/stackit_organization_member_list.md +++ b/docs/stackit_organization_member_list.md @@ -40,6 +40,7 @@ stackit organization member list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_member_remove.md b/docs/stackit_organization_member_remove.md index 69d028d67..0b0882fbe 100644 --- a/docs/stackit_organization_member_remove.md +++ b/docs/stackit_organization_member_remove.md @@ -38,6 +38,7 @@ stackit organization member remove SUBJECT [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_role.md b/docs/stackit_organization_role.md index 7de5adca7..3eab71957 100644 --- a/docs/stackit_organization_role.md +++ b/docs/stackit_organization_role.md @@ -23,6 +23,7 @@ stackit organization role [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_organization_role_list.md b/docs/stackit_organization_role_list.md index a13b36713..2497c821b 100644 --- a/docs/stackit_organization_role_list.md +++ b/docs/stackit_organization_role_list.md @@ -38,6 +38,7 @@ stackit organization role list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex.md b/docs/stackit_postgresflex.md index f97789144..689ffe638 100644 --- a/docs/stackit_postgresflex.md +++ b/docs/stackit_postgresflex.md @@ -23,6 +23,7 @@ stackit postgresflex [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance.md b/docs/stackit_postgresflex_instance.md index 0d6fa26ea..0dee862d2 100644 --- a/docs/stackit_postgresflex_instance.md +++ b/docs/stackit_postgresflex_instance.md @@ -23,6 +23,7 @@ stackit postgresflex instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_clone.md b/docs/stackit_postgresflex_instance_clone.md index cbc9f1e9b..a972a4f9d 100644 --- a/docs/stackit_postgresflex_instance_clone.md +++ b/docs/stackit_postgresflex_instance_clone.md @@ -39,6 +39,7 @@ stackit postgresflex instance clone INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_create.md b/docs/stackit_postgresflex_instance_create.md index b081370e6..4df9a23c6 100644 --- a/docs/stackit_postgresflex_instance_create.md +++ b/docs/stackit_postgresflex_instance_create.md @@ -46,6 +46,7 @@ stackit postgresflex instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_delete.md b/docs/stackit_postgresflex_instance_delete.md index 21dbbe393..b4b6bb94d 100644 --- a/docs/stackit_postgresflex_instance_delete.md +++ b/docs/stackit_postgresflex_instance_delete.md @@ -36,6 +36,7 @@ stackit postgresflex instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_describe.md b/docs/stackit_postgresflex_instance_describe.md index fba871537..974ba30b3 100644 --- a/docs/stackit_postgresflex_instance_describe.md +++ b/docs/stackit_postgresflex_instance_describe.md @@ -33,6 +33,7 @@ stackit postgresflex instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_list.md b/docs/stackit_postgresflex_instance_list.md index 684eb447b..76ad9d20d 100644 --- a/docs/stackit_postgresflex_instance_list.md +++ b/docs/stackit_postgresflex_instance_list.md @@ -37,6 +37,7 @@ stackit postgresflex instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_instance_update.md b/docs/stackit_postgresflex_instance_update.md index e924673e1..85b627689 100644 --- a/docs/stackit_postgresflex_instance_update.md +++ b/docs/stackit_postgresflex_instance_update.md @@ -43,6 +43,7 @@ stackit postgresflex instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_options.md b/docs/stackit_postgresflex_options.md index 29ff16ede..93733c35f 100644 --- a/docs/stackit_postgresflex_options.md +++ b/docs/stackit_postgresflex_options.md @@ -41,6 +41,7 @@ stackit postgresflex options [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user.md b/docs/stackit_postgresflex_user.md index e23ef514b..01c2e3556 100644 --- a/docs/stackit_postgresflex_user.md +++ b/docs/stackit_postgresflex_user.md @@ -23,6 +23,7 @@ stackit postgresflex user [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_create.md b/docs/stackit_postgresflex_user_create.md index b47e65efa..c8e592906 100644 --- a/docs/stackit_postgresflex_user_create.md +++ b/docs/stackit_postgresflex_user_create.md @@ -39,6 +39,7 @@ stackit postgresflex user create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_delete.md b/docs/stackit_postgresflex_user_delete.md index d505538cb..fc717667a 100644 --- a/docs/stackit_postgresflex_user_delete.md +++ b/docs/stackit_postgresflex_user_delete.md @@ -33,6 +33,7 @@ stackit postgresflex user delete USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_describe.md b/docs/stackit_postgresflex_user_describe.md index 573bc9f57..5467a1cdf 100644 --- a/docs/stackit_postgresflex_user_describe.md +++ b/docs/stackit_postgresflex_user_describe.md @@ -36,6 +36,7 @@ stackit postgresflex user describe USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_list.md b/docs/stackit_postgresflex_user_list.md index e1ee8a156..5be02d3af 100644 --- a/docs/stackit_postgresflex_user_list.md +++ b/docs/stackit_postgresflex_user_list.md @@ -38,6 +38,7 @@ stackit postgresflex user list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_reset-password.md b/docs/stackit_postgresflex_user_reset-password.md index 275988dc4..6198470a5 100644 --- a/docs/stackit_postgresflex_user_reset-password.md +++ b/docs/stackit_postgresflex_user_reset-password.md @@ -32,6 +32,7 @@ stackit postgresflex user reset-password USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_postgresflex_user_update.md b/docs/stackit_postgresflex_user_update.md index 5f323978d..ddc9b3156 100644 --- a/docs/stackit_postgresflex_user_update.md +++ b/docs/stackit_postgresflex_user_update.md @@ -32,6 +32,7 @@ stackit postgresflex user update USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project.md b/docs/stackit_project.md index fb08e0671..cd1633b15 100644 --- a/docs/stackit_project.md +++ b/docs/stackit_project.md @@ -24,6 +24,7 @@ stackit project [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_create.md b/docs/stackit_project_create.md index a779e2b03..f2eaa69b4 100644 --- a/docs/stackit_project_create.md +++ b/docs/stackit_project_create.md @@ -36,6 +36,7 @@ stackit project create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_delete.md b/docs/stackit_project_delete.md index 6e22b2e0e..42df806c0 100644 --- a/docs/stackit_project_delete.md +++ b/docs/stackit_project_delete.md @@ -33,6 +33,7 @@ stackit project delete [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_describe.md b/docs/stackit_project_describe.md index d2f9f7eb5..807f653e3 100644 --- a/docs/stackit_project_describe.md +++ b/docs/stackit_project_describe.md @@ -37,6 +37,7 @@ stackit project describe [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_list.md b/docs/stackit_project_list.md index 8643290ee..fb84eee4f 100644 --- a/docs/stackit_project_list.md +++ b/docs/stackit_project_list.md @@ -45,6 +45,7 @@ stackit project list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_member.md b/docs/stackit_project_member.md index 30c17e477..2625419cd 100644 --- a/docs/stackit_project_member.md +++ b/docs/stackit_project_member.md @@ -23,6 +23,7 @@ stackit project member [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_member_add.md b/docs/stackit_project_member_add.md index aa1f5dfc1..fa67b1094 100644 --- a/docs/stackit_project_member_add.md +++ b/docs/stackit_project_member_add.md @@ -35,6 +35,7 @@ stackit project member add SUBJECT [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_member_list.md b/docs/stackit_project_member_list.md index 43f371879..811b9f9c4 100644 --- a/docs/stackit_project_member_list.md +++ b/docs/stackit_project_member_list.md @@ -39,6 +39,7 @@ stackit project member list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_member_remove.md b/docs/stackit_project_member_remove.md index e6e15e847..12ba9e232 100644 --- a/docs/stackit_project_member_remove.md +++ b/docs/stackit_project_member_remove.md @@ -37,6 +37,7 @@ stackit project member remove SUBJECT [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_role.md b/docs/stackit_project_role.md index f8843d243..641f0462b 100644 --- a/docs/stackit_project_role.md +++ b/docs/stackit_project_role.md @@ -23,6 +23,7 @@ stackit project role [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_role_list.md b/docs/stackit_project_role_list.md index 1e7dc1367..f4b4cfe8f 100644 --- a/docs/stackit_project_role_list.md +++ b/docs/stackit_project_role_list.md @@ -37,6 +37,7 @@ stackit project role list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_project_update.md b/docs/stackit_project_update.md index c52b2112c..b5ba23cbd 100644 --- a/docs/stackit_project_update.md +++ b/docs/stackit_project_update.md @@ -39,6 +39,7 @@ stackit project update [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq.md b/docs/stackit_rabbitmq.md index f4450278e..fd8ada24d 100644 --- a/docs/stackit_rabbitmq.md +++ b/docs/stackit_rabbitmq.md @@ -23,6 +23,7 @@ stackit rabbitmq [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_credentials.md b/docs/stackit_rabbitmq_credentials.md index 5f8a190fc..004fc8a06 100644 --- a/docs/stackit_rabbitmq_credentials.md +++ b/docs/stackit_rabbitmq_credentials.md @@ -23,6 +23,7 @@ stackit rabbitmq credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_credentials_create.md b/docs/stackit_rabbitmq_credentials_create.md index 0b3787e67..ed14d65ab 100644 --- a/docs/stackit_rabbitmq_credentials_create.md +++ b/docs/stackit_rabbitmq_credentials_create.md @@ -35,6 +35,7 @@ stackit rabbitmq credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_credentials_delete.md b/docs/stackit_rabbitmq_credentials_delete.md index 2818b0585..42827f8d0 100644 --- a/docs/stackit_rabbitmq_credentials_delete.md +++ b/docs/stackit_rabbitmq_credentials_delete.md @@ -31,6 +31,7 @@ stackit rabbitmq credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_credentials_describe.md b/docs/stackit_rabbitmq_credentials_describe.md index 468af2b0c..34b10e786 100644 --- a/docs/stackit_rabbitmq_credentials_describe.md +++ b/docs/stackit_rabbitmq_credentials_describe.md @@ -34,6 +34,7 @@ stackit rabbitmq credentials describe CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_credentials_list.md b/docs/stackit_rabbitmq_credentials_list.md index 78b933e47..2d68213ab 100644 --- a/docs/stackit_rabbitmq_credentials_list.md +++ b/docs/stackit_rabbitmq_credentials_list.md @@ -38,6 +38,7 @@ stackit rabbitmq credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance.md b/docs/stackit_rabbitmq_instance.md index 4beddfe51..15d248621 100644 --- a/docs/stackit_rabbitmq_instance.md +++ b/docs/stackit_rabbitmq_instance.md @@ -23,6 +23,7 @@ stackit rabbitmq instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance_create.md b/docs/stackit_rabbitmq_instance_create.md index 717b8ded8..01172ee58 100644 --- a/docs/stackit_rabbitmq_instance_create.md +++ b/docs/stackit_rabbitmq_instance_create.md @@ -48,6 +48,7 @@ stackit rabbitmq instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance_delete.md b/docs/stackit_rabbitmq_instance_delete.md index 3f5a3851d..e30f84c02 100644 --- a/docs/stackit_rabbitmq_instance_delete.md +++ b/docs/stackit_rabbitmq_instance_delete.md @@ -30,6 +30,7 @@ stackit rabbitmq instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance_describe.md b/docs/stackit_rabbitmq_instance_describe.md index 74e9a1f2d..c292508c1 100644 --- a/docs/stackit_rabbitmq_instance_describe.md +++ b/docs/stackit_rabbitmq_instance_describe.md @@ -33,6 +33,7 @@ stackit rabbitmq instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance_list.md b/docs/stackit_rabbitmq_instance_list.md index 8cb95d860..f587a78a6 100644 --- a/docs/stackit_rabbitmq_instance_list.md +++ b/docs/stackit_rabbitmq_instance_list.md @@ -37,6 +37,7 @@ stackit rabbitmq instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_instance_update.md b/docs/stackit_rabbitmq_instance_update.md index 4021c3adc..c1cf77130 100644 --- a/docs/stackit_rabbitmq_instance_update.md +++ b/docs/stackit_rabbitmq_instance_update.md @@ -44,6 +44,7 @@ stackit rabbitmq instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_rabbitmq_plans.md b/docs/stackit_rabbitmq_plans.md index bf41ffbe8..c6c910167 100644 --- a/docs/stackit_rabbitmq_plans.md +++ b/docs/stackit_rabbitmq_plans.md @@ -37,6 +37,7 @@ stackit rabbitmq plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis.md b/docs/stackit_redis.md index 8fa3bb4c3..253130e76 100644 --- a/docs/stackit_redis.md +++ b/docs/stackit_redis.md @@ -23,6 +23,7 @@ stackit redis [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_credentials.md b/docs/stackit_redis_credentials.md index 31d9245f0..f4eaae021 100644 --- a/docs/stackit_redis_credentials.md +++ b/docs/stackit_redis_credentials.md @@ -23,6 +23,7 @@ stackit redis credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_credentials_create.md b/docs/stackit_redis_credentials_create.md index 7d0117244..deabb8888 100644 --- a/docs/stackit_redis_credentials_create.md +++ b/docs/stackit_redis_credentials_create.md @@ -35,6 +35,7 @@ stackit redis credentials create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_credentials_delete.md b/docs/stackit_redis_credentials_delete.md index fb4a1bd72..73e7aa22d 100644 --- a/docs/stackit_redis_credentials_delete.md +++ b/docs/stackit_redis_credentials_delete.md @@ -31,6 +31,7 @@ stackit redis credentials delete CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_credentials_describe.md b/docs/stackit_redis_credentials_describe.md index 9fb1028df..313c9895a 100644 --- a/docs/stackit_redis_credentials_describe.md +++ b/docs/stackit_redis_credentials_describe.md @@ -34,6 +34,7 @@ stackit redis credentials describe CREDENTIALS_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_credentials_list.md b/docs/stackit_redis_credentials_list.md index 31e0ab33f..c417a5c16 100644 --- a/docs/stackit_redis_credentials_list.md +++ b/docs/stackit_redis_credentials_list.md @@ -38,6 +38,7 @@ stackit redis credentials list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance.md b/docs/stackit_redis_instance.md index 59e565f7e..2876a15f0 100644 --- a/docs/stackit_redis_instance.md +++ b/docs/stackit_redis_instance.md @@ -23,6 +23,7 @@ stackit redis instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance_create.md b/docs/stackit_redis_instance_create.md index 2c5616448..0d33f7727 100644 --- a/docs/stackit_redis_instance_create.md +++ b/docs/stackit_redis_instance_create.md @@ -48,6 +48,7 @@ stackit redis instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance_delete.md b/docs/stackit_redis_instance_delete.md index fda22976d..589af2424 100644 --- a/docs/stackit_redis_instance_delete.md +++ b/docs/stackit_redis_instance_delete.md @@ -30,6 +30,7 @@ stackit redis instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance_describe.md b/docs/stackit_redis_instance_describe.md index 896d64748..50f305096 100644 --- a/docs/stackit_redis_instance_describe.md +++ b/docs/stackit_redis_instance_describe.md @@ -33,6 +33,7 @@ stackit redis instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance_list.md b/docs/stackit_redis_instance_list.md index bc59c1a84..b29669d2e 100644 --- a/docs/stackit_redis_instance_list.md +++ b/docs/stackit_redis_instance_list.md @@ -37,6 +37,7 @@ stackit redis instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_instance_update.md b/docs/stackit_redis_instance_update.md index 7087eaec8..a8bfcd449 100644 --- a/docs/stackit_redis_instance_update.md +++ b/docs/stackit_redis_instance_update.md @@ -44,6 +44,7 @@ stackit redis instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_redis_plans.md b/docs/stackit_redis_plans.md index 6ad8a3afe..de76d3d88 100644 --- a/docs/stackit_redis_plans.md +++ b/docs/stackit_redis_plans.md @@ -37,6 +37,7 @@ stackit redis plans [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager.md b/docs/stackit_secrets-manager.md index 6863d1692..f1e9d3cff 100644 --- a/docs/stackit_secrets-manager.md +++ b/docs/stackit_secrets-manager.md @@ -23,6 +23,7 @@ stackit secrets-manager [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance.md b/docs/stackit_secrets-manager_instance.md index 6fe9357c2..44caf0afa 100644 --- a/docs/stackit_secrets-manager_instance.md +++ b/docs/stackit_secrets-manager_instance.md @@ -23,6 +23,7 @@ stackit secrets-manager instance [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance_create.md b/docs/stackit_secrets-manager_instance_create.md index fde1cdfa0..36d046d11 100644 --- a/docs/stackit_secrets-manager_instance_create.md +++ b/docs/stackit_secrets-manager_instance_create.md @@ -35,6 +35,7 @@ stackit secrets-manager instance create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance_delete.md b/docs/stackit_secrets-manager_instance_delete.md index 72766bc71..99f4a70ae 100644 --- a/docs/stackit_secrets-manager_instance_delete.md +++ b/docs/stackit_secrets-manager_instance_delete.md @@ -30,6 +30,7 @@ stackit secrets-manager instance delete INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance_describe.md b/docs/stackit_secrets-manager_instance_describe.md index 4ddd537fa..2fdf41ac9 100644 --- a/docs/stackit_secrets-manager_instance_describe.md +++ b/docs/stackit_secrets-manager_instance_describe.md @@ -33,6 +33,7 @@ stackit secrets-manager instance describe INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance_list.md b/docs/stackit_secrets-manager_instance_list.md index 2431f2e95..296b321ee 100644 --- a/docs/stackit_secrets-manager_instance_list.md +++ b/docs/stackit_secrets-manager_instance_list.md @@ -37,6 +37,7 @@ stackit secrets-manager instance list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_instance_update.md b/docs/stackit_secrets-manager_instance_update.md index c755bb294..9fa66aa18 100644 --- a/docs/stackit_secrets-manager_instance_update.md +++ b/docs/stackit_secrets-manager_instance_update.md @@ -31,6 +31,7 @@ stackit secrets-manager instance update INSTANCE_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user.md b/docs/stackit_secrets-manager_user.md index 606af1500..0cacab143 100644 --- a/docs/stackit_secrets-manager_user.md +++ b/docs/stackit_secrets-manager_user.md @@ -23,6 +23,7 @@ stackit secrets-manager user [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user_create.md b/docs/stackit_secrets-manager_user_create.md index be7633eb4..c797958de 100644 --- a/docs/stackit_secrets-manager_user_create.md +++ b/docs/stackit_secrets-manager_user_create.md @@ -38,6 +38,7 @@ stackit secrets-manager user create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user_delete.md b/docs/stackit_secrets-manager_user_delete.md index 6181e5b63..539e103b3 100644 --- a/docs/stackit_secrets-manager_user_delete.md +++ b/docs/stackit_secrets-manager_user_delete.md @@ -32,6 +32,7 @@ stackit secrets-manager user delete USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user_describe.md b/docs/stackit_secrets-manager_user_describe.md index e80e781e4..6b10164fd 100644 --- a/docs/stackit_secrets-manager_user_describe.md +++ b/docs/stackit_secrets-manager_user_describe.md @@ -34,6 +34,7 @@ stackit secrets-manager user describe USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user_list.md b/docs/stackit_secrets-manager_user_list.md index a9d8088be..f0e727808 100644 --- a/docs/stackit_secrets-manager_user_list.md +++ b/docs/stackit_secrets-manager_user_list.md @@ -38,6 +38,7 @@ stackit secrets-manager user list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_secrets-manager_user_update.md b/docs/stackit_secrets-manager_user_update.md index 274d6e7c6..b1572b00a 100644 --- a/docs/stackit_secrets-manager_user_update.md +++ b/docs/stackit_secrets-manager_user_update.md @@ -36,6 +36,7 @@ stackit secrets-manager user update USER_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account.md b/docs/stackit_service-account.md index 99eaa4856..c5ec6bb1e 100644 --- a/docs/stackit_service-account.md +++ b/docs/stackit_service-account.md @@ -23,6 +23,7 @@ stackit service-account [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_create.md b/docs/stackit_service-account_create.md index cc7e576fe..2ee156ba4 100644 --- a/docs/stackit_service-account_create.md +++ b/docs/stackit_service-account_create.md @@ -31,6 +31,7 @@ stackit service-account create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_delete.md b/docs/stackit_service-account_delete.md index 8cb35269f..f45a6fd31 100644 --- a/docs/stackit_service-account_delete.md +++ b/docs/stackit_service-account_delete.md @@ -30,6 +30,7 @@ stackit service-account delete EMAIL [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_get-jwks.md b/docs/stackit_service-account_get-jwks.md index 2a648082c..11e299671 100644 --- a/docs/stackit_service-account_get-jwks.md +++ b/docs/stackit_service-account_get-jwks.md @@ -30,6 +30,7 @@ stackit service-account get-jwks EMAIL [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key.md b/docs/stackit_service-account_key.md index e09df2aec..437bb14d8 100644 --- a/docs/stackit_service-account_key.md +++ b/docs/stackit_service-account_key.md @@ -23,6 +23,7 @@ stackit service-account key [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key_create.md b/docs/stackit_service-account_key_create.md index 80c7a7abc..93e137657 100644 --- a/docs/stackit_service-account_key_create.md +++ b/docs/stackit_service-account_key_create.md @@ -41,6 +41,7 @@ stackit service-account key create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key_delete.md b/docs/stackit_service-account_key_delete.md index dd71723bb..a114a37f0 100644 --- a/docs/stackit_service-account_key_delete.md +++ b/docs/stackit_service-account_key_delete.md @@ -31,6 +31,7 @@ stackit service-account key delete KEY_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key_describe.md b/docs/stackit_service-account_key_describe.md index 74050f720..b7d319aca 100644 --- a/docs/stackit_service-account_key_describe.md +++ b/docs/stackit_service-account_key_describe.md @@ -31,6 +31,7 @@ stackit service-account key describe KEY_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key_list.md b/docs/stackit_service-account_key_list.md index 91dc4236a..86e1ad141 100644 --- a/docs/stackit_service-account_key_list.md +++ b/docs/stackit_service-account_key_list.md @@ -38,6 +38,7 @@ stackit service-account key list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_key_update.md b/docs/stackit_service-account_key_update.md index 4fe5dcd48..cec87b91d 100644 --- a/docs/stackit_service-account_key_update.md +++ b/docs/stackit_service-account_key_update.md @@ -41,6 +41,7 @@ stackit service-account key update KEY_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_list.md b/docs/stackit_service-account_list.md index 6794ab457..ad5672095 100644 --- a/docs/stackit_service-account_list.md +++ b/docs/stackit_service-account_list.md @@ -31,6 +31,7 @@ stackit service-account list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_token.md b/docs/stackit_service-account_token.md index edfc3a311..fffcf30eb 100644 --- a/docs/stackit_service-account_token.md +++ b/docs/stackit_service-account_token.md @@ -23,6 +23,7 @@ stackit service-account token [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_token_create.md b/docs/stackit_service-account_token_create.md index a309d8da8..687f6ddfb 100644 --- a/docs/stackit_service-account_token_create.md +++ b/docs/stackit_service-account_token_create.md @@ -37,6 +37,7 @@ stackit service-account token create [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_token_list.md b/docs/stackit_service-account_token_list.md index 1c5bc3006..1ca82934c 100644 --- a/docs/stackit_service-account_token_list.md +++ b/docs/stackit_service-account_token_list.md @@ -40,6 +40,7 @@ stackit service-account token list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_service-account_token_revoke.md b/docs/stackit_service-account_token_revoke.md index 5bea85a2f..c45bf208e 100644 --- a/docs/stackit_service-account_token_revoke.md +++ b/docs/stackit_service-account_token_revoke.md @@ -33,6 +33,7 @@ stackit service-account token revoke TOKEN_ID [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske.md b/docs/stackit_ske.md index 0f3834afc..746ad86bc 100644 --- a/docs/stackit_ske.md +++ b/docs/stackit_ske.md @@ -23,6 +23,7 @@ stackit ske [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster.md b/docs/stackit_ske_cluster.md index 52afd1e82..6f411f89f 100644 --- a/docs/stackit_ske_cluster.md +++ b/docs/stackit_ske_cluster.md @@ -23,6 +23,7 @@ stackit ske cluster [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_create.md b/docs/stackit_ske_cluster_create.md index f1e9db105..d75092c03 100644 --- a/docs/stackit_ske_cluster_create.md +++ b/docs/stackit_ske_cluster_create.md @@ -44,6 +44,7 @@ stackit ske cluster create CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_delete.md b/docs/stackit_ske_cluster_delete.md index ccaaeb399..a14214b9d 100644 --- a/docs/stackit_ske_cluster_delete.md +++ b/docs/stackit_ske_cluster_delete.md @@ -30,6 +30,7 @@ stackit ske cluster delete CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_describe.md b/docs/stackit_ske_cluster_describe.md index 300525f6c..6c94e14a0 100644 --- a/docs/stackit_ske_cluster_describe.md +++ b/docs/stackit_ske_cluster_describe.md @@ -33,6 +33,7 @@ stackit ske cluster describe CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_generate-payload.md b/docs/stackit_ske_cluster_generate-payload.md index 5d18c47d9..28b31e269 100644 --- a/docs/stackit_ske_cluster_generate-payload.md +++ b/docs/stackit_ske_cluster_generate-payload.md @@ -39,6 +39,7 @@ stackit ske cluster generate-payload [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_list.md b/docs/stackit_ske_cluster_list.md index 935ec1a4c..2af049bad 100644 --- a/docs/stackit_ske_cluster_list.md +++ b/docs/stackit_ske_cluster_list.md @@ -37,6 +37,7 @@ stackit ske cluster list [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_cluster_update.md b/docs/stackit_ske_cluster_update.md index de5c9391e..362dc4678 100644 --- a/docs/stackit_ske_cluster_update.md +++ b/docs/stackit_ske_cluster_update.md @@ -41,6 +41,7 @@ stackit ske cluster update CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_credentials.md b/docs/stackit_ske_credentials.md index 8b7c6f4b9..41920d19a 100644 --- a/docs/stackit_ske_credentials.md +++ b/docs/stackit_ske_credentials.md @@ -23,6 +23,7 @@ stackit ske credentials [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_credentials_complete-rotation.md b/docs/stackit_ske_credentials_complete-rotation.md index 404d7509f..583232472 100644 --- a/docs/stackit_ske_credentials_complete-rotation.md +++ b/docs/stackit_ske_credentials_complete-rotation.md @@ -45,6 +45,7 @@ stackit ske credentials complete-rotation CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_credentials_start-rotation.md b/docs/stackit_ske_credentials_start-rotation.md index b1c2cac66..2ae5f6837 100644 --- a/docs/stackit_ske_credentials_start-rotation.md +++ b/docs/stackit_ske_credentials_start-rotation.md @@ -49,6 +49,7 @@ stackit ske credentials start-rotation CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_describe.md b/docs/stackit_ske_describe.md index 529e9f3a1..0220938fc 100644 --- a/docs/stackit_ske_describe.md +++ b/docs/stackit_ske_describe.md @@ -30,6 +30,7 @@ stackit ske describe [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_disable.md b/docs/stackit_ske_disable.md index b4f8d7893..cb5bcfd7f 100644 --- a/docs/stackit_ske_disable.md +++ b/docs/stackit_ske_disable.md @@ -30,6 +30,7 @@ stackit ske disable [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_enable.md b/docs/stackit_ske_enable.md index 53ca100c7..23e07a2a9 100644 --- a/docs/stackit_ske_enable.md +++ b/docs/stackit_ske_enable.md @@ -30,6 +30,7 @@ stackit ske enable [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_kubeconfig.md b/docs/stackit_ske_kubeconfig.md index ec9e7011f..d42c1eaf7 100644 --- a/docs/stackit_ske_kubeconfig.md +++ b/docs/stackit_ske_kubeconfig.md @@ -23,6 +23,7 @@ stackit ske kubeconfig [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_kubeconfig_create.md b/docs/stackit_ske_kubeconfig_create.md index 39718071d..bbd33fa1a 100644 --- a/docs/stackit_ske_kubeconfig_create.md +++ b/docs/stackit_ske_kubeconfig_create.md @@ -46,6 +46,7 @@ stackit ske kubeconfig create CLUSTER_NAME [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/docs/stackit_ske_options.md b/docs/stackit_ske_options.md index 0bde3b8d6..7398a83ad 100644 --- a/docs/stackit_ske_options.md +++ b/docs/stackit_ske_options.md @@ -42,6 +42,7 @@ stackit ske options [flags] --async If set, runs the command asynchronously -o, --output-format string Output format, one of ["json" "pretty"] -p, --project-id string Project ID + --verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info") ``` ### SEE ALSO diff --git a/internal/cmd/argus/argus.go b/internal/cmd/argus/argus.go index 7609c9cfb..38dc77321 100644 --- a/internal/cmd/argus/argus.go +++ b/internal/cmd/argus/argus.go @@ -4,12 +4,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/argus/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "argus", Short: "Provides functionality for Argus", @@ -17,11 +18,11 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(instance.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(instance.NewCmd(p)) } diff --git a/internal/cmd/argus/instance/create/create.go b/internal/cmd/argus/instance/create/create.go index 352e67022..a850a48b2 100644 --- a/internal/cmd/argus/instance/create/create.go +++ b/internal/cmd/argus/instance/create/create.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils" @@ -35,7 +35,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates an Argus instance", @@ -57,19 +57,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create an Argus instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -92,7 +92,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, instanceId, model.ProjectId).WaitWithContext(ctx) if err != nil { @@ -105,7 +105,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/argus/instance/create/create_test.go b/internal/cmd/argus/instance/create/create_test.go index e75827f86..9dd6cd436 100644 --- a/internal/cmd/argus/instance/create/create_test.go +++ b/internal/cmd/argus/instance/create/create_test.go @@ -56,6 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -134,6 +135,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -171,7 +173,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/argus/instance/delete/delete.go b/internal/cmd/argus/instance/delete/delete.go index 345fc7758..4812c7bce 100644 --- a/internal/cmd/argus/instance/delete/delete.go +++ b/internal/cmd/argus/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes an Argus instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.InstanceId, model.ProjectId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/argus/instance/delete/delete_test.go b/internal/cmd/argus/instance/delete/delete_test.go index 5508651cb..502431d5e 100644 --- a/internal/cmd/argus/instance/delete/delete_test.go +++ b/internal/cmd/argus/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/argus/instance/describe/describe.go b/internal/cmd/argus/instance/describe/describe.go index a87826061..7574e1a77 100644 --- a/internal/cmd/argus/instance/describe/describe.go +++ b/internal/cmd/argus/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -26,7 +27,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of an Argus instance", @@ -47,7 +48,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +60,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read Argus instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -84,7 +85,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetInstanceResponse) error { +func outputResult(p *print.Printer, outputFormat string, instance *argus.GetInstanceResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: @@ -109,7 +110,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetIn table.AddSeparator() table.AddRow("GRAFANA URL", *instance.Instance.GrafanaUrl) table.AddSeparator() - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -120,7 +121,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *argus.GetIn if err != nil { return fmt.Errorf("marshal Argus instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/argus/instance/describe/describe_test.go b/internal/cmd/argus/instance/describe/describe_test.go index 0799f8989..ac060428a 100644 --- a/internal/cmd/argus/instance/describe/describe_test.go +++ b/internal/cmd/argus/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/argus/instance/instance.go b/internal/cmd/argus/instance/instance.go index 629c43ad9..af10b9a7c 100644 --- a/internal/cmd/argus/instance/instance.go +++ b/internal/cmd/argus/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/argus/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for Argus instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(update.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(describe.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) } diff --git a/internal/cmd/argus/instance/list/list.go b/internal/cmd/argus/instance/list/list.go index 702172ed2..167ee90e8 100644 --- a/internal/cmd/argus/instance/list/list.go +++ b/internal/cmd/argus/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all Argus instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []argus.ProjectInstanceFull) error { +func outputResult(p *print.Printer, outputFormat string, instances []argus.ProjectInstanceFull) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal Argus instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []argus.Pro instance := instances[i] table.AddRow(*instance.Id, *instance.Name, *instance.PlanName, *instance.Status) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/argus/instance/list/list_test.go b/internal/cmd/argus/instance/list/list_test.go index 1f40779d7..f9a0a0e7c 100644 --- a/internal/cmd/argus/instance/list/list_test.go +++ b/internal/cmd/argus/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/argus/instance/update/update.go b/internal/cmd/argus/instance/update/update.go index a1d807dad..2faec24a7 100644 --- a/internal/cmd/argus/instance/update/update.go +++ b/internal/cmd/argus/instance/update/update.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" argusUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -38,7 +38,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates an Argus instance", @@ -63,7 +63,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -75,7 +75,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -99,7 +99,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.UpdateInstanceWaitHandler(ctx, apiClient, instanceId, model.ProjectId).WaitWithContext(ctx) if err != nil { @@ -112,7 +112,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/argus/instance/update/update_test.go b/internal/cmd/argus/instance/update/update_test.go index 5a2ab1d33..330e6943f 100644 --- a/internal/cmd/argus/instance/update/update_test.go +++ b/internal/cmd/argus/instance/update/update_test.go @@ -82,6 +82,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testNewPlanId), @@ -237,7 +238,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/argus/plans/plans.go b/internal/cmd/argus/plans/plans.go index a74e5c534..ff6d9a1d2 100644 --- a/internal/cmd/argus/plans/plans.go +++ b/internal/cmd/argus/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/argus/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all Argus service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Plans if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []argus.Plan) error { +func outputResult(p *print.Printer, outputFormat string, plans []argus.Plan) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal Argus plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -134,7 +135,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []argus.Plan) e table.AddSeparator() } table.EnableAutoMergeOnColumns(1) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/argus/plans/plans_test.go b/internal/cmd/argus/plans/plans_test.go index d7072ab48..2e6364416 100644 --- a/internal/cmd/argus/plans/plans_test.go +++ b/internal/cmd/argus/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/auth/activate-service-account/activate_service_account.go b/internal/cmd/auth/activate-service-account/activate_service_account.go index ae1b2f537..6f2c5b9db 100644 --- a/internal/cmd/auth/activate-service-account/activate_service_account.go +++ b/internal/cmd/auth/activate-service-account/activate_service_account.go @@ -9,6 +9,7 @@ import ( cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" sdkAuth "github.com/stackitcloud/stackit-sdk-go/core/auth" @@ -31,7 +32,7 @@ type inputModel struct { JwksCustomEndpoint string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "activate-service-account", Short: "Authenticates using a service account", @@ -72,11 +73,12 @@ func NewCmd() *cobra.Command { // Initializes the authentication flow rt, err := sdkAuth.SetupAuth(cfg) if err != nil { + p.Debug(print.ErrorLevel, "setup auth: %v", err) return &cliErr.ActivateServiceAccountError{} } // Authenticates the service account and stores credentials - email, err := auth.AuthenticateServiceAccount(rt) + email, err := auth.AuthenticateServiceAccount(p, rt) if err != nil { var activateServiceAccountError *cliErr.ActivateServiceAccountError if !errors.As(err, &activateServiceAccountError) { @@ -85,7 +87,7 @@ func NewCmd() *cobra.Command { return err } - cmd.Printf("You have been successfully authenticated to the STACKIT CLI!\nService account email: %s\n", email) + p.Info("You have been successfully authenticated to the STACKIT CLI!\nService account email: %s\n", email) return nil }, diff --git a/internal/cmd/auth/activate-service-account/activate_service_account_test.go b/internal/cmd/auth/activate-service-account/activate_service_account_test.go index 912412c56..04f7a9084 100644 --- a/internal/cmd/auth/activate-service-account/activate_service_account_test.go +++ b/internal/cmd/auth/activate-service-account/activate_service_account_test.go @@ -90,7 +90,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/auth/auth.go b/internal/cmd/auth/auth.go index e3215f9e2..cad07aaed 100644 --- a/internal/cmd/auth/auth.go +++ b/internal/cmd/auth/auth.go @@ -4,12 +4,13 @@ import ( activateserviceaccount "github.com/stackitcloud/stackit-cli/internal/cmd/auth/activate-service-account" "github.com/stackitcloud/stackit-cli/internal/cmd/auth/login" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "auth", Short: "Provides authentication functionality", @@ -17,11 +18,11 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(login.NewCmd()) - cmd.AddCommand(activateserviceaccount.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(login.NewCmd(p)) + cmd.AddCommand(activateserviceaccount.NewCmd(p)) } diff --git a/internal/cmd/auth/login/login.go b/internal/cmd/auth/login/login.go index c1474dc29..55f3663b0 100644 --- a/internal/cmd/auth/login/login.go +++ b/internal/cmd/auth/login/login.go @@ -6,11 +6,12 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "login", Short: "Logs in to the STACKIT CLI", @@ -27,7 +28,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("authorization failed: %w", err) } - cmd.Println("Successfully logged into STACKIT CLI.") + p.Info("Successfully logged into STACKIT CLI.\n") return nil }, } diff --git a/internal/cmd/config/config.go b/internal/cmd/config/config.go index dc23ce78a..ee650f765 100644 --- a/internal/cmd/config/config.go +++ b/internal/cmd/config/config.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/config/set" "github.com/stackitcloud/stackit-cli/internal/cmd/config/unset" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "config", Short: "Provides functionality for CLI configuration options", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(set.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(set.NewCmd(p)) cmd.AddCommand(unset.NewCmd()) } diff --git a/internal/cmd/config/list/list.go b/internal/cmd/config/list/list.go index b227f617f..b6bdf48e2 100644 --- a/internal/cmd/config/list/list.go +++ b/internal/cmd/config/list/list.go @@ -10,13 +10,14 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/spf13/cobra" "github.com/spf13/viper" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists the current CLI configuration values", @@ -83,7 +84,7 @@ func NewCmd() *cobra.Command { table.AddRow(key, valueString) table.AddSeparator() } - err = table.Display(cmd) + err = table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/config/set/set.go b/internal/cmd/config/set/set.go index 485a1ef9b..36e9c06d4 100644 --- a/internal/cmd/config/set/set.go +++ b/internal/cmd/config/set/set.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" "github.com/spf13/viper" @@ -41,7 +42,7 @@ type inputModel struct { ProjectIdSet bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "set", Short: "Sets CLI configuration options", @@ -70,7 +71,7 @@ func NewCmd() *cobra.Command { } if model.SessionTimeLimit != nil { - cmd.Println("Authenticate again to apply changes to session time limit") + p.Warn("Authenticate again to apply changes to session time limit\n") viper.Set(config.SessionTimeLimitKey, *model.SessionTimeLimit) } diff --git a/internal/cmd/config/set/set_test.go b/internal/cmd/config/set/set_test.go index 2c5d9c171..e3b6c972b 100644 --- a/internal/cmd/config/set/set_test.go +++ b/internal/cmd/config/set/set_test.go @@ -120,7 +120,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/config/unset/unset.go b/internal/cmd/config/unset/unset.go index ac9e63a64..ff4e4d665 100644 --- a/internal/cmd/config/unset/unset.go +++ b/internal/cmd/config/unset/unset.go @@ -17,6 +17,7 @@ const ( asyncFlag = globalflags.AsyncFlag outputFormatFlag = globalflags.OutputFormatFlag projectIdFlag = globalflags.ProjectIdFlag + verbosityFlag = globalflags.VerbosityFlag sessionTimeLimitFlag = "session-time-limit" @@ -38,11 +39,11 @@ const ( ) type inputModel struct { - AsyncFlag bool - OutputFormat bool - ProjectId bool - + Async bool + OutputFormat bool + ProjectId bool SessionTimeLimit bool + Verbosity bool ArgusCustomEndpoint bool AuthorizationCustomEndpoint bool @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { RunE: func(cmd *cobra.Command, args []string) error { model := parseInput(cmd) - if model.AsyncFlag { + if model.Async { viper.Set(config.AsyncKey, config.AsyncDefault) } if model.OutputFormat { @@ -90,10 +91,12 @@ func NewCmd() *cobra.Command { if model.ProjectId { viper.Set(config.ProjectIdKey, "") } - if model.SessionTimeLimit { viper.Set(config.SessionTimeLimitKey, config.SessionTimeLimitDefault) } + if model.Verbosity { + viper.Set(config.VerbosityKey, globalflags.VerbosityDefault) + } if model.ArgusCustomEndpoint { viper.Set(config.ArgusCustomEndpointKey, "") @@ -156,8 +159,8 @@ func configureFlags(cmd *cobra.Command) { cmd.Flags().Bool(asyncFlag, false, "Configuration option to run commands asynchronously") cmd.Flags().Bool(projectIdFlag, false, "Project ID") cmd.Flags().Bool(outputFormatFlag, false, "Output format") - cmd.Flags().Bool(sessionTimeLimitFlag, false, fmt.Sprintf("Maximum time before authentication is required again. If unset, defaults to %s", config.SessionTimeLimitDefault)) + cmd.Flags().Bool(verbosityFlag, false, "Verbosity of the CLI") cmd.Flags().Bool(argusCustomEndpointFlag, false, "Argus API base URL. If unset, uses the default base URL") cmd.Flags().Bool(authorizationCustomEndpointFlag, false, "Authorization API base URL. If unset, uses the default base URL") @@ -178,11 +181,12 @@ func configureFlags(cmd *cobra.Command) { func parseInput(cmd *cobra.Command) *inputModel { return &inputModel{ - AsyncFlag: flags.FlagToBoolValue(cmd, asyncFlag), - OutputFormat: flags.FlagToBoolValue(cmd, outputFormatFlag), - ProjectId: flags.FlagToBoolValue(cmd, projectIdFlag), + Async: flags.FlagToBoolValue(cmd, asyncFlag), + OutputFormat: flags.FlagToBoolValue(cmd, outputFormatFlag), + ProjectId: flags.FlagToBoolValue(cmd, projectIdFlag), + SessionTimeLimit: flags.FlagToBoolValue(cmd, sessionTimeLimitFlag), + Verbosity: flags.FlagToBoolValue(cmd, verbosityFlag), - SessionTimeLimit: flags.FlagToBoolValue(cmd, sessionTimeLimitFlag), ArgusCustomEndpoint: flags.FlagToBoolValue(cmd, argusCustomEndpointFlag), AuthorizationCustomEndpoint: flags.FlagToBoolValue(cmd, authorizationCustomEndpointFlag), DNSCustomEndpoint: flags.FlagToBoolValue(cmd, dnsCustomEndpointFlag), diff --git a/internal/cmd/config/unset/unset_test.go b/internal/cmd/config/unset/unset_test.go index f68717953..738bbbdb5 100644 --- a/internal/cmd/config/unset/unset_test.go +++ b/internal/cmd/config/unset/unset_test.go @@ -9,8 +9,11 @@ import ( func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool { flagValues := map[string]bool{ - projectIdFlag: true, - outputFormatFlag: true, + asyncFlag: true, + outputFormatFlag: true, + projectIdFlag: true, + sessionTimeLimitFlag: true, + verbosityFlag: true, argusCustomEndpointFlag: true, authorizationCustomEndpointFlag: true, @@ -34,8 +37,11 @@ func fixtureFlagValues(mods ...func(flagValues map[string]bool)) map[string]bool func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - ProjectId: true, - OutputFormat: true, + Async: true, + OutputFormat: true, + ProjectId: true, + SessionTimeLimit: true, + Verbosity: true, ArgusCustomEndpoint: true, AuthorizationCustomEndpoint: true, @@ -75,8 +81,11 @@ func TestParseInput(t *testing.T) { flagValues: map[string]bool{}, isValid: true, expectedModel: fixtureInputModel(func(model *inputModel) { - model.ProjectId = false + model.Async = false model.OutputFormat = false + model.ProjectId = false + model.SessionTimeLimit = false + model.Verbosity = false model.ArgusCustomEndpoint = false model.AuthorizationCustomEndpoint = false diff --git a/internal/cmd/curl/curl.go b/internal/cmd/curl/curl.go index 573bcc67b..8454cb0ce 100644 --- a/internal/cmd/curl/curl.go +++ b/internal/cmd/curl/curl.go @@ -16,6 +16,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" ) @@ -43,7 +44,7 @@ type inputModel struct { OutputFile *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("curl %s", urlArg), Short: "Executes an authenticated HTTP request to an endpoint", @@ -73,7 +74,7 @@ func NewCmd() *cobra.Command { return err } - bearerToken, err := getBearerToken(cmd) + bearerToken, err := getBearerToken(p) if err != nil { return err } @@ -97,7 +98,7 @@ func NewCmd() *cobra.Command { } }() - err = outputResponse(cmd, model, resp) + err = outputResponse(p, model, resp) if err != nil { return err } @@ -167,8 +168,8 @@ func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) { }, nil } -func getBearerToken(cmd *cobra.Command) (string, error) { - _, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) +func getBearerToken(p *print.Printer) (string, error) { + _, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return "", &errors.AuthError{} } @@ -199,7 +200,7 @@ func buildRequest(model *inputModel, bearerToken string) (*http.Request, error) return req, nil } -func outputResponse(cmd *cobra.Command, model *inputModel, resp *http.Response) error { +func outputResponse(p *print.Printer, model *inputModel, resp *http.Response) error { output := make([]byte, 0) if model.IncludeResponseHeaders { respHeader, err := httputil.DumpResponse(resp, false) @@ -215,7 +216,7 @@ func outputResponse(cmd *cobra.Command, model *inputModel, resp *http.Response) output = append(output, respBody...) if model.OutputFile == nil { - cmd.Println(string(output)) + p.Outputln(string(output)) } else { err = os.WriteFile(*model.OutputFile, output, 0o600) if err != nil { diff --git a/internal/cmd/curl/curl_test.go b/internal/cmd/curl/curl_test.go index bb60d27aa..da57f3d04 100644 --- a/internal/cmd/curl/curl_test.go +++ b/internal/cmd/curl/curl_test.go @@ -205,7 +205,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/dns/dns.go b/internal/cmd/dns/dns.go index e73164998..a89e959c5 100644 --- a/internal/cmd/dns/dns.go +++ b/internal/cmd/dns/dns.go @@ -4,12 +4,13 @@ import ( recordset "github.com/stackitcloud/stackit-cli/internal/cmd/dns/record-set" "github.com/stackitcloud/stackit-cli/internal/cmd/dns/zone" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "dns", Short: "Provides functionality for DNS", @@ -17,11 +18,11 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(zone.NewCmd()) - cmd.AddCommand(recordset.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(zone.NewCmd(p)) + cmd.AddCommand(recordset.NewCmd(p)) } diff --git a/internal/cmd/dns/record-set/create/create.go b/internal/cmd/dns/record-set/create/create.go index a8dbe3ff0..f144a59ca 100644 --- a/internal/cmd/dns/record-set/create/create.go +++ b/internal/cmd/dns/record-set/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -41,7 +41,7 @@ type inputModel struct { Type string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a DNS record set", @@ -60,7 +60,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -72,7 +72,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a record set for zone %s?", zoneLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -88,7 +88,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating record set") _, err = wait.CreateRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, recordSetId).WaitWithContext(ctx) if err != nil { @@ -101,7 +101,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, recordSetId) + p.Outputf("%s record set for zone %s. Record set ID: %s\n", operationState, zoneLabel, recordSetId) return nil }, } diff --git a/internal/cmd/dns/record-set/create/create_test.go b/internal/cmd/dns/record-set/create/create_test.go index 1094d1e33..c8d095748 100644 --- a/internal/cmd/dns/record-set/create/create_test.go +++ b/internal/cmd/dns/record-set/create/create_test.go @@ -42,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr("example.com"), @@ -104,6 +105,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr("example.com"), @@ -125,6 +127,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr(""), @@ -236,7 +239,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -305,6 +308,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr("example.com"), diff --git a/internal/cmd/dns/record-set/delete/delete.go b/internal/cmd/dns/record-set/delete/delete.go index 003f00a0c..b85a68149 100644 --- a/internal/cmd/dns/record-set/delete/delete.go +++ b/internal/cmd/dns/record-set/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -32,7 +32,7 @@ type inputModel struct { RecordSetId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", recordSetIdArg), Short: "Deletes a DNS record set", @@ -51,7 +51,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete record set %s of zone %s? (This cannot be undone)", recordSetLabel, zoneLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -86,7 +86,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting record set") _, err = wait.DeleteRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) if err != nil { @@ -99,7 +99,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s record set %s of zone %s\n", operationState, recordSetLabel, zoneLabel) + p.Info("%s record set %s of zone %s\n", operationState, recordSetLabel, zoneLabel) return nil }, } diff --git a/internal/cmd/dns/record-set/delete/delete_test.go b/internal/cmd/dns/record-set/delete/delete_test.go index 751a4e23b..a60e5b63b 100644 --- a/internal/cmd/dns/record-set/delete/delete_test.go +++ b/internal/cmd/dns/record-set/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/dns/record-set/describe/describe.go b/internal/cmd/dns/record-set/describe/describe.go index 4ac1b7989..c392d2f06 100644 --- a/internal/cmd/dns/record-set/describe/describe.go +++ b/internal/cmd/dns/record-set/describe/describe.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +32,7 @@ type inputModel struct { RecordSetId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", recordSetIdArg), Short: "Shows details of a DNS record set", @@ -53,7 +54,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +67,7 @@ func NewCmd() *cobra.Command { } recordSet := resp.Rrset - return outputResult(cmd, model.OutputFormat, recordSet) + return outputResult(p, model.OutputFormat, recordSet) }, } configureFlags(cmd) @@ -100,7 +101,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, recordSet *dns.RecordSet) error { +func outputResult(p *print.Printer, outputFormat string, recordSet *dns.RecordSet) error { switch outputFormat { case globalflags.PrettyOutputFormat: recordsData := make([]string, 0, len(*recordSet.Records)) @@ -121,7 +122,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, recordSet *dns.Record table.AddRow("TYPE", *recordSet.Type) table.AddSeparator() table.AddRow("RECORDS DATA", recordsDataJoin) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, recordSet *dns.Record if err != nil { return fmt.Errorf("marshal DNS record set: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/dns/record-set/describe/describe_test.go b/internal/cmd/dns/record-set/describe/describe_test.go index 0a5c506a6..c3dd68d55 100644 --- a/internal/cmd/dns/record-set/describe/describe_test.go +++ b/internal/cmd/dns/record-set/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/dns/record-set/list/list.go b/internal/cmd/dns/record-set/list/list.go index a551abdef..182d4ca29 100644 --- a/internal/cmd/dns/record-set/list/list.go +++ b/internal/cmd/dns/record-set/list/list.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -46,7 +47,7 @@ type inputModel struct { PageSize int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "List DNS record sets", @@ -77,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -92,10 +93,10 @@ func NewCmd() *cobra.Command { if err != nil { zoneLabel = model.ZoneId } - cmd.Printf("No record sets found for zone %s matching the criteria\n", zoneLabel) + p.Info("No record sets found for zone %s matching the criteria\n", zoneLabel) return nil } - return outputResult(cmd, model.OutputFormat, recordSets) + return outputResult(p, model.OutputFormat, recordSets) }, } @@ -220,14 +221,14 @@ func fetchRecordSets(ctx context.Context, model *inputModel, apiClient dnsClient return recordSets, nil } -func outputResult(cmd *cobra.Command, outputFormat string, recordSets []dns.RecordSet) error { +func outputResult(p *print.Printer, outputFormat string, recordSets []dns.RecordSet) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(recordSets, "", " ") if err != nil { return fmt.Errorf("marshal DNS record set list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -242,7 +243,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, recordSets []dns.Reco recordDataJoin := strings.Join(recordData, ", ") table.AddRow(*rs.Id, *rs.Name, *rs.State, *rs.Ttl, *rs.Type, recordDataJoin) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/dns/record-set/list/list_test.go b/internal/cmd/dns/record-set/list/list_test.go index c6d404be9..e647eb819 100644 --- a/internal/cmd/dns/record-set/list/list_test.go +++ b/internal/cmd/dns/record-set/list/list_test.go @@ -44,6 +44,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, NameLike: utils.Ptr("some-pattern"), @@ -133,6 +134,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, PageSize: 100, // Default value @@ -211,7 +213,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -302,6 +304,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, PageSize: 10, diff --git a/internal/cmd/dns/record-set/record_set.go b/internal/cmd/dns/record-set/record_set.go index efba550e1..698750f4b 100644 --- a/internal/cmd/dns/record-set/record_set.go +++ b/internal/cmd/dns/record-set/record_set.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/dns/record-set/list" "github.com/stackitcloud/stackit-cli/internal/cmd/dns/record-set/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "record-set", Short: "Provides functionality for DNS record set", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/dns/record-set/update/update.go b/internal/cmd/dns/record-set/update/update.go index ebc2c5e5c..702e16712 100644 --- a/internal/cmd/dns/record-set/update/update.go +++ b/internal/cmd/dns/record-set/update/update.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -40,7 +40,7 @@ type inputModel struct { TTL *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", recordSetIdArg), Short: "Updates a DNS record set", @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update record set %s of zone %s?", recordSetLabel, zoneLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -91,7 +91,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating record set") _, err = wait.PartialUpdateRecordSetWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId, model.RecordSetId).WaitWithContext(ctx) if err != nil { @@ -104,7 +104,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s record set %s of zone %s\n", operationState, recordSetLabel, zoneLabel) + p.Info("%s record set %s of zone %s\n", operationState, recordSetLabel, zoneLabel) return nil }, } diff --git a/internal/cmd/dns/record-set/update/update_test.go b/internal/cmd/dns/record-set/update/update_test.go index c95506423..087ce4158 100644 --- a/internal/cmd/dns/record-set/update/update_test.go +++ b/internal/cmd/dns/record-set/update/update_test.go @@ -52,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, @@ -127,6 +128,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, @@ -147,6 +149,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, @@ -240,7 +243,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -317,6 +320,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, RecordSetId: testRecordSetId, diff --git a/internal/cmd/dns/zone/create/create.go b/internal/cmd/dns/zone/create/create.go index 624578749..f07f72ced 100644 --- a/internal/cmd/dns/zone/create/create.go +++ b/internal/cmd/dns/zone/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -52,7 +52,7 @@ type inputModel struct { ContactEmail *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a DNS zone", @@ -74,19 +74,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a zone for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -102,7 +102,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating zone") _, err = wait.CreateZoneWaitHandler(ctx, apiClient, model.ProjectId, zoneId).WaitWithContext(ctx) if err != nil { @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, zoneId) + p.Outputf("%s zone for project %q. Zone ID: %s\n", operationState, projectLabel, zoneId) return nil }, } diff --git a/internal/cmd/dns/zone/create/create_test.go b/internal/cmd/dns/zone/create/create_test.go index 6a9b01a42..75a43ae75 100644 --- a/internal/cmd/dns/zone/create/create_test.go +++ b/internal/cmd/dns/zone/create/create_test.go @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr("example"), DnsName: utils.Ptr("example.com"), @@ -122,6 +123,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr("example"), DnsName: utils.Ptr("example.com"), @@ -149,6 +151,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr(""), DnsName: utils.Ptr(""), @@ -212,7 +215,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -281,6 +284,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr("example"), DnsName: utils.Ptr("example.com"), diff --git a/internal/cmd/dns/zone/delete/delete.go b/internal/cmd/dns/zone/delete/delete.go index c2b70ba03..e36f4dd56 100644 --- a/internal/cmd/dns/zone/delete/delete.go +++ b/internal/cmd/dns/zone/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { ZoneId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", zoneIdArg), Short: "Deletes a DNS zone", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -58,7 +58,7 @@ func NewCmd() *cobra.Command { } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete zone %s? (This cannot be undone)", zoneLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting zone") _, err = wait.DeleteZoneWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId).WaitWithContext(ctx) if err != nil { @@ -89,7 +89,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s zone %s\n", operationState, zoneLabel) + p.Info("%s zone %s\n", operationState, zoneLabel) return nil }, } diff --git a/internal/cmd/dns/zone/delete/delete_test.go b/internal/cmd/dns/zone/delete/delete_test.go index 031a5b80b..a2bd86748 100644 --- a/internal/cmd/dns/zone/delete/delete_test.go +++ b/internal/cmd/dns/zone/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/dns/zone/describe/describe.go b/internal/cmd/dns/zone/describe/describe.go index b9bbf7043..3503fac06 100644 --- a/internal/cmd/dns/zone/describe/describe.go +++ b/internal/cmd/dns/zone/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -26,7 +27,7 @@ type inputModel struct { ZoneId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", zoneIdArg), Short: "Shows details of a DNS zone", @@ -47,7 +48,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -60,7 +61,7 @@ func NewCmd() *cobra.Command { } zone := resp.Zone - return outputResult(cmd, model.OutputFormat, zone) + return outputResult(p, model.OutputFormat, zone) }, } return cmd @@ -85,7 +86,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *dns.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, zone *dns.Zone) error { +func outputResult(p *print.Printer, outputFormat string, zone *dns.Zone) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -118,7 +119,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, zone *dns.Zone) error table.AddRow("EXPIRE TIME", *zone.ExpireTime) table.AddSeparator() table.AddRow("NEGATIVE CACHE", *zone.NegativeCache) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -129,7 +130,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, zone *dns.Zone) error if err != nil { return fmt.Errorf("marshal DNS zone: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/dns/zone/describe/describe_test.go b/internal/cmd/dns/zone/describe/describe_test.go index 8fcea083d..2b402efab 100644 --- a/internal/cmd/dns/zone/describe/describe_test.go +++ b/internal/cmd/dns/zone/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/dns/zone/list/list.go b/internal/cmd/dns/zone/list/list.go index 81af21198..08a5edd23 100644 --- a/internal/cmd/dns/zone/list/list.go +++ b/internal/cmd/dns/zone/list/list.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -44,7 +45,7 @@ type inputModel struct { PageSize int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "List DNS zones", @@ -72,7 +73,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -83,15 +84,15 @@ func NewCmd() *cobra.Command { return err } if len(zones) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No zones found for project %q matching the criteria\n", projectLabel) + p.Info("No zones found for project %q matching the criteria\n", projectLabel) return nil } - return outputResult(cmd, model.OutputFormat, zones) + return outputResult(p, model.OutputFormat, zones) }, } configureFlags(cmd) @@ -208,7 +209,7 @@ func fetchZones(ctx context.Context, model *inputModel, apiClient dnsClient) ([] return zones, nil } -func outputResult(cmd *cobra.Command, outputFormat string, zones []dns.Zone) error { +func outputResult(p *print.Printer, outputFormat string, zones []dns.Zone) error { switch outputFormat { case globalflags.JSONOutputFormat: // Show details @@ -216,7 +217,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, zones []dns.Zone) err if err != nil { return fmt.Errorf("marshal DNS zone list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -226,7 +227,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, zones []dns.Zone) err z := zones[i] table.AddRow(*z.Id, *z.Name, *z.State, *z.Type, *z.DnsName, *z.RecordCount) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/dns/zone/list/list_test.go b/internal/cmd/dns/zone/list/list_test.go index 430f3372a..9a3b6c011 100644 --- a/internal/cmd/dns/zone/list/list_test.go +++ b/internal/cmd/dns/zone/list/list_test.go @@ -42,6 +42,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, NameLike: utils.Ptr("some-pattern"), OrderByName: utils.Ptr("asc"), @@ -129,6 +130,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PageSize: pageSizeDefault, }, @@ -206,7 +208,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -297,6 +299,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PageSize: pageSizeDefault, }, diff --git a/internal/cmd/dns/zone/update/update.go b/internal/cmd/dns/zone/update/update.go index 18509e02e..5b3e20ec4 100644 --- a/internal/cmd/dns/zone/update/update.go +++ b/internal/cmd/dns/zone/update/update.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/client" dnsUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/dns/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -50,7 +50,7 @@ type inputModel struct { ContactEmail *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", zoneIdArg), Short: "Updates a DNS zone", @@ -69,7 +69,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -81,7 +81,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update zone %s?", zoneLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -99,7 +99,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating zone") _, err = wait.PartialUpdateZoneWaitHandler(ctx, apiClient, model.ProjectId, model.ZoneId).WaitWithContext(ctx) if err != nil { @@ -112,7 +112,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s zone %s\n", operationState, zoneLabel) + p.Info("%s zone %s\n", operationState, zoneLabel) return nil }, } diff --git a/internal/cmd/dns/zone/update/update_test.go b/internal/cmd/dns/zone/update/update_test.go index c53d511e2..1be550af6 100644 --- a/internal/cmd/dns/zone/update/update_test.go +++ b/internal/cmd/dns/zone/update/update_test.go @@ -56,6 +56,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr("example"), @@ -139,6 +140,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, }, @@ -163,6 +165,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, Name: utils.Ptr(""), @@ -241,7 +244,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -318,6 +321,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ZoneId: testZoneId, }, diff --git a/internal/cmd/dns/zone/zone.go b/internal/cmd/dns/zone/zone.go index c8a5d8522..c3578401f 100644 --- a/internal/cmd/dns/zone/zone.go +++ b/internal/cmd/dns/zone/zone.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/dns/zone/list" "github.com/stackitcloud/stackit-cli/internal/cmd/dns/zone/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "zone", Short: "Provides functionality for DNS zones", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(update.NewCmd()) - cmd.AddCommand(delete.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) } diff --git a/internal/cmd/logme/credentials/create/create.go b/internal/cmd/logme/credentials/create/create.go index 4c102c1ee..a07ad997e 100644 --- a/internal/cmd/logme/credentials/create/create.go +++ b/internal/cmd/logme/credentials/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" @@ -28,7 +28,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for a LogMe instance", @@ -50,7 +50,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -75,20 +75,20 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create LogMe credentials: %w", err) } - cmd.Printf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty username := *resp.Raw.Credentials.Username if username != "" { - cmd.Printf("Username: %s\n", *resp.Raw.Credentials.Username) + p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } if model.HidePassword { - cmd.Printf("Password: \n") + p.Outputf("Password: \n") } else { - cmd.Printf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) } - cmd.Printf("Host: %s\n", *resp.Raw.Credentials.Host) - cmd.Printf("Port: %d\n", *resp.Raw.Credentials.Port) - cmd.Printf("URI: %s\n", *resp.Uri) + p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) + p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) + p.Outputf("URI: %s\n", *resp.Uri) return nil }, } diff --git a/internal/cmd/logme/credentials/create/create_test.go b/internal/cmd/logme/credentials/create/create_test.go index 6cf81ee9a..504c90265 100644 --- a/internal/cmd/logme/credentials/create/create_test.go +++ b/internal/cmd/logme/credentials/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -117,7 +118,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/credentials/credentials.go b/internal/cmd/logme/credentials/credentials.go index 641956995..1b884797a 100644 --- a/internal/cmd/logme/credentials/credentials.go +++ b/internal/cmd/logme/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/logme/credentials/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/logme/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for LogMe credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/logme/credentials/delete/delete.go b/internal/cmd/logme/credentials/delete/delete.go index 36b92c071..d6d5f0b8c 100644 --- a/internal/cmd/logme/credentials/delete/delete.go +++ b/internal/cmd/logme/credentials/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of a LogMe instance", @@ -49,7 +49,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %s of instance %q? (This cannot be undone)", credentialsLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -79,7 +79,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete LogMe credentials: %w", err) } - cmd.Printf("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) + p.Info("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/logme/credentials/delete/delete_test.go b/internal/cmd/logme/credentials/delete/delete_test.go index c7ea5a330..0ed08ed98 100644 --- a/internal/cmd/logme/credentials/delete/delete_test.go +++ b/internal/cmd/logme/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/credentials/describe/describe.go b/internal/cmd/logme/credentials/describe/describe.go index 0d8893c05..c9715adf7 100644 --- a/internal/cmd/logme/credentials/describe/describe.go +++ b/internal/cmd/logme/credentials/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", credentialsIdArg), Short: "Shows details of credentials of a LogMe instance", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("describe LogMe credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -98,7 +99,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *logme.CredentialsResponse) error { +func outputResult(p *print.Printer, outputFormat string, credentials *logme.CredentialsResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -113,7 +114,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *logme.Cr table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) table.AddSeparator() table.AddRow("URI", *credentials.Raw.Credentials.Uri) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *logme.Cr if err != nil { return fmt.Errorf("marshal LogMe credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/logme/credentials/describe/describe_test.go b/internal/cmd/logme/credentials/describe/describe_test.go index b157ff651..4cecdaad2 100644 --- a/internal/cmd/logme/credentials/describe/describe_test.go +++ b/internal/cmd/logme/credentials/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/credentials/list/list.go b/internal/cmd/logme/credentials/list/list.go index 98c7c9b6e..d40810424 100644 --- a/internal/cmd/logme/credentials/list/list.go +++ b/internal/cmd/logme/credentials/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials' IDs for a LogMe instance", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = model.InstanceId } - cmd.Printf("No credentials found for instance %q\n", instanceLabel) + p.Info("No credentials found for instance %q\n", instanceLabel) return nil } @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -120,14 +121,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []logme.CredentialsListItem) error { +func outputResult(p *print.Printer, outputFormat string, credentials []logme.CredentialsListItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal LogMe credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []logme.C c := credentials[i] table.AddRow(*c.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/logme/credentials/list/list_test.go b/internal/cmd/logme/credentials/list/list_test.go index 7f3cb8faa..5b6737330 100644 --- a/internal/cmd/logme/credentials/list/list_test.go +++ b/internal/cmd/logme/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Limit: utils.Ptr(int64(10)), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/instance/create/create.go b/internal/cmd/logme/instance/create/create.go index 117e5ae37..459ab3a8e 100644 --- a/internal/cmd/logme/instance/create/create.go +++ b/internal/cmd/logme/instance/create/create.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" @@ -55,7 +55,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a LogMe instance", @@ -80,19 +80,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a LogMe instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/logme/instance/create/create_test.go b/internal/cmd/logme/instance/create/create_test.go index cac6708d2..ff41d205a 100644 --- a/internal/cmd/logme/instance/create/create_test.go +++ b/internal/cmd/logme/instance/create/create_test.go @@ -65,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), EnableMonitoring: utils.Ptr(true), @@ -151,6 +152,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -171,6 +173,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -272,7 +275,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -437,6 +440,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), }, diff --git a/internal/cmd/logme/instance/delete/delete.go b/internal/cmd/logme/instance/delete/delete.go index 5817fe84d..c3b7cd837 100644 --- a/internal/cmd/logme/instance/delete/delete.go +++ b/internal/cmd/logme/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a LogMe instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/logme/instance/delete/delete_test.go b/internal/cmd/logme/instance/delete/delete_test.go index 41863912d..82ae2cb94 100644 --- a/internal/cmd/logme/instance/delete/delete_test.go +++ b/internal/cmd/logme/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/instance/describe/describe.go b/internal/cmd/logme/instance/describe/describe.go index 30d054776..28dd148ef 100644 --- a/internal/cmd/logme/instance/describe/describe.go +++ b/internal/cmd/logme/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a LogMe instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read LogMe instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *logme.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *logme.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -108,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *logme.Insta table.AddRow("ACL", aclStr) } } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -119,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *logme.Insta if err != nil { return fmt.Errorf("marshal LogMe instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/logme/instance/describe/describe_test.go b/internal/cmd/logme/instance/describe/describe_test.go index cbfa438c4..2dd60d3ce 100644 --- a/internal/cmd/logme/instance/describe/describe_test.go +++ b/internal/cmd/logme/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/logme/instance/instance.go b/internal/cmd/logme/instance/instance.go index 69877a401..534151d57 100644 --- a/internal/cmd/logme/instance/instance.go +++ b/internal/cmd/logme/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/logme/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/logme/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for LogMe instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/logme/instance/list/list.go b/internal/cmd/logme/instance/list/list.go index a0eb3c500..12f85d8e1 100644 --- a/internal/cmd/logme/instance/list/list.go +++ b/internal/cmd/logme/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all LogMe instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []logme.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []logme.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal LogMe instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []logme.Ins instance := instances[i] table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/logme/instance/list/list_test.go b/internal/cmd/logme/instance/list/list_test.go index eb6f9faac..a2be6bda6 100644 --- a/internal/cmd/logme/instance/list/list_test.go +++ b/internal/cmd/logme/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/logme/instance/update/update.go b/internal/cmd/logme/instance/update/update.go index 5cd79ca7d..927ace20b 100644 --- a/internal/cmd/logme/instance/update/update.go +++ b/internal/cmd/logme/instance/update/update.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" logmeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -56,7 +56,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a LogMe instance", @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -113,7 +113,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -126,7 +126,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/logme/instance/update/update_test.go b/internal/cmd/logme/instance/update/update_test.go index e2da035a9..633fe1165 100644 --- a/internal/cmd/logme/instance/update/update_test.go +++ b/internal/cmd/logme/instance/update/update_test.go @@ -77,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, EnableMonitoring: utils.Ptr(true), @@ -162,6 +163,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, @@ -181,6 +183,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testPlanId), @@ -278,7 +281,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -451,6 +454,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, diff --git a/internal/cmd/logme/logme.go b/internal/cmd/logme/logme.go index 8880bfff7..9dc8b77fd 100644 --- a/internal/cmd/logme/logme.go +++ b/internal/cmd/logme/logme.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/logme/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/logme/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "logme", Short: "Provides functionality for LogMe", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/logme/plans/plans.go b/internal/cmd/logme/plans/plans.go index 8bf3fd69d..652178444 100644 --- a/internal/cmd/logme/plans/plans.go +++ b/internal/cmd/logme/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/logme/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all LogMe service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Offerings if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *logme.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []logme.Offering) error { +func outputResult(p *print.Printer, outputFormat string, plans []logme.Offering) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal LogMe plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []logme.Offerin table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/logme/plans/plans_test.go b/internal/cmd/logme/plans/plans_test.go index 49045f706..032fac61c 100644 --- a/internal/cmd/logme/plans/plans_test.go +++ b/internal/cmd/logme/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/mariadb/credentials/create/create.go b/internal/cmd/mariadb/credentials/create/create.go index b4dd2d8ee..0df6ea069 100644 --- a/internal/cmd/mariadb/credentials/create/create.go +++ b/internal/cmd/mariadb/credentials/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" @@ -28,7 +28,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for a MariaDB instance", @@ -50,7 +50,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -75,20 +75,20 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create MariaDB credentials: %w", err) } - cmd.Printf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty username := *resp.Raw.Credentials.Username if username != "" { - cmd.Printf("Username: %s\n", *resp.Raw.Credentials.Username) + p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } if model.HidePassword { - cmd.Printf("Password: \n") + p.Outputf("Password: \n") } else { - cmd.Printf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) } - cmd.Printf("Host: %s\n", *resp.Raw.Credentials.Host) - cmd.Printf("Port: %d\n", *resp.Raw.Credentials.Port) - cmd.Printf("URI: %s\n", *resp.Uri) + p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) + p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) + p.Outputf("URI: %s\n", *resp.Uri) return nil }, } diff --git a/internal/cmd/mariadb/credentials/create/create_test.go b/internal/cmd/mariadb/credentials/create/create_test.go index a47d55d57..3676ee551 100644 --- a/internal/cmd/mariadb/credentials/create/create_test.go +++ b/internal/cmd/mariadb/credentials/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -117,7 +118,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/credentials/credentials.go b/internal/cmd/mariadb/credentials/credentials.go index a5bbfd8c4..f8fb1c5d2 100644 --- a/internal/cmd/mariadb/credentials/credentials.go +++ b/internal/cmd/mariadb/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/credentials/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for MariaDB credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/mariadb/credentials/delete/delete.go b/internal/cmd/mariadb/credentials/delete/delete.go index af05398e2..d1df164d0 100644 --- a/internal/cmd/mariadb/credentials/delete/delete.go +++ b/internal/cmd/mariadb/credentials/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of a MariaDB instance", @@ -49,7 +49,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %s of instance %q? (This cannot be undone)", credentialsLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -79,7 +79,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete MariaDB credentials: %w", err) } - cmd.Printf("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) + p.Info("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/mariadb/credentials/delete/delete_test.go b/internal/cmd/mariadb/credentials/delete/delete_test.go index ed6f81c92..8834de487 100644 --- a/internal/cmd/mariadb/credentials/delete/delete_test.go +++ b/internal/cmd/mariadb/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/credentials/describe/describe.go b/internal/cmd/mariadb/credentials/describe/describe.go index 2469c69af..13b3ee2be 100644 --- a/internal/cmd/mariadb/credentials/describe/describe.go +++ b/internal/cmd/mariadb/credentials/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", credentialsIdArg), Short: "Shows details of credentials of a MariaDB instance", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("describe MariaDB credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -98,7 +99,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *mariadb.CredentialsResponse) error { +func outputResult(p *print.Printer, outputFormat string, credentials *mariadb.CredentialsResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -113,7 +114,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *mariadb. table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) table.AddSeparator() table.AddRow("URI", *credentials.Raw.Credentials.Uri) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *mariadb. if err != nil { return fmt.Errorf("marshal MariaDB credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/mariadb/credentials/describe/describe_test.go b/internal/cmd/mariadb/credentials/describe/describe_test.go index 154913803..717238033 100644 --- a/internal/cmd/mariadb/credentials/describe/describe_test.go +++ b/internal/cmd/mariadb/credentials/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/credentials/list/list.go b/internal/cmd/mariadb/credentials/list/list.go index 7ec7b5e1d..b394e7720 100644 --- a/internal/cmd/mariadb/credentials/list/list.go +++ b/internal/cmd/mariadb/credentials/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials' IDs for a MariaDB instance", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = model.InstanceId } - cmd.Printf("No credentials found for instance %q\n", instanceLabel) + p.Info("No credentials found for instance %q\n", instanceLabel) return nil } @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -120,14 +121,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []mariadb.CredentialsListItem) error { +func outputResult(p *print.Printer, outputFormat string, credentials []mariadb.CredentialsListItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal MariaDB credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []mariadb c := credentials[i] table.AddRow(*c.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/mariadb/credentials/list/list_test.go b/internal/cmd/mariadb/credentials/list/list_test.go index 56b2c2556..5531af98b 100644 --- a/internal/cmd/mariadb/credentials/list/list_test.go +++ b/internal/cmd/mariadb/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Limit: utils.Ptr(int64(10)), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/instance/create/create.go b/internal/cmd/mariadb/instance/create/create.go index c2a43d209..91923cd0c 100644 --- a/internal/cmd/mariadb/instance/create/create.go +++ b/internal/cmd/mariadb/instance/create/create.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" @@ -55,7 +55,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a MariaDB instance", @@ -80,19 +80,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a MariaDB instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/mariadb/instance/create/create_test.go b/internal/cmd/mariadb/instance/create/create_test.go index db3eb811b..46dcf6ff3 100644 --- a/internal/cmd/mariadb/instance/create/create_test.go +++ b/internal/cmd/mariadb/instance/create/create_test.go @@ -65,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), EnableMonitoring: utils.Ptr(true), @@ -151,6 +152,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -171,6 +173,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -272,7 +275,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -437,6 +440,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), }, diff --git a/internal/cmd/mariadb/instance/delete/delete.go b/internal/cmd/mariadb/instance/delete/delete.go index 7f9004b51..c52138e67 100644 --- a/internal/cmd/mariadb/instance/delete/delete.go +++ b/internal/cmd/mariadb/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a MariaDB instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/mariadb/instance/delete/delete_test.go b/internal/cmd/mariadb/instance/delete/delete_test.go index 554580b6c..f1b99b143 100644 --- a/internal/cmd/mariadb/instance/delete/delete_test.go +++ b/internal/cmd/mariadb/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/instance/describe/describe.go b/internal/cmd/mariadb/instance/describe/describe.go index aa02f63a0..6a93d6a3d 100644 --- a/internal/cmd/mariadb/instance/describe/describe.go +++ b/internal/cmd/mariadb/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a MariaDB instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read MariaDB instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *mariadb.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *mariadb.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -108,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *mariadb.Ins table.AddRow("ACL", aclStr) } } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -119,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *mariadb.Ins if err != nil { return fmt.Errorf("marshal MariaDB instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/mariadb/instance/describe/describe_test.go b/internal/cmd/mariadb/instance/describe/describe_test.go index aaeb3d5f5..db3aa4ac7 100644 --- a/internal/cmd/mariadb/instance/describe/describe_test.go +++ b/internal/cmd/mariadb/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mariadb/instance/instance.go b/internal/cmd/mariadb/instance/instance.go index dc68e87ee..71e25309a 100644 --- a/internal/cmd/mariadb/instance/instance.go +++ b/internal/cmd/mariadb/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for MariaDB instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/mariadb/instance/list/list.go b/internal/cmd/mariadb/instance/list/list.go index bc1321c42..5bf143ec5 100644 --- a/internal/cmd/mariadb/instance/list/list.go +++ b/internal/cmd/mariadb/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all MariaDB instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []mariadb.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []mariadb.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal MariaDB instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []mariadb.I instance := instances[i] table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/mariadb/instance/list/list_test.go b/internal/cmd/mariadb/instance/list/list_test.go index a730195b9..10dd9fd94 100644 --- a/internal/cmd/mariadb/instance/list/list_test.go +++ b/internal/cmd/mariadb/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/mariadb/instance/update/update.go b/internal/cmd/mariadb/instance/update/update.go index 80dcae49d..338e04e35 100644 --- a/internal/cmd/mariadb/instance/update/update.go +++ b/internal/cmd/mariadb/instance/update/update.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" mariadbUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -56,7 +56,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a MariaDB instance", @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -113,7 +113,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -126,7 +126,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/mariadb/instance/update/update_test.go b/internal/cmd/mariadb/instance/update/update_test.go index 362bf4447..eb7545a53 100644 --- a/internal/cmd/mariadb/instance/update/update_test.go +++ b/internal/cmd/mariadb/instance/update/update_test.go @@ -77,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, EnableMonitoring: utils.Ptr(true), @@ -162,6 +163,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, @@ -181,6 +183,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testPlanId), @@ -289,7 +292,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -462,6 +465,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, diff --git a/internal/cmd/mariadb/mariadb.go b/internal/cmd/mariadb/mariadb.go index e8f9f647d..7058813f9 100644 --- a/internal/cmd/mariadb/mariadb.go +++ b/internal/cmd/mariadb/mariadb.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/mariadb/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "mariadb", Short: "Provides functionality for MariaDB", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/mariadb/plans/plans.go b/internal/cmd/mariadb/plans/plans.go index f7135658e..a567c0b51 100644 --- a/internal/cmd/mariadb/plans/plans.go +++ b/internal/cmd/mariadb/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mariadb/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all MariaDB service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Offerings if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mariadb.API return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []mariadb.Offering) error { +func outputResult(p *print.Printer, outputFormat string, plans []mariadb.Offering) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal MariaDB plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -131,13 +132,13 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []mariadb.Offer for i := range plans { o := plans[i] for j := range *o.Plans { - p := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *p.Id, *p.Name, *p.Description) + plan := (*o.Plans)[j] + table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) } table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/mariadb/plans/plans_test.go b/internal/cmd/mariadb/plans/plans_test.go index fe2d96445..fe38082b0 100644 --- a/internal/cmd/mariadb/plans/plans_test.go +++ b/internal/cmd/mariadb/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/mongodbflex/instance/create/create.go b/internal/cmd/mongodbflex/instance/create/create.go index 837082408..3f28f243b 100644 --- a/internal/cmd/mongodbflex/instance/create/create.go +++ b/internal/cmd/mongodbflex/instance/create/create.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" @@ -55,7 +55,7 @@ type inputModel struct { Type *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a MongoDB Flex instance", @@ -81,19 +81,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a MongoDB Flex instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -121,7 +121,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -134,7 +134,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/mongodbflex/instance/create/create_test.go b/internal/cmd/mongodbflex/instance/create/create_test.go index 44fbaa2d5..d3dfacad3 100644 --- a/internal/cmd/mongodbflex/instance/create/create_test.go +++ b/internal/cmd/mongodbflex/instance/create/create_test.go @@ -71,6 +71,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), ACL: utils.Ptr([]string{"0.0.0.0/0"}), @@ -247,7 +248,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/instance/delete/delete.go b/internal/cmd/mongodbflex/instance/delete/delete.go index 37c2c7654..9a832524d 100644 --- a/internal/cmd/mongodbflex/instance/delete/delete.go +++ b/internal/cmd/mongodbflex/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a MongoDB Flex instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/mongodbflex/instance/delete/delete_test.go b/internal/cmd/mongodbflex/instance/delete/delete_test.go index 13469325f..2a2d3f2e2 100644 --- a/internal/cmd/mongodbflex/instance/delete/delete_test.go +++ b/internal/cmd/mongodbflex/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/instance/describe/describe.go b/internal/cmd/mongodbflex/instance/describe/describe.go index 1b91eebf1..f45ef1466 100644 --- a/internal/cmd/mongodbflex/instance/describe/describe.go +++ b/internal/cmd/mongodbflex/instance/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a MongoDB Flex instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read MongoDB Flex instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp.Item) + return outputResult(p, model.OutputFormat, resp.Item) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *mongodbflex.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *mongodbflex.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: aclsArray := *instance.Acl.Items @@ -121,7 +122,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *mongodbflex table.AddSeparator() table.AddRow("RAM", *instance.Flavor.Memory) table.AddSeparator() - err = table.Display(cmd) + err = table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *mongodbflex if err != nil { return fmt.Errorf("marshal MongoDB Flex instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/mongodbflex/instance/describe/describe_test.go b/internal/cmd/mongodbflex/instance/describe/describe_test.go index 2067e1990..bbc76890e 100644 --- a/internal/cmd/mongodbflex/instance/describe/describe_test.go +++ b/internal/cmd/mongodbflex/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/instance/instance.go b/internal/cmd/mongodbflex/instance/instance.go index 5915fc909..1a770bcc1 100644 --- a/internal/cmd/mongodbflex/instance/instance.go +++ b/internal/cmd/mongodbflex/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for MongoDB Flex instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/mongodbflex/instance/list/list.go b/internal/cmd/mongodbflex/instance/list/list.go index 98a5d1290..8a25f6c0d 100644 --- a/internal/cmd/mongodbflex/instance/list/list.go +++ b/internal/cmd/mongodbflex/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all MongoDB Flex instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,11 +65,11 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get MongoDB Flex instances: %w", err) } if resp.Items == nil || len(*resp.Items) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } instances := *resp.Items @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []mongodbflex.InstanceListInstance) error { +func outputResult(p *print.Printer, outputFormat string, instances []mongodbflex.InstanceListInstance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal MongoDB Flex instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []mongodbfl instance := instances[i] table.AddRow(*instance.Id, *instance.Name, *instance.Status) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/mongodbflex/instance/list/list_test.go b/internal/cmd/mongodbflex/instance/list/list_test.go index 5f2d89749..eef3a67b0 100644 --- a/internal/cmd/mongodbflex/instance/list/list_test.go +++ b/internal/cmd/mongodbflex/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/mongodbflex/instance/update/update.go b/internal/cmd/mongodbflex/instance/update/update.go index 12c3900ee..c7cd7040b 100644 --- a/internal/cmd/mongodbflex/instance/update/update.go +++ b/internal/cmd/mongodbflex/instance/update/update.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -52,7 +52,7 @@ type inputModel struct { Type *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a MongoDB Flex instance", @@ -75,7 +75,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -106,7 +106,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -119,7 +119,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/mongodbflex/instance/update/update_test.go b/internal/cmd/mongodbflex/instance/update/update_test.go index 9390d83ff..9fc3670a4 100644 --- a/internal/cmd/mongodbflex/instance/update/update_test.go +++ b/internal/cmd/mongodbflex/instance/update/update_test.go @@ -101,6 +101,7 @@ func fixtureRequiredInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -114,6 +115,7 @@ func fixtureStandardInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, FlavorId: utils.Ptr(testFlavorId), @@ -276,7 +278,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/mongodbflex.go b/internal/cmd/mongodbflex/mongodbflex.go index 7b285c3b9..3aa6bf890 100644 --- a/internal/cmd/mongodbflex/mongodbflex.go +++ b/internal/cmd/mongodbflex/mongodbflex.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/options" "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "mongodbflex", Short: "Provides functionality for MongoDB Flex", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(user.NewCmd()) - cmd.AddCommand(options.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(user.NewCmd(p)) + cmd.AddCommand(options.NewCmd(p)) } diff --git a/internal/cmd/mongodbflex/options/options.go b/internal/cmd/mongodbflex/options/options.go index 7196b8c4c..23bb7f1e1 100644 --- a/internal/cmd/mongodbflex/options/options.go +++ b/internal/cmd/mongodbflex/options/options.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/pager" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -44,7 +45,7 @@ type flavorStorages struct { Storages *mongodbflex.ListStoragesResponse `json:"storages"` } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "options", Short: "Lists MongoDB Flex options", @@ -69,13 +70,13 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } // Call API - err = buildAndExecuteRequest(ctx, cmd, model, apiClient) + err = buildAndExecuteRequest(ctx, p, model, apiClient) if err != nil { return fmt.Errorf("get MongoDB Flex options: %w", err) } @@ -129,7 +130,7 @@ type mongoDBFlexOptionsClient interface { ListStoragesExecute(ctx context.Context, projectId, flavorId string) (*mongodbflex.ListStoragesResponse, error) } -func buildAndExecuteRequest(ctx context.Context, cmd *cobra.Command, model *inputModel, apiClient mongoDBFlexOptionsClient) error { +func buildAndExecuteRequest(ctx context.Context, p *print.Printer, model *inputModel, apiClient mongoDBFlexOptionsClient) error { var flavors *mongodbflex.ListFlavorsResponse var versions *mongodbflex.ListVersionsResponse var storages *mongodbflex.ListStoragesResponse @@ -154,10 +155,10 @@ func buildAndExecuteRequest(ctx context.Context, cmd *cobra.Command, model *inpu } } - return outputResult(cmd, model, flavors, versions, storages) + return outputResult(p, model, flavors, versions, storages) } -func outputResult(cmd *cobra.Command, model *inputModel, flavors *mongodbflex.ListFlavorsResponse, versions *mongodbflex.ListVersionsResponse, storages *mongodbflex.ListStoragesResponse) error { +func outputResult(p *print.Printer, model *inputModel, flavors *mongodbflex.ListFlavorsResponse, versions *mongodbflex.ListVersionsResponse, storages *mongodbflex.ListStoragesResponse) error { options := &options{} if flavors != nil { options.Flavors = flavors.Flavors @@ -178,14 +179,14 @@ func outputResult(cmd *cobra.Command, model *inputModel, flavors *mongodbflex.Li if err != nil { return fmt.Errorf("marshal MongoDB Flex options: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: - return outputResultAsTable(cmd, model, options) + return outputResultAsTable(p, model, options) } } -func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *options) error { +func outputResultAsTable(p *print.Printer, model *inputModel, options *options) error { content := "" if model.Flavors { content += renderFlavors(*options.Flavors) @@ -197,7 +198,7 @@ func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *options content += renderStorages(options.Storages.Storages) } - err := pager.Display(cmd, content) + err := pager.Display(p, content) if err != nil { return fmt.Errorf("display output: %w", err) } diff --git a/internal/cmd/mongodbflex/options/options_test.go b/internal/cmd/mongodbflex/options/options_test.go index 0cdc7bc75..812ee8359 100644 --- a/internal/cmd/mongodbflex/options/options_test.go +++ b/internal/cmd/mongodbflex/options/options_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" @@ -75,7 +76,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, Flavors: false, Versions: false, Storages: false, @@ -88,7 +89,7 @@ func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { func fixtureInputModelAllTrue(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, Flavors: true, Versions: true, Storages: true, @@ -165,7 +166,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -288,14 +289,16 @@ func TestBuildAndExecuteRequest(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + p := &print.Printer{} + cmd := NewCmd(p) + p.Cmd = cmd client := &mongoDBFlexClientMocked{ listFlavorsFails: tt.listFlavorsFails, listVersionsFails: tt.listVersionsFails, listStoragesFails: tt.listStoragesFails, } - err := buildAndExecuteRequest(testCtx, cmd, tt.model, client) + err := buildAndExecuteRequest(testCtx, p, tt.model, client) if err != nil && tt.isValid { t.Fatalf("error building and executing request: %v", err) } diff --git a/internal/cmd/mongodbflex/user/create/create.go b/internal/cmd/mongodbflex/user/create/create.go index de670b3ef..5540487cf 100644 --- a/internal/cmd/mongodbflex/user/create/create.go +++ b/internal/cmd/mongodbflex/user/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" @@ -37,7 +37,7 @@ type inputModel struct { Roles *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a MongoDB Flex user", @@ -64,7 +64,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a user for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -90,14 +90,14 @@ func NewCmd() *cobra.Command { } user := resp.Item - cmd.Printf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) - cmd.Printf("Username: %s\n", *user.Username) - cmd.Printf("Password: %s\n", *user.Password) - cmd.Printf("Roles: %v\n", *user.Roles) - cmd.Printf("Database: %s\n", *user.Database) - cmd.Printf("Host: %s\n", *user.Host) - cmd.Printf("Port: %d\n", *user.Port) - cmd.Printf("URI: %s\n", *user.Uri) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) + p.Outputf("Username: %s\n", *user.Username) + p.Outputf("Password: %s\n", *user.Password) + p.Outputf("Roles: %v\n", *user.Roles) + p.Outputf("Database: %s\n", *user.Database) + p.Outputf("Host: %s\n", *user.Host) + p.Outputf("Port: %d\n", *user.Port) + p.Outputf("URI: %s\n", *user.Uri) return nil }, diff --git a/internal/cmd/mongodbflex/user/create/create_test.go b/internal/cmd/mongodbflex/user/create/create_test.go index feb2dc175..2165b3b77 100644 --- a/internal/cmd/mongodbflex/user/create/create_test.go +++ b/internal/cmd/mongodbflex/user/create/create_test.go @@ -41,6 +41,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Username: utils.Ptr("johndoe"), diff --git a/internal/cmd/mongodbflex/user/delete/delete.go b/internal/cmd/mongodbflex/user/delete/delete.go index c13123ed5..84d31d7cb 100644 --- a/internal/cmd/mongodbflex/user/delete/delete.go +++ b/internal/cmd/mongodbflex/user/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +31,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", userIdArg), Short: "Deletes a MongoDB Flex user", @@ -53,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete user %q of instance %q? (This cannot be undone)", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,7 +83,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete MongoDB Flex user: %w", err) } - cmd.Printf("Deleted user %q of instance %q\n", userLabel, instanceLabel) + p.Info("Deleted user %q of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/mongodbflex/user/delete/delete_test.go b/internal/cmd/mongodbflex/user/delete/delete_test.go index e3d930a64..7fd731c07 100644 --- a/internal/cmd/mongodbflex/user/delete/delete_test.go +++ b/internal/cmd/mongodbflex/user/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/user/describe/describe.go b/internal/cmd/mongodbflex/user/describe/describe.go index cd03a0244..24b3eefc7 100644 --- a/internal/cmd/mongodbflex/user/describe/describe.go +++ b/internal/cmd/mongodbflex/user/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +32,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", userIdArg), Short: "Shows details of a MongoDB Flex user", @@ -57,7 +58,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -69,7 +70,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get MongoDB Flex user: %w", err) } - return outputResult(cmd, model.OutputFormat, *resp.Item) + return outputResult(p, model.OutputFormat, *resp.Item) }, } @@ -104,7 +105,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex return req } -func outputResult(cmd *cobra.Command, outputFormat string, user mongodbflex.InstanceResponseUser) error { +func outputResult(p *print.Printer, outputFormat string, user mongodbflex.InstanceResponseUser) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -120,7 +121,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user mongodbflex.Inst table.AddSeparator() table.AddRow("PORT", *user.Port) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -131,7 +132,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user mongodbflex.Inst if err != nil { return fmt.Errorf("marshal MongoDB Flex user: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/mongodbflex/user/describe/describe_test.go b/internal/cmd/mongodbflex/user/describe/describe_test.go index 49d8089e8..47a913f80 100644 --- a/internal/cmd/mongodbflex/user/describe/describe_test.go +++ b/internal/cmd/mongodbflex/user/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/user/list/list.go b/internal/cmd/mongodbflex/user/list/list.go index 5ec42bb34..43288df6c 100644 --- a/internal/cmd/mongodbflex/user/list/list.go +++ b/internal/cmd/mongodbflex/user/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all MongoDB Flex users of an instance", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = *model.InstanceId } - cmd.Printf("No users found for instance %q\n", instanceLabel) + p.Info("No users found for instance %q\n", instanceLabel) return nil } users := *resp.Items @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { users = users[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, users) + return outputResult(p, model.OutputFormat, users) }, } @@ -123,14 +124,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *mongodbflex return req } -func outputResult(cmd *cobra.Command, outputFormat string, users []mongodbflex.ListUser) error { +func outputResult(p *print.Printer, outputFormat string, users []mongodbflex.ListUser) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(users, "", " ") if err != nil { return fmt.Errorf("marshal MongoDB Flex user list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -140,7 +141,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, users []mongodbflex.L user := users[i] table.AddRow(*user.Id, *user.Username) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/mongodbflex/user/list/list_test.go b/internal/cmd/mongodbflex/user/list/list_test.go index ddebcda27..c4ac29db8 100644 --- a/internal/cmd/mongodbflex/user/list/list_test.go +++ b/internal/cmd/mongodbflex/user/list/list_test.go @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: utils.Ptr(testInstanceId), Limit: utils.Ptr(int64(10)), diff --git a/internal/cmd/mongodbflex/user/reset-password/reset_password.go b/internal/cmd/mongodbflex/user/reset-password/reset_password.go index df544d5ec..f1faa7240 100644 --- a/internal/cmd/mongodbflex/user/reset-password/reset_password.go +++ b/internal/cmd/mongodbflex/user/reset-password/reset_password.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +31,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("reset-password %s", userIdArg), Short: "Resets the password of a MongoDB Flex user", @@ -53,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to reset the password of user %q of instance %q? (This cannot be undone)", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,10 +83,10 @@ func NewCmd() *cobra.Command { return fmt.Errorf("reset MongoDB Flex user password: %w", err) } - cmd.Printf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) - cmd.Printf("Username: %s\n", *user.Username) - cmd.Printf("New password: %s\n", *user.Password) - cmd.Printf("New URI: %s\n", *user.Uri) + p.Outputf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) + p.Outputf("Username: %s\n", *user.Username) + p.Outputf("New password: %s\n", *user.Password) + p.Outputf("New URI: %s\n", *user.Uri) return nil }, } diff --git a/internal/cmd/mongodbflex/user/reset-password/reset_password_test.go b/internal/cmd/mongodbflex/user/reset-password/reset_password_test.go index 103ab19f0..20c1fbff9 100644 --- a/internal/cmd/mongodbflex/user/reset-password/reset_password_test.go +++ b/internal/cmd/mongodbflex/user/reset-password/reset_password_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/user/update/update.go b/internal/cmd/mongodbflex/user/update/update.go index 8e202aea7..a42abd00f 100644 --- a/internal/cmd/mongodbflex/user/update/update.go +++ b/internal/cmd/mongodbflex/user/update/update.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/client" mongodbflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/mongodbflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -35,7 +35,7 @@ type inputModel struct { Roles *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", userIdArg), Short: "Updates a MongoDB Flex user", @@ -54,7 +54,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +71,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update user %q of instance %q?", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -84,7 +84,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("update MongoDB Flex user: %w", err) } - cmd.Printf("Updated user %q of instance %q\n", userLabel, instanceLabel) + p.Info("Updated user %q of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/mongodbflex/user/update/update_test.go b/internal/cmd/mongodbflex/user/update/update_test.go index 223325c57..6d4029141 100644 --- a/internal/cmd/mongodbflex/user/update/update_test.go +++ b/internal/cmd/mongodbflex/user/update/update_test.go @@ -49,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -194,7 +195,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/mongodbflex/user/user.go b/internal/cmd/mongodbflex/user/user.go index 9bdb12903..614b7c2f9 100644 --- a/internal/cmd/mongodbflex/user/user.go +++ b/internal/cmd/mongodbflex/user/user.go @@ -8,12 +8,13 @@ import ( resetpassword "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/reset-password" "github.com/stackitcloud/stackit-cli/internal/cmd/mongodbflex/user/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "user", Short: "Provides functionality for MongoDB Flex users", @@ -21,15 +22,15 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(resetpassword.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(resetpassword.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/object-storage/bucket/bucket.go b/internal/cmd/object-storage/bucket/bucket.go index 5b0e1638b..701fc0934 100644 --- a/internal/cmd/object-storage/bucket/bucket.go +++ b/internal/cmd/object-storage/bucket/bucket.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "bucket", Short: "Provides functionality for Object Storage buckets", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/object-storage/bucket/create/create.go b/internal/cmd/object-storage/bucket/create/create.go index e05a060b9..32aeb74dd 100644 --- a/internal/cmd/object-storage/bucket/create/create.go +++ b/internal/cmd/object-storage/bucket/create/create.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { BucketName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("create %s", bucketNameArg), Short: "Creates an Object Storage bucket", @@ -45,14 +45,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create bucket %q? (This cannot be undone)", model.BucketName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -67,7 +67,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating bucket") _, err = wait.CreateBucketWaitHandler(ctx, apiClient, model.ProjectId, model.BucketName).WaitWithContext(ctx) if err != nil { @@ -80,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s bucket %q\n", operationState, model.BucketName) + p.Outputf("%s bucket %q\n", operationState, model.BucketName) return nil }, } diff --git a/internal/cmd/object-storage/bucket/create/create_test.go b/internal/cmd/object-storage/bucket/create/create_test.go index 2cf5e65e6..524091713 100644 --- a/internal/cmd/object-storage/bucket/create/create_test.go +++ b/internal/cmd/object-storage/bucket/create/create_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, BucketName: testBucketName, } @@ -129,7 +130,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/bucket/delete/delete.go b/internal/cmd/object-storage/bucket/delete/delete.go index d4d92e3e1..2b98854b0 100644 --- a/internal/cmd/object-storage/bucket/delete/delete.go +++ b/internal/cmd/object-storage/bucket/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { BucketName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", bucketNameArg), Short: "Deletes an Object Storage bucket", @@ -45,14 +45,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete bucket %q? (This cannot be undone)", model.BucketName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -67,7 +67,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting bucket") _, err = wait.DeleteBucketWaitHandler(ctx, apiClient, model.ProjectId, model.BucketName).WaitWithContext(ctx) if err != nil { @@ -80,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s bucket %q\n", operationState, model.BucketName) + p.Info("%s bucket %q\n", operationState, model.BucketName) return nil }, } diff --git a/internal/cmd/object-storage/bucket/delete/delete_test.go b/internal/cmd/object-storage/bucket/delete/delete_test.go index 1648a3989..3b2037735 100644 --- a/internal/cmd/object-storage/bucket/delete/delete_test.go +++ b/internal/cmd/object-storage/bucket/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, BucketName: testBucketName, } @@ -129,7 +130,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/bucket/describe/describe.go b/internal/cmd/object-storage/bucket/describe/describe.go index c3853e240..9d95041b5 100644 --- a/internal/cmd/object-storage/bucket/describe/describe.go +++ b/internal/cmd/object-storage/bucket/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -25,7 +26,7 @@ type inputModel struct { BucketName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", bucketNameArg), Short: "Shows details of an Object Storage bucket", @@ -46,7 +47,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -58,7 +59,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read Object Storage bucket: %w", err) } - return outputResult(cmd, model.OutputFormat, resp.Bucket) + return outputResult(p, model.OutputFormat, resp.Bucket) }, } return cmd @@ -83,7 +84,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstora return req } -func outputResult(cmd *cobra.Command, outputFormat string, bucket *objectstorage.Bucket) error { +func outputResult(p *print.Printer, outputFormat string, bucket *objectstorage.Bucket) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -95,7 +96,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, bucket *objectstorage table.AddSeparator() table.AddRow("URL (Virtual Hosted Style)", *bucket.UrlVirtualHostedStyle) table.AddSeparator() - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -106,7 +107,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, bucket *objectstorage if err != nil { return fmt.Errorf("marshal Object Storage bucket: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/object-storage/bucket/describe/describe_test.go b/internal/cmd/object-storage/bucket/describe/describe_test.go index 8a57f6c25..e23245368 100644 --- a/internal/cmd/object-storage/bucket/describe/describe_test.go +++ b/internal/cmd/object-storage/bucket/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, BucketName: testBucketName, } @@ -129,7 +130,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/bucket/list/list.go b/internal/cmd/object-storage/bucket/list/list.go index e716b1078..e2f79f87a 100644 --- a/internal/cmd/object-storage/bucket/list/list.go +++ b/internal/cmd/object-storage/bucket/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all Object Storage buckets", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,11 +65,11 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get Object Storage buckets: %w", err) } if resp.Buckets == nil || len(*resp.Buckets) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No buckets found for project %s\n", projectLabel) + p.Info("No buckets found for project %s\n", projectLabel) return nil } buckets := *resp.Buckets @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { buckets = buckets[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, buckets) + return outputResult(p, model.OutputFormat, buckets) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstora return req } -func outputResult(cmd *cobra.Command, outputFormat string, buckets []objectstorage.Bucket) error { +func outputResult(p *print.Printer, outputFormat string, buckets []objectstorage.Bucket) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(buckets, "", " ") if err != nil { return fmt.Errorf("marshal Object Storage bucket list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, buckets []objectstora bucket := buckets[i] table.AddRow(*bucket.Name, *bucket.Region, *bucket.UrlPathStyle, *bucket.UrlVirtualHostedStyle) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/object-storage/bucket/list/list_test.go b/internal/cmd/object-storage/bucket/list/list_test.go index 4c50f6931..7d83b76e0 100644 --- a/internal/cmd/object-storage/bucket/list/list_test.go +++ b/internal/cmd/object-storage/bucket/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/object-storage/credentials-group/create/create.go b/internal/cmd/object-storage/credentials-group/create/create.go index f441b99dc..2dd24a759 100644 --- a/internal/cmd/object-storage/credentials-group/create/create.go +++ b/internal/cmd/object-storage/credentials-group/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -26,7 +26,7 @@ type inputModel struct { CredentialsGroupName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a credentials group to hold Object Storage access credentials", @@ -45,14 +45,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a credentials group with name %q?", model.CredentialsGroupName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -65,8 +65,8 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create Object Storage credentials group: %w", err) } - cmd.Printf("Created credentials group %q. Credentials group ID: %s\n\n", *resp.CredentialsGroup.DisplayName, *resp.CredentialsGroup.CredentialsGroupId) - cmd.Printf("URN: %s\n", *resp.CredentialsGroup.Urn) + p.Outputf("Created credentials group %q. Credentials group ID: %s\n\n", *resp.CredentialsGroup.DisplayName, *resp.CredentialsGroup.CredentialsGroupId) + p.Outputf("URN: %s\n", *resp.CredentialsGroup.Urn) return nil }, } diff --git a/internal/cmd/object-storage/credentials-group/create/create_test.go b/internal/cmd/object-storage/credentials-group/create/create_test.go index 72e5d55e4..5b5fbc95a 100644 --- a/internal/cmd/object-storage/credentials-group/create/create_test.go +++ b/internal/cmd/object-storage/credentials-group/create/create_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, CredentialsGroupName: testCredentialsGroupName, } @@ -115,7 +116,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/credentials-group/credentials_group.go b/internal/cmd/object-storage/credentials-group/credentials_group.go index 6427642ef..0803796f4 100644 --- a/internal/cmd/object-storage/credentials-group/credentials_group.go +++ b/internal/cmd/object-storage/credentials-group/credentials_group.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/credentials-group/delete" "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/credentials-group/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials-group", Short: "Provides functionality for Object Storage credentials group", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/object-storage/credentials-group/delete/delete.go b/internal/cmd/object-storage/credentials-group/delete/delete.go index bdc519414..d0ecf5fd5 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -26,7 +26,7 @@ type inputModel struct { CredentialsGroupId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsGroupIdArg), Short: "Deletes a credentials group that holds Object Storage access credentials", @@ -45,7 +45,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -57,7 +57,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials group %q? (This cannot be undone)", credentialsGroupLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete Object Storage credentials group: %w", err) } - cmd.Printf("Deleted credentials group %q\n", credentialsGroupLabel) + p.Info("Deleted credentials group %q\n", credentialsGroupLabel) return nil }, } diff --git a/internal/cmd/object-storage/credentials-group/delete/delete_test.go b/internal/cmd/object-storage/credentials-group/delete/delete_test.go index fc00516a3..d29e79f99 100644 --- a/internal/cmd/object-storage/credentials-group/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials-group/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, CredentialsGroupId: testCredentialsGroupId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/credentials-group/list/list.go b/internal/cmd/object-storage/credentials-group/list/list.go index 135b969e4..789a407b9 100644 --- a/internal/cmd/object-storage/credentials-group/list/list.go +++ b/internal/cmd/object-storage/credentials-group/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -26,7 +27,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials groups that hold Object Storage access credentials", @@ -51,7 +52,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { } credentialsGroups := *resp.CredentialsGroups if len(credentialsGroups) == 0 { - cmd.Println("No credentials groups found for your project") + p.Info("No credentials groups found for your project") return nil } @@ -72,7 +73,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentialsGroups) > int(*model.Limit) { credentialsGroups = credentialsGroups[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentialsGroups) + return outputResult(p, model.OutputFormat, credentialsGroups) }, } configureFlags(cmd) @@ -108,14 +109,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstora return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentialsGroups []objectstorage.CredentialsGroup) error { +func outputResult(p *print.Printer, outputFormat string, credentialsGroups []objectstorage.CredentialsGroup) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentialsGroups, "", " ") if err != nil { return fmt.Errorf("marshal Object Storage credentials group list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -125,7 +126,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentialsGroups []o c := credentialsGroups[i] table.AddRow(*c.CredentialsGroupId, *c.DisplayName, *c.Urn) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/object-storage/credentials-group/list/list_test.go b/internal/cmd/object-storage/credentials-group/list/list_test.go index 0658184a5..a8058e24e 100644 --- a/internal/cmd/object-storage/credentials-group/list/list_test.go +++ b/internal/cmd/object-storage/credentials-group/list/list_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } @@ -110,7 +111,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/credentials/create/create.go b/internal/cmd/object-storage/credentials/create/create.go index 7088e1874..db2118384 100644 --- a/internal/cmd/object-storage/credentials/create/create.go +++ b/internal/cmd/object-storage/credentials/create/create.go @@ -9,11 +9,11 @@ import ( "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) @@ -31,7 +31,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for an Object Storage credentials group", @@ -53,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,7 +65,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials in group %q?", credentialsGroupLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,10 +83,10 @@ func NewCmd() *cobra.Command { expireDate = *resp.Expires } - cmd.Printf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, *resp.KeyId) - cmd.Printf("Access Key ID: %s\n", *resp.AccessKey) - cmd.Printf("Secret Access Key: %s\n", *resp.SecretAccessKey) - cmd.Printf("Expire Date: %s\n", expireDate) + p.Outputf("Created credentials in group %q. Credentials ID: %s\n\n", credentialsGroupLabel, *resp.KeyId) + p.Outputf("Access Key ID: %s\n", *resp.AccessKey) + p.Outputf("Secret Access Key: %s\n", *resp.SecretAccessKey) + p.Outputf("Expire Date: %s\n", expireDate) return nil }, diff --git a/internal/cmd/object-storage/credentials/create/create_test.go b/internal/cmd/object-storage/credentials/create/create_test.go index c9c5e1b8d..b13fa63e5 100644 --- a/internal/cmd/object-storage/credentials/create/create_test.go +++ b/internal/cmd/object-storage/credentials/create/create_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ExpireDate: utils.Ptr(testExpirationDate), CredentialsGroupId: testCredentialsGroupId, @@ -174,7 +175,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/credentials/credentials.go b/internal/cmd/object-storage/credentials/credentials.go index 4914945e9..e96b86072 100644 --- a/internal/cmd/object-storage/credentials/credentials.go +++ b/internal/cmd/object-storage/credentials/credentials.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/credentials/delete" "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for Object Storage credentials", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/object-storage/credentials/delete/delete.go b/internal/cmd/object-storage/credentials/delete/delete.go index 3a029e0f3..5836e5373 100644 --- a/internal/cmd/object-storage/credentials/delete/delete.go +++ b/internal/cmd/object-storage/credentials/delete/delete.go @@ -6,11 +6,11 @@ import ( "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" objectStorageUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/utils" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" @@ -27,7 +27,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of an Object Storage credentials group", @@ -46,7 +46,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -63,7 +63,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %q of credentials group %q? (This cannot be undone)", credentialsLabel, credentialsGroupLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete Object Storage credentials: %w", err) } - cmd.Printf("Deleted credentials %q of credentials group %q\n", credentialsLabel, credentialsGroupLabel) + p.Info("Deleted credentials %q of credentials group %q\n", credentialsLabel, credentialsGroupLabel) return nil }, } diff --git a/internal/cmd/object-storage/credentials/delete/delete_test.go b/internal/cmd/object-storage/credentials/delete/delete_test.go index c160315af..bc023ebf2 100644 --- a/internal/cmd/object-storage/credentials/delete/delete_test.go +++ b/internal/cmd/object-storage/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, CredentialsGroupId: testCredentialsGroupId, CredentialsId: testCredentialsId, @@ -154,7 +155,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/credentials/list/list.go b/internal/cmd/object-storage/credentials/list/list.go index f982bd44e..b38ee23cb 100644 --- a/internal/cmd/object-storage/credentials/list/list.go +++ b/internal/cmd/object-storage/credentials/list/list.go @@ -12,6 +12,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials for an Object Storage credentials group", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -73,7 +74,7 @@ func NewCmd() *cobra.Command { credentialsGroupLabel = model.CredentialsGroupId } - cmd.Printf("No credentials found for credentials group %q\n", credentialsGroupLabel) + p.Info("No credentials found for credentials group %q\n", credentialsGroupLabel) return nil } @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -123,14 +124,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstora return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []objectstorage.AccessKey) error { +func outputResult(p *print.Printer, outputFormat string, credentials []objectstorage.AccessKey) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal Object Storage credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -145,7 +146,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []objects } table.AddRow(*c.KeyId, *c.DisplayName, expiresAt) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/object-storage/credentials/list/list_test.go b/internal/cmd/object-storage/credentials/list/list_test.go index fa828642e..32feb5457 100644 --- a/internal/cmd/object-storage/credentials/list/list_test.go +++ b/internal/cmd/object-storage/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, CredentialsGroupId: testCredentialsGroupId, Limit: utils.Ptr(int64(10)), @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/object-storage/disable/disable.go b/internal/cmd/object-storage/disable/disable.go index 44a701f9c..8c5f91adf 100644 --- a/internal/cmd/object-storage/disable/disable.go +++ b/internal/cmd/object-storage/disable/disable.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" @@ -20,7 +20,7 @@ type InputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "disable", Short: "Disables Object Storage for a project", @@ -39,19 +39,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to disable Object Storage for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered disablement of" } - cmd.Printf("%s Object Storage for project %q\n", operationState, projectLabel) + p.Info("%s Object Storage for project %q\n", operationState, projectLabel) return nil }, } diff --git a/internal/cmd/object-storage/disable/disable_test.go b/internal/cmd/object-storage/disable/disable_test.go index 1512e1168..8a52bbf27 100644 --- a/internal/cmd/object-storage/disable/disable_test.go +++ b/internal/cmd/object-storage/disable/disable_test.go @@ -35,6 +35,7 @@ func fixtureInputModel(mods ...func(model *InputModel)) *InputModel { model := &InputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/object-storage/enable/enable.go b/internal/cmd/object-storage/enable/enable.go index f76ab50b7..1f77a6b06 100644 --- a/internal/cmd/object-storage/enable/enable.go +++ b/internal/cmd/object-storage/enable/enable.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client" @@ -20,7 +20,7 @@ type InputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "enable", Short: "Enables Object Storage for a project", @@ -39,19 +39,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to enable Object Storage for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered enablement of" } - cmd.Printf("%s Object Storage for project %q\n", operationState, projectLabel) + p.Info("%s Object Storage for project %q\n", operationState, projectLabel) return nil }, } diff --git a/internal/cmd/object-storage/enable/enable_test.go b/internal/cmd/object-storage/enable/enable_test.go index 03cd814f8..1c12bd918 100644 --- a/internal/cmd/object-storage/enable/enable_test.go +++ b/internal/cmd/object-storage/enable/enable_test.go @@ -35,6 +35,7 @@ func fixtureInputModel(mods ...func(model *InputModel)) *InputModel { model := &InputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/object-storage/object_storage.go b/internal/cmd/object-storage/object_storage.go index c3a1a38f0..a612598d3 100644 --- a/internal/cmd/object-storage/object_storage.go +++ b/internal/cmd/object-storage/object_storage.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/disable" "github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/enable" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "object-storage", Short: "Provides functionality regarding Object Storage", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(bucket.NewCmd()) - cmd.AddCommand(disable.NewCmd()) - cmd.AddCommand(enable.NewCmd()) - cmd.AddCommand(credentialsGroup.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(bucket.NewCmd(p)) + cmd.AddCommand(disable.NewCmd(p)) + cmd.AddCommand(enable.NewCmd(p)) + cmd.AddCommand(credentialsGroup.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/opensearch/credentials/create/create.go b/internal/cmd/opensearch/credentials/create/create.go index 4cb9ac1c1..824ba135f 100644 --- a/internal/cmd/opensearch/credentials/create/create.go +++ b/internal/cmd/opensearch/credentials/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" @@ -28,7 +28,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for an OpenSearch instance", @@ -50,7 +50,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -75,19 +75,19 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create OpenSearch credentials: %w", err) } - cmd.Printf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty username := *resp.Raw.Credentials.Username if username != "" { - cmd.Printf("Username: %s\n", *resp.Raw.Credentials.Username) + p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } if model.HidePassword { - cmd.Printf("Password: \n") + p.Outputf("Password: \n") } else { - cmd.Printf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) } - cmd.Printf("Host: %s\n", *resp.Raw.Credentials.Host) - cmd.Printf("Port: %d\n", *resp.Raw.Credentials.Port) - cmd.Printf("URI: %s\n", *resp.Uri) + p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) + p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) + p.Outputf("URI: %s\n", *resp.Uri) return nil }, } diff --git a/internal/cmd/opensearch/credentials/create/create_test.go b/internal/cmd/opensearch/credentials/create/create_test.go index 5ba51a1f2..5ec06a4ae 100644 --- a/internal/cmd/opensearch/credentials/create/create_test.go +++ b/internal/cmd/opensearch/credentials/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -117,7 +118,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/credentials/credentials.go b/internal/cmd/opensearch/credentials/credentials.go index e890f45a4..4ea7f3f76 100644 --- a/internal/cmd/opensearch/credentials/credentials.go +++ b/internal/cmd/opensearch/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for OpenSearch credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/opensearch/credentials/delete/delete.go b/internal/cmd/opensearch/credentials/delete/delete.go index cc4a97a82..13c4d8065 100644 --- a/internal/cmd/opensearch/credentials/delete/delete.go +++ b/internal/cmd/opensearch/credentials/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of an OpenSearch instance", @@ -49,7 +49,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %s of instance %q? (This cannot be undone)", credentialsLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -79,7 +79,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete OpenSearch credentials: %w", err) } - cmd.Printf("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) + p.Info("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/opensearch/credentials/delete/delete_test.go b/internal/cmd/opensearch/credentials/delete/delete_test.go index ad1a9a41f..276e68eaa 100644 --- a/internal/cmd/opensearch/credentials/delete/delete_test.go +++ b/internal/cmd/opensearch/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/credentials/describe/describe.go b/internal/cmd/opensearch/credentials/describe/describe.go index eb826e495..4b8c35cb6 100644 --- a/internal/cmd/opensearch/credentials/describe/describe.go +++ b/internal/cmd/opensearch/credentials/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", credentialsIdArg), Short: "Shows details of credentials of an OpenSearch instance", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("describe OpenSearch credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -98,7 +99,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch. return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *opensearch.CredentialsResponse) error { +func outputResult(p *print.Printer, outputFormat string, credentials *opensearch.CredentialsResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -113,7 +114,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *opensear table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) table.AddSeparator() table.AddRow("URI", *credentials.Raw.Credentials.Uri) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *opensear if err != nil { return fmt.Errorf("marshal OpenSearch credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/opensearch/credentials/describe/describe_test.go b/internal/cmd/opensearch/credentials/describe/describe_test.go index e72ed1694..5b1354aeb 100644 --- a/internal/cmd/opensearch/credentials/describe/describe_test.go +++ b/internal/cmd/opensearch/credentials/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/credentials/list/list.go b/internal/cmd/opensearch/credentials/list/list.go index d5c5c7c59..ccb2dbfe3 100644 --- a/internal/cmd/opensearch/credentials/list/list.go +++ b/internal/cmd/opensearch/credentials/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials' IDs for an OpenSearch instance", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = model.InstanceId } - cmd.Printf("No credentials found for instance %q\n", instanceLabel) + p.Info("No credentials found for instance %q\n", instanceLabel) return nil } @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -120,14 +121,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch. return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []opensearch.CredentialsListItem) error { +func outputResult(p *print.Printer, outputFormat string, credentials []opensearch.CredentialsListItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal OpenSearch credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []opensea c := credentials[i] table.AddRow(*c.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/opensearch/credentials/list/list_test.go b/internal/cmd/opensearch/credentials/list/list_test.go index 4c503e18f..3cd807c35 100644 --- a/internal/cmd/opensearch/credentials/list/list_test.go +++ b/internal/cmd/opensearch/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Limit: utils.Ptr(int64(10)), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/instance/create/create.go b/internal/cmd/opensearch/instance/create/create.go index 18c948aa2..fec307f1f 100644 --- a/internal/cmd/opensearch/instance/create/create.go +++ b/internal/cmd/opensearch/instance/create/create.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" @@ -55,7 +55,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates an OpenSearch instance", @@ -80,19 +80,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create an OpenSearch instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/opensearch/instance/create/create_test.go b/internal/cmd/opensearch/instance/create/create_test.go index 6a6679242..e123fdaf4 100644 --- a/internal/cmd/opensearch/instance/create/create_test.go +++ b/internal/cmd/opensearch/instance/create/create_test.go @@ -65,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), EnableMonitoring: utils.Ptr(true), @@ -151,6 +152,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -171,6 +173,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -272,7 +275,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -437,6 +440,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), }, diff --git a/internal/cmd/opensearch/instance/delete/delete.go b/internal/cmd/opensearch/instance/delete/delete.go index 49b54f582..a4ee8cff2 100644 --- a/internal/cmd/opensearch/instance/delete/delete.go +++ b/internal/cmd/opensearch/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes an OpenSearch instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/opensearch/instance/delete/delete_test.go b/internal/cmd/opensearch/instance/delete/delete_test.go index 3f6042eb9..4ef2fc8a8 100644 --- a/internal/cmd/opensearch/instance/delete/delete_test.go +++ b/internal/cmd/opensearch/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/instance/describe/describe.go b/internal/cmd/opensearch/instance/describe/describe.go index 13e189ec8..30063cf8f 100644 --- a/internal/cmd/opensearch/instance/describe/describe.go +++ b/internal/cmd/opensearch/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of an OpenSearch instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read OpenSearch instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch. return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *opensearch.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *opensearch.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -108,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *opensearch. table.AddRow("ACL", aclStr) } } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -119,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *opensearch. if err != nil { return fmt.Errorf("marshal OpenSearch instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/opensearch/instance/describe/describe_test.go b/internal/cmd/opensearch/instance/describe/describe_test.go index 6881ec419..f93c14d58 100644 --- a/internal/cmd/opensearch/instance/describe/describe_test.go +++ b/internal/cmd/opensearch/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/opensearch/instance/instance.go b/internal/cmd/opensearch/instance/instance.go index 790526952..649d439ce 100644 --- a/internal/cmd/opensearch/instance/instance.go +++ b/internal/cmd/opensearch/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for OpenSearch instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/opensearch/instance/list/list.go b/internal/cmd/opensearch/instance/list/list.go index 67cb15d5e..61eebea26 100644 --- a/internal/cmd/opensearch/instance/list/list.go +++ b/internal/cmd/opensearch/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all OpenSearch instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch. return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []opensearch.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []opensearch.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal OpenSearch instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []opensearc instance := instances[i] table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/opensearch/instance/list/list_test.go b/internal/cmd/opensearch/instance/list/list_test.go index 17f77beb8..fad552b73 100644 --- a/internal/cmd/opensearch/instance/list/list_test.go +++ b/internal/cmd/opensearch/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/opensearch/instance/update/update.go b/internal/cmd/opensearch/instance/update/update.go index f7eeba84a..82ff1ce5b 100644 --- a/internal/cmd/opensearch/instance/update/update.go +++ b/internal/cmd/opensearch/instance/update/update.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" opensearchUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -56,7 +56,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates an OpenSearch instance", @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -113,7 +113,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -126,7 +126,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/opensearch/instance/update/update_test.go b/internal/cmd/opensearch/instance/update/update_test.go index 7623b7dde..628f898ea 100644 --- a/internal/cmd/opensearch/instance/update/update_test.go +++ b/internal/cmd/opensearch/instance/update/update_test.go @@ -77,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, EnableMonitoring: utils.Ptr(true), @@ -162,6 +163,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, @@ -181,6 +183,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testPlanId), @@ -289,7 +292,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -462,6 +465,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, diff --git a/internal/cmd/opensearch/opensearch.go b/internal/cmd/opensearch/opensearch.go index c432ea875..08103e63c 100644 --- a/internal/cmd/opensearch/opensearch.go +++ b/internal/cmd/opensearch/opensearch.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/opensearch/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "opensearch", Short: "Provides functionality for OpenSearch", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/opensearch/plans/plans.go b/internal/cmd/opensearch/plans/plans.go index e46bbb888..3c3f8d7ac 100644 --- a/internal/cmd/opensearch/plans/plans.go +++ b/internal/cmd/opensearch/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/opensearch/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all OpenSearch service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Offerings if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *opensearch. return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []opensearch.Offering) error { +func outputResult(p *print.Printer, outputFormat string, plans []opensearch.Offering) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal OpenSearch plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -131,13 +132,13 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []opensearch.Of for i := range plans { o := plans[i] for j := range *o.Plans { - p := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *p.Id, *p.Name, *p.Description) + plan := (*o.Plans)[j] + table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) } table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/opensearch/plans/plans_test.go b/internal/cmd/opensearch/plans/plans_test.go index d0f656b7f..dbd843a56 100644 --- a/internal/cmd/opensearch/plans/plans_test.go +++ b/internal/cmd/opensearch/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/organization/member/add/add.go b/internal/cmd/organization/member/add/add.go index bed1c53fb..2afc5e32b 100644 --- a/internal/cmd/organization/member/add/add.go +++ b/internal/cmd/organization/member/add/add.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -33,7 +33,7 @@ type inputModel struct { Role *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("add %s", subjectArg), Short: "Adds a member to an organization", @@ -59,14 +59,14 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to add the %s role to %s on organization with ID %q?", *model.Role, model.Subject, *model.OrganizationId) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("add member: %w", err) } - cmd.Println("Member added") + p.Info("Member added") return nil }, } diff --git a/internal/cmd/organization/member/add/add_test.go b/internal/cmd/organization/member/add/add_test.go index 8bfb8c6c8..dae68d183 100644 --- a/internal/cmd/organization/member/add/add_test.go +++ b/internal/cmd/organization/member/add/add_test.go @@ -43,7 +43,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, OrganizationId: utils.Ptr(testOrganizationID), Subject: testSubject, Role: utils.Ptr(testRole), @@ -123,7 +123,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/organization/member/list/list.go b/internal/cmd/organization/member/list/list.go index f44a60180..46af0d0ab 100644 --- a/internal/cmd/organization/member/list/list.go +++ b/internal/cmd/organization/member/list/list.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -36,7 +37,7 @@ type inputModel struct { SortBy string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists members of an organization", @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -74,7 +75,7 @@ func NewCmd() *cobra.Command { } members := *resp.Members if len(members) == 0 { - cmd.Printf("No members found for organization with ID %q\n", *model.OrganizationId) + p.Info("No members found for organization with ID %q\n", *model.OrganizationId) return nil } @@ -83,7 +84,7 @@ func NewCmd() *cobra.Command { members = members[:*model.Limit] } - return outputResult(cmd, model, members) + return outputResult(p, model, members) }, } configureFlags(cmd) @@ -130,7 +131,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *authorizati return req } -func outputResult(cmd *cobra.Command, model *inputModel, members []authorization.Member) error { +func outputResult(p *print.Printer, model *inputModel, members []authorization.Member) error { sortFn := func(i, j int) bool { switch model.SortBy { case "subject": @@ -150,7 +151,7 @@ func outputResult(cmd *cobra.Command, model *inputModel, members []authorization if err != nil { return fmt.Errorf("marshal members: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -171,7 +172,7 @@ func outputResult(cmd *cobra.Command, model *inputModel, members []authorization table.EnableAutoMergeOnColumns(2) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/organization/member/list/list_test.go b/internal/cmd/organization/member/list/list_test.go index dd7819331..48800ae1c 100644 --- a/internal/cmd/organization/member/list/list_test.go +++ b/internal/cmd/organization/member/list/list_test.go @@ -32,7 +32,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, OrganizationId: utils.Ptr(testOrganizationID), Limit: utils.Ptr(int64(10)), SortBy: "subject", diff --git a/internal/cmd/organization/member/member.go b/internal/cmd/organization/member/member.go index 0d4737b64..fecdcfc1a 100644 --- a/internal/cmd/organization/member/member.go +++ b/internal/cmd/organization/member/member.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/organization/member/list" "github.com/stackitcloud/stackit-cli/internal/cmd/organization/member/remove" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "member", Short: "Provides functionality regarding organization members", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(add.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(remove.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(add.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(remove.NewCmd(p)) } diff --git a/internal/cmd/organization/member/remove/remove.go b/internal/cmd/organization/member/remove/remove.go index 194f79d8a..2a3dad778 100644 --- a/internal/cmd/organization/member/remove/remove.go +++ b/internal/cmd/organization/member/remove/remove.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -35,7 +35,7 @@ type inputModel struct { Force bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("remove %s", subjectArg), Short: "Removes a member from an organization", @@ -61,7 +61,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +71,7 @@ func NewCmd() *cobra.Command { if model.Force { prompt = fmt.Sprintf("%s This will also remove other roles of the subject that would stop the removal of the requested role", prompt) } - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -84,7 +84,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("remove member: %w", err) } - cmd.Println("Member removed") + p.Info("Member removed") return nil }, } diff --git a/internal/cmd/organization/member/remove/remove_test.go b/internal/cmd/organization/member/remove/remove_test.go index 6ba7eff7a..4befba92a 100644 --- a/internal/cmd/organization/member/remove/remove_test.go +++ b/internal/cmd/organization/member/remove/remove_test.go @@ -43,7 +43,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, OrganizationId: utils.Ptr(testOrganizationID), Subject: testSubject, Role: utils.Ptr(testRole), @@ -136,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/organization/organization.go b/internal/cmd/organization/organization.go index 179b4b37b..fb2b6ca57 100644 --- a/internal/cmd/organization/organization.go +++ b/internal/cmd/organization/organization.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/organization/member" "github.com/stackitcloud/stackit-cli/internal/cmd/organization/role" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "organization", Short: "Provides functionality regarding organizations", @@ -22,11 +23,11 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(member.NewCmd()) - cmd.AddCommand(role.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(member.NewCmd(p)) + cmd.AddCommand(role.NewCmd(p)) } diff --git a/internal/cmd/organization/role/list/list.go b/internal/cmd/organization/role/list/list.go index 0cbca1621..e0af5e6cd 100644 --- a/internal/cmd/organization/role/list/list.go +++ b/internal/cmd/organization/role/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -31,7 +32,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists roles and permissions of an organization", @@ -56,7 +57,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -69,7 +70,7 @@ func NewCmd() *cobra.Command { } roles := *resp.Roles if len(roles) == 0 { - cmd.Printf("No roles found for organization with ID %q\n", *model.OrganizationId) + p.Info("No roles found for organization with ID %q\n", *model.OrganizationId) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { roles = roles[:*model.Limit] } - return outputRolesResult(cmd, model.OutputFormat, roles) + return outputRolesResult(p, model.OutputFormat, roles) }, } configureFlags(cmd) @@ -115,7 +116,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *authorizati return apiClient.ListRoles(ctx, organizationResourceType, *model.OrganizationId) } -func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authorization.Role) error { +func outputRolesResult(p *print.Printer, outputFormat string, roles []authorization.Role) error { switch outputFormat { case globalflags.JSONOutputFormat: // Show details @@ -123,7 +124,7 @@ func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authoriz if err != nil { return fmt.Errorf("marshal roles: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -138,7 +139,7 @@ func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authoriz table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/organization/role/list/list_test.go b/internal/cmd/organization/role/list/list_test.go index 4e6ee570a..413a3d072 100644 --- a/internal/cmd/organization/role/list/list_test.go +++ b/internal/cmd/organization/role/list/list_test.go @@ -32,7 +32,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, OrganizationId: utils.Ptr(testOrganizationID), Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/organization/role/role.go b/internal/cmd/organization/role/role.go index e35e2e3ef..41f87752a 100644 --- a/internal/cmd/organization/role/role.go +++ b/internal/cmd/organization/role/role.go @@ -3,12 +3,13 @@ package role import ( "github.com/stackitcloud/stackit-cli/internal/cmd/organization/role/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "role", Short: "Provides functionality regarding organization roles", @@ -16,10 +17,10 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/postgresflex/instance/clone/clone.go b/internal/cmd/postgresflex/instance/clone/clone.go index 3bea17ed3..68d248cb8 100644 --- a/internal/cmd/postgresflex/instance/clone/clone.go +++ b/internal/cmd/postgresflex/instance/clone/clone.go @@ -6,11 +6,11 @@ import ( "time" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -39,7 +39,7 @@ type inputModel struct { RecoveryDate *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("clone %s", instanceIdArg), Short: "Clones a PostgreSQL Flex instance", @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to clone instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -97,7 +97,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Cloning instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -111,7 +111,7 @@ func NewCmd() *cobra.Command { operationState = "Triggered cloning of" } - cmd.Printf("%s instance from instance %q. New Instance ID: %s\n", operationState, instanceLabel, instanceId) + p.Info("%s instance from instance %q. New Instance ID: %s\n", operationState, instanceLabel, instanceId) return nil }, } diff --git a/internal/cmd/postgresflex/instance/clone/clone_test.go b/internal/cmd/postgresflex/instance/clone/clone_test.go index 4eb2c11b3..f84f42f40 100644 --- a/internal/cmd/postgresflex/instance/clone/clone_test.go +++ b/internal/cmd/postgresflex/instance/clone/clone_test.go @@ -98,6 +98,7 @@ func fixtureRequiredInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, RecoveryDate: utils.Ptr(recoveryTimestampString), @@ -118,6 +119,7 @@ func fixtureStandardInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, StorageClass: utils.Ptr(testStorageClass), @@ -296,7 +298,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/instance/create/create.go b/internal/cmd/postgresflex/instance/create/create.go index 8e43ae3a8..6d8696eb3 100644 --- a/internal/cmd/postgresflex/instance/create/create.go +++ b/internal/cmd/postgresflex/instance/create/create.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" @@ -55,7 +55,7 @@ type inputModel struct { Type *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a PostgreSQL Flex instance", @@ -81,19 +81,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a PostgreSQL Flex instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -121,7 +121,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -134,7 +134,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/postgresflex/instance/create/create_test.go b/internal/cmd/postgresflex/instance/create/create_test.go index 53babd3b8..69e348237 100644 --- a/internal/cmd/postgresflex/instance/create/create_test.go +++ b/internal/cmd/postgresflex/instance/create/create_test.go @@ -71,6 +71,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), ACL: utils.Ptr([]string{"0.0.0.0/0"}), @@ -247,7 +248,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/instance/delete/delete.go b/internal/cmd/postgresflex/instance/delete/delete.go index 025d1bf0f..bf98e4464 100644 --- a/internal/cmd/postgresflex/instance/delete/delete.go +++ b/internal/cmd/postgresflex/instance/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -32,7 +32,7 @@ type inputModel struct { ForceDelete bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a PostgreSQL Flex instance", @@ -58,7 +58,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -91,7 +91,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -111,7 +111,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Forcing deletion of instance") _, err = wait.ForceDeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -131,8 +131,7 @@ func NewCmd() *cobra.Command { operationState = "Triggered forced deletion of" } } - - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/postgresflex/instance/delete/delete_test.go b/internal/cmd/postgresflex/instance/delete/delete_test.go index 26197f744..60b1fd00a 100644 --- a/internal/cmd/postgresflex/instance/delete/delete_test.go +++ b/internal/cmd/postgresflex/instance/delete/delete_test.go @@ -69,6 +69,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -167,7 +168,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/instance/describe/describe.go b/internal/cmd/postgresflex/instance/describe/describe.go index bf280a125..4836bc0cb 100644 --- a/internal/cmd/postgresflex/instance/describe/describe.go +++ b/internal/cmd/postgresflex/instance/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a PostgreSQL Flex instance", @@ -51,7 +52,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -63,7 +64,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read PostgreSQL Flex instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp.Item) + return outputResult(p, model.OutputFormat, resp.Item) }, } return cmd @@ -88,7 +89,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *postgresflex.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *postgresflex.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: aclsArray := *instance.Acl.Items @@ -123,7 +124,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *postgresfle table.AddSeparator() table.AddRow("RAM", *instance.Flavor.Memory) table.AddSeparator() - err = table.Display(cmd) + err = table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -134,7 +135,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *postgresfle if err != nil { return fmt.Errorf("marshal PostgreSQL Flex instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/postgresflex/instance/describe/describe_test.go b/internal/cmd/postgresflex/instance/describe/describe_test.go index a1b50bb49..bcff29fa6 100644 --- a/internal/cmd/postgresflex/instance/describe/describe_test.go +++ b/internal/cmd/postgresflex/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/instance/instance.go b/internal/cmd/postgresflex/instance/instance.go index 0d16db1f8..4a005c13a 100644 --- a/internal/cmd/postgresflex/instance/instance.go +++ b/internal/cmd/postgresflex/instance/instance.go @@ -8,12 +8,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for PostgreSQL Flex instances", @@ -21,15 +22,15 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(update.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(clone.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(clone.NewCmd(p)) } diff --git a/internal/cmd/postgresflex/instance/list/list.go b/internal/cmd/postgresflex/instance/list/list.go index 98ce881f4..a9f6b5e25 100644 --- a/internal/cmd/postgresflex/instance/list/list.go +++ b/internal/cmd/postgresflex/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all PostgreSQL Flex instances", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,11 +67,11 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get PostgreSQL Flex instances: %w", err) } if resp.Items == nil || len(*resp.Items) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } instances := *resp.Items @@ -80,7 +81,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -117,14 +118,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []postgresflex.InstanceListInstance) error { +func outputResult(p *print.Printer, outputFormat string, instances []postgresflex.InstanceListInstance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal PostgreSQL Flex instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -135,7 +136,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []postgresf instance := instances[i] table.AddRow(*instance.Id, *instance.Name, caser.String(*instance.Status)) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/postgresflex/instance/list/list_test.go b/internal/cmd/postgresflex/instance/list/list_test.go index fca5029bd..c8aede301 100644 --- a/internal/cmd/postgresflex/instance/list/list_test.go +++ b/internal/cmd/postgresflex/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/postgresflex/instance/update/update.go b/internal/cmd/postgresflex/instance/update/update.go index 0a860ad71..5a61ff14e 100644 --- a/internal/cmd/postgresflex/instance/update/update.go +++ b/internal/cmd/postgresflex/instance/update/update.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -52,7 +52,7 @@ type inputModel struct { Type *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a PostgreSQL Flex instance", @@ -75,7 +75,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q? (This may cause downtime)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -106,7 +106,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -119,7 +119,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/postgresflex/instance/update/update_test.go b/internal/cmd/postgresflex/instance/update/update_test.go index 190823939..16f6d3769 100644 --- a/internal/cmd/postgresflex/instance/update/update_test.go +++ b/internal/cmd/postgresflex/instance/update/update_test.go @@ -101,6 +101,7 @@ func fixtureRequiredInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -114,6 +115,7 @@ func fixtureStandardInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, FlavorId: utils.Ptr(testFlavorId), @@ -276,7 +278,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/options/options.go b/internal/cmd/postgresflex/options/options.go index 327521e5c..998c18d87 100644 --- a/internal/cmd/postgresflex/options/options.go +++ b/internal/cmd/postgresflex/options/options.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/pager" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -44,7 +45,7 @@ type flavorStorages struct { Storages *postgresflex.ListStoragesResponse `json:"storages"` } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "options", Short: "Lists PostgreSQL Flex options", @@ -69,13 +70,13 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } // Call API - err = buildAndExecuteRequest(ctx, cmd, model, apiClient) + err = buildAndExecuteRequest(ctx, p, model, apiClient) if err != nil { return fmt.Errorf("get PostgreSQL Flex options: %w", err) } @@ -129,7 +130,7 @@ type postgresFlexOptionsClient interface { ListStoragesExecute(ctx context.Context, projectId, flavorId string) (*postgresflex.ListStoragesResponse, error) } -func buildAndExecuteRequest(ctx context.Context, cmd *cobra.Command, model *inputModel, apiClient postgresFlexOptionsClient) error { +func buildAndExecuteRequest(ctx context.Context, p *print.Printer, model *inputModel, apiClient postgresFlexOptionsClient) error { var flavors *postgresflex.ListFlavorsResponse var versions *postgresflex.ListVersionsResponse var storages *postgresflex.ListStoragesResponse @@ -154,10 +155,10 @@ func buildAndExecuteRequest(ctx context.Context, cmd *cobra.Command, model *inpu } } - return outputResult(cmd, model, flavors, versions, storages) + return outputResult(p, model, flavors, versions, storages) } -func outputResult(cmd *cobra.Command, model *inputModel, flavors *postgresflex.ListFlavorsResponse, versions *postgresflex.ListVersionsResponse, storages *postgresflex.ListStoragesResponse) error { +func outputResult(p *print.Printer, model *inputModel, flavors *postgresflex.ListFlavorsResponse, versions *postgresflex.ListVersionsResponse, storages *postgresflex.ListStoragesResponse) error { options := &options{} if flavors != nil { options.Flavors = flavors.Flavors @@ -178,14 +179,14 @@ func outputResult(cmd *cobra.Command, model *inputModel, flavors *postgresflex.L if err != nil { return fmt.Errorf("marshal PostgreSQL Flex options: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: - return outputResultAsTable(cmd, model, options) + return outputResultAsTable(p, model, options) } } -func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *options) error { +func outputResultAsTable(p *print.Printer, model *inputModel, options *options) error { content := "" if model.Flavors { content += renderFlavors(*options.Flavors) @@ -197,7 +198,7 @@ func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *options content += renderStorages(options.Storages.Storages) } - err := pager.Display(cmd, content) + err := pager.Display(p, content) if err != nil { return fmt.Errorf("display output: %w", err) } diff --git a/internal/cmd/postgresflex/options/options_test.go b/internal/cmd/postgresflex/options/options_test.go index acb6c2a88..c9905cd20 100644 --- a/internal/cmd/postgresflex/options/options_test.go +++ b/internal/cmd/postgresflex/options/options_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/google/go-cmp/cmp" @@ -75,7 +76,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, Flavors: false, Versions: false, Storages: false, @@ -88,7 +89,7 @@ func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { func fixtureInputModelAllTrue(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, Flavors: true, Versions: true, Storages: true, @@ -165,7 +166,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -288,14 +289,16 @@ func TestBuildAndExecuteRequest(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + p := &print.Printer{} + cmd := NewCmd(p) + p.Cmd = cmd client := &postgresFlexClientMocked{ listFlavorsFails: tt.listFlavorsFails, listVersionsFails: tt.listVersionsFails, listStoragesFails: tt.listStoragesFails, } - err := buildAndExecuteRequest(testCtx, cmd, tt.model, client) + err := buildAndExecuteRequest(testCtx, p, tt.model, client) if err != nil && tt.isValid { t.Fatalf("error building and executing request: %v", err) } diff --git a/internal/cmd/postgresflex/postgresflex.go b/internal/cmd/postgresflex/postgresflex.go index 3f74e35c8..8dba63f4a 100644 --- a/internal/cmd/postgresflex/postgresflex.go +++ b/internal/cmd/postgresflex/postgresflex.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/options" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "postgresflex", Aliases: []string{"postgresqlflex"}, @@ -19,12 +20,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(user.NewCmd()) - cmd.AddCommand(options.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(user.NewCmd(p)) + cmd.AddCommand(options.NewCmd(p)) } diff --git a/internal/cmd/postgresflex/user/create/create.go b/internal/cmd/postgresflex/user/create/create.go index 07cbf6d8a..a0758c12b 100644 --- a/internal/cmd/postgresflex/user/create/create.go +++ b/internal/cmd/postgresflex/user/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" @@ -35,7 +35,7 @@ type inputModel struct { Roles *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a PostgreSQL Flex user", @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a user for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -88,13 +88,13 @@ func NewCmd() *cobra.Command { } user := resp.Item - cmd.Printf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) - cmd.Printf("Username: %s\n", *user.Username) - cmd.Printf("Password: %s\n", *user.Password) - cmd.Printf("Roles: %v\n", *user.Roles) - cmd.Printf("Host: %s\n", *user.Host) - cmd.Printf("Port: %d\n", *user.Port) - cmd.Printf("URI: %s\n", *user.Uri) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *user.Id) + p.Outputf("Username: %s\n", *user.Username) + p.Outputf("Password: %s\n", *user.Password) + p.Outputf("Roles: %v\n", *user.Roles) + p.Outputf("Host: %s\n", *user.Host) + p.Outputf("Port: %d\n", *user.Port) + p.Outputf("URI: %s\n", *user.Uri) return nil }, diff --git a/internal/cmd/postgresflex/user/create/create_test.go b/internal/cmd/postgresflex/user/create/create_test.go index 106dff903..f12b20b89 100644 --- a/internal/cmd/postgresflex/user/create/create_test.go +++ b/internal/cmd/postgresflex/user/create/create_test.go @@ -40,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Username: utils.Ptr("johndoe"), diff --git a/internal/cmd/postgresflex/user/delete/delete.go b/internal/cmd/postgresflex/user/delete/delete.go index 430747215..c4bb11f24 100644 --- a/internal/cmd/postgresflex/user/delete/delete.go +++ b/internal/cmd/postgresflex/user/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" @@ -30,7 +30,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", userIdArg), Short: "Deletes a PostgreSQL Flex user", @@ -53,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete user %q of instance %q? (This cannot be undone)", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,7 +83,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete PostgreSQL Flex user: %w", err) } - cmd.Printf("Deleted user %q of instance %q\n", userLabel, instanceLabel) + p.Info("Deleted user %q of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/postgresflex/user/delete/delete_test.go b/internal/cmd/postgresflex/user/delete/delete_test.go index 47a1240ef..1a7bb7d94 100644 --- a/internal/cmd/postgresflex/user/delete/delete_test.go +++ b/internal/cmd/postgresflex/user/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -156,7 +157,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/user/describe/describe.go b/internal/cmd/postgresflex/user/describe/describe.go index a24e432db..acfa5d5d2 100644 --- a/internal/cmd/postgresflex/user/describe/describe.go +++ b/internal/cmd/postgresflex/user/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", userIdArg), Short: "Shows details of a PostgreSQL Flex user", @@ -56,7 +57,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -68,7 +69,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get MongoDB Flex user: %w", err) } - return outputResult(cmd, model.OutputFormat, *resp.Item) + return outputResult(p, model.OutputFormat, *resp.Item) }, } @@ -103,7 +104,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle return req } -func outputResult(cmd *cobra.Command, outputFormat string, user postgresflex.UserResponse) error { +func outputResult(p *print.Printer, outputFormat string, user postgresflex.UserResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -117,7 +118,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user postgresflex.Use table.AddSeparator() table.AddRow("PORT", *user.Port) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -128,7 +129,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user postgresflex.Use if err != nil { return fmt.Errorf("marshal MongoDB Flex user: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/postgresflex/user/describe/describe_test.go b/internal/cmd/postgresflex/user/describe/describe_test.go index 1826289dd..4bc121ee7 100644 --- a/internal/cmd/postgresflex/user/describe/describe_test.go +++ b/internal/cmd/postgresflex/user/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -156,7 +157,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/user/list/list.go b/internal/cmd/postgresflex/user/list/list.go index cb0ecff20..785fc473a 100644 --- a/internal/cmd/postgresflex/user/list/list.go +++ b/internal/cmd/postgresflex/user/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all PostgreSQL Flex users of an instance", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = *model.InstanceId } - cmd.Printf("No users found for instance %q\n", instanceLabel) + p.Info("No users found for instance %q\n", instanceLabel) return nil } users := *resp.Items @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { users = users[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, users) + return outputResult(p, model.OutputFormat, users) }, } @@ -123,14 +124,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *postgresfle return req } -func outputResult(cmd *cobra.Command, outputFormat string, users []postgresflex.ListUsersResponseItem) error { +func outputResult(p *print.Printer, outputFormat string, users []postgresflex.ListUsersResponseItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(users, "", " ") if err != nil { return fmt.Errorf("marshal PostgreSQL Flex user list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -140,7 +141,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, users []postgresflex. user := users[i] table.AddRow(*user.Id, *user.Username) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/postgresflex/user/list/list_test.go b/internal/cmd/postgresflex/user/list/list_test.go index 38e70b921..58f5c7434 100644 --- a/internal/cmd/postgresflex/user/list/list_test.go +++ b/internal/cmd/postgresflex/user/list/list_test.go @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: utils.Ptr(testInstanceId), Limit: utils.Ptr(int64(10)), diff --git a/internal/cmd/postgresflex/user/reset-password/reset_password.go b/internal/cmd/postgresflex/user/reset-password/reset_password.go index b8754e56c..ba0ab2b26 100644 --- a/internal/cmd/postgresflex/user/reset-password/reset_password.go +++ b/internal/cmd/postgresflex/user/reset-password/reset_password.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" @@ -30,7 +30,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("reset-password %s", userIdArg), Short: "Resets the password of a PostgreSQL Flex user", @@ -52,7 +52,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -69,7 +69,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to reset the password of user %q of instance %q? (This cannot be undone)", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -82,10 +82,10 @@ func NewCmd() *cobra.Command { return fmt.Errorf("reset PostgreSQL Flex user password: %w", err) } - cmd.Printf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) - cmd.Printf("Username: %s\n", *user.Item.Username) - cmd.Printf("New password: %s\n", *user.Item.Password) - cmd.Printf("New URI: %s\n", *user.Item.Uri) + p.Outputf("Reset password for user %q of instance %q\n\n", userLabel, instanceLabel) + p.Outputf("Username: %s\n", *user.Item.Username) + p.Outputf("New password: %s\n", *user.Item.Password) + p.Outputf("New URI: %s\n", *user.Item.Uri) return nil }, } diff --git a/internal/cmd/postgresflex/user/reset-password/reset_password_test.go b/internal/cmd/postgresflex/user/reset-password/reset_password_test.go index 0898d2b7b..b312e5867 100644 --- a/internal/cmd/postgresflex/user/reset-password/reset_password_test.go +++ b/internal/cmd/postgresflex/user/reset-password/reset_password_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -156,7 +157,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/user/update/update.go b/internal/cmd/postgresflex/user/update/update.go index 560531627..0b39a8eef 100644 --- a/internal/cmd/postgresflex/user/update/update.go +++ b/internal/cmd/postgresflex/user/update/update.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/client" postgresflexUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/postgresflex/utils" @@ -32,7 +32,7 @@ type inputModel struct { Roles *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", userIdArg), Short: "Updates a PostgreSQL Flex user", @@ -51,7 +51,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update user %q of instance %q?", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -81,7 +81,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("update PostgreSQL Flex user: %w", err) } - cmd.Printf("Updated user %q of instance %q\n", userLabel, instanceLabel) + p.Info("Updated user %q of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/postgresflex/user/update/update_test.go b/internal/cmd/postgresflex/user/update/update_test.go index e73ddff46..7f5f50092 100644 --- a/internal/cmd/postgresflex/user/update/update_test.go +++ b/internal/cmd/postgresflex/user/update/update_test.go @@ -49,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -165,7 +166,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/postgresflex/user/user.go b/internal/cmd/postgresflex/user/user.go index df90fac71..018244197 100644 --- a/internal/cmd/postgresflex/user/user.go +++ b/internal/cmd/postgresflex/user/user.go @@ -8,12 +8,13 @@ import ( resetpassword "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/reset-password" "github.com/stackitcloud/stackit-cli/internal/cmd/postgresflex/user/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "user", Short: "Provides functionality for PostgreSQL Flex users", @@ -21,15 +22,15 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(update.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(resetpassword.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(resetpassword.NewCmd(p)) } diff --git a/internal/cmd/project/create/create.go b/internal/cmd/project/create/create.go index 47e17f009..e1fbc397b 100644 --- a/internal/cmd/project/create/create.go +++ b/internal/cmd/project/create/create.go @@ -7,11 +7,11 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/auth" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -36,7 +36,7 @@ type inputModel struct { Labels *map[string]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a STACKIT project", @@ -58,14 +58,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a project under the parent with ID %q?", *model.ParentId) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -81,7 +81,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create project: %w", err) } - cmd.Printf("Created project under the parent with ID %q. Project ID: %s\n", *model.ParentId, *resp.ProjectId) + p.Outputf("Created project under the parent with ID %q. Project ID: %s\n", *model.ParentId, *resp.ProjectId) return nil }, } diff --git a/internal/cmd/project/create/create_test.go b/internal/cmd/project/create/create_test.go index 3da6087e5..b7e051328 100644 --- a/internal/cmd/project/create/create_test.go +++ b/internal/cmd/project/create/create_test.go @@ -36,7 +36,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, ParentId: utils.Ptr(testParentId), Name: utils.Ptr(nameFlag), Labels: utils.Ptr(map[string]string{ @@ -139,7 +139,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/project/delete/delete.go b/internal/cmd/project/delete/delete.go index f939a52d1..1709736f3 100644 --- a/internal/cmd/project/delete/delete.go +++ b/internal/cmd/project/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" @@ -20,7 +20,7 @@ type inputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "delete", Short: "Deletes a STACKIT project", @@ -42,19 +42,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete the project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -67,9 +67,11 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete project: %w", err) } - cmd.Printf("Deleted project %q\n", projectLabel) - cmd.Printf("If this was your default project, consider configuring a new project ID by running:\n") - cmd.Printf(" $ stackit config set --project-id \n") + p.Info("Deleted project %q\n", projectLabel) + p.Warn(fmt.Sprintf("%s\n%s\n", + "If this was your default project, consider configuring a new project ID by running:", + " $ stackit config set --project-id ", + )) return nil }, } diff --git a/internal/cmd/project/delete/delete_test.go b/internal/cmd/project/delete/delete_test.go index 122b5b930..2bb0b63c6 100644 --- a/internal/cmd/project/delete/delete_test.go +++ b/internal/cmd/project/delete/delete_test.go @@ -34,6 +34,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/project/describe/describe.go b/internal/cmd/project/describe/describe.go index 4d692b8c0..9208fe081 100644 --- a/internal/cmd/project/describe/describe.go +++ b/internal/cmd/project/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -29,7 +30,7 @@ type inputModel struct { IncludeParents bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "describe", Short: "Shows details of a STACKIT project", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +67,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read project details: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -105,7 +106,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *resourceman return req } -func outputResult(cmd *cobra.Command, outputFormat string, project *resourcemanager.ProjectResponseWithParents) error { +func outputResult(p *print.Printer, outputFormat string, project *resourcemanager.ProjectResponseWithParents) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -118,7 +119,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, project *resourcemana table.AddRow("STATE", *project.LifecycleState) table.AddSeparator() table.AddRow("PARENT ID", *project.Parent.Id) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -129,7 +130,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, project *resourcemana if err != nil { return fmt.Errorf("marshal project details: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/project/describe/describe_test.go b/internal/cmd/project/describe/describe_test.go index c2d7537cd..cd60acf0a 100644 --- a/internal/cmd/project/describe/describe_test.go +++ b/internal/cmd/project/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: "", + Verbosity: globalflags.VerbosityDefault, }, IncludeParents: false, ArgProjectId: testProjectId, @@ -133,7 +134,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/project/list/list.go b/internal/cmd/project/list/list.go index 0809e8928..1dd26e492 100644 --- a/internal/cmd/project/list/list.go +++ b/internal/cmd/project/list/list.go @@ -12,6 +12,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -41,7 +42,7 @@ type inputModel struct { PageSize int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists STACKIT projects", @@ -69,7 +70,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -80,11 +81,11 @@ func NewCmd() *cobra.Command { return err } if len(projects) == 0 { - cmd.Print("No projects found matching the criteria\n") + p.Info("No projects found matching the criteria\n") return nil } - return outputResult(cmd, model.OutputFormat, projects) + return outputResult(p, model.OutputFormat, projects) }, } configureFlags(cmd) @@ -206,14 +207,14 @@ func fetchProjects(ctx context.Context, model *inputModel, apiClient resourceMan return projects, nil } -func outputResult(cmd *cobra.Command, outputFormat string, projects []resourcemanager.ProjectResponse) error { +func outputResult(p *print.Printer, outputFormat string, projects []resourcemanager.ProjectResponse) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(projects, "", " ") if err != nil { return fmt.Errorf("marshal projects list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -224,7 +225,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, projects []resourcema table.AddRow(*p.ProjectId, *p.Name, *p.LifecycleState, *p.Parent.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/project/list/list_test.go b/internal/cmd/project/list/list_test.go index 1a4ca5755..b89adca73 100644 --- a/internal/cmd/project/list/list_test.go +++ b/internal/cmd/project/list/list_test.go @@ -48,7 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { } model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, ParentId: utils.Ptr(testParentId), Member: utils.Ptr("member"), CreationTimeAfter: utils.Ptr(testCreationTimeAfter), @@ -193,7 +193,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/project/member/add/add.go b/internal/cmd/project/member/add/add.go index 5618daaf3..f0bc1ec05 100644 --- a/internal/cmd/project/member/add/add.go +++ b/internal/cmd/project/member/add/add.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -33,7 +33,7 @@ type inputModel struct { Role *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("add %s", subjectArg), Short: "Adds a member to a project", @@ -58,19 +58,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to add the role %q to %s on project %q?", *model.Role, model.Subject, projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,7 +83,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("add member: %w", err) } - cmd.Printf("Added the role %q to %s on project %q\n", *model.Role, model.Subject, projectLabel) + p.Info("Added the role %q to %s on project %q\n", *model.Role, model.Subject, projectLabel) return nil }, } diff --git a/internal/cmd/project/member/add/add_test.go b/internal/cmd/project/member/add/add_test.go index 36d78653f..e59825633 100644 --- a/internal/cmd/project/member/add/add_test.go +++ b/internal/cmd/project/member/add/add_test.go @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Subject: testSubject, Role: utils.Ptr(testRole), @@ -121,7 +122,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/project/member/list/list.go b/internal/cmd/project/member/list/list.go index 5337048e4..be2f80471 100644 --- a/internal/cmd/project/member/list/list.go +++ b/internal/cmd/project/member/list/list.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -35,7 +36,7 @@ type inputModel struct { SortBy string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists members of a project", @@ -60,7 +61,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -73,11 +74,11 @@ func NewCmd() *cobra.Command { } members := *resp.Members if len(members) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No members found for project %q\n", projectLabel) + p.Info("No members found for project %q\n", projectLabel) return nil } @@ -86,7 +87,7 @@ func NewCmd() *cobra.Command { members = members[:*model.Limit] } - return outputResult(cmd, model, members) + return outputResult(p, model, members) }, } configureFlags(cmd) @@ -131,7 +132,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *authorizati return req } -func outputResult(cmd *cobra.Command, model *inputModel, members []authorization.Member) error { +func outputResult(p *print.Printer, model *inputModel, members []authorization.Member) error { sortFn := func(i, j int) bool { switch model.SortBy { case "subject": @@ -151,7 +152,7 @@ func outputResult(cmd *cobra.Command, model *inputModel, members []authorization if err != nil { return fmt.Errorf("marshal members: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -172,7 +173,7 @@ func outputResult(cmd *cobra.Command, model *inputModel, members []authorization table.EnableAutoMergeOnColumns(2) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/project/member/list/list_test.go b/internal/cmd/project/member/list/list_test.go index eaf78bec2..469ce2eb0 100644 --- a/internal/cmd/project/member/list/list_test.go +++ b/internal/cmd/project/member/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), SortBy: "subject", diff --git a/internal/cmd/project/member/member.go b/internal/cmd/project/member/member.go index 9791c3153..38340c1f2 100644 --- a/internal/cmd/project/member/member.go +++ b/internal/cmd/project/member/member.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/project/member/list" "github.com/stackitcloud/stackit-cli/internal/cmd/project/member/remove" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "member", Short: "Provides functionality regarding project members", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(add.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(remove.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(add.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(remove.NewCmd(p)) } diff --git a/internal/cmd/project/member/remove/remove.go b/internal/cmd/project/member/remove/remove.go index fc8d3498f..46d5015c2 100644 --- a/internal/cmd/project/member/remove/remove.go +++ b/internal/cmd/project/member/remove/remove.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -35,7 +35,7 @@ type inputModel struct { Force bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("remove %s", subjectArg), Short: "Removes a member from a project", @@ -61,12 +61,12 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { if model.Force { prompt = fmt.Sprintf("%s This will also remove other roles of the subject that would stop the removal of the requested role", prompt) } - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -89,7 +89,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("remove member: %w", err) } - cmd.Printf("Removed the role %q from %s on project %q\n", *model.Role, model.Subject, projectLabel) + p.Info("Removed the role %q from %s on project %q\n", *model.Role, model.Subject, projectLabel) return nil }, } diff --git a/internal/cmd/project/member/remove/remove_test.go b/internal/cmd/project/member/remove/remove_test.go index 76372e8af..c39df7e82 100644 --- a/internal/cmd/project/member/remove/remove_test.go +++ b/internal/cmd/project/member/remove/remove_test.go @@ -48,6 +48,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Subject: testSubject, Role: utils.Ptr(testRole), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/project/project.go b/internal/cmd/project/project.go index c3d486707..b4cf79228 100644 --- a/internal/cmd/project/project.go +++ b/internal/cmd/project/project.go @@ -11,12 +11,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/project/role" "github.com/stackitcloud/stackit-cli/internal/cmd/project/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "project", Short: "Provides functionality regarding projects", @@ -27,16 +28,16 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(update.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(member.NewCmd()) - cmd.AddCommand(role.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(member.NewCmd(p)) + cmd.AddCommand(role.NewCmd(p)) } diff --git a/internal/cmd/project/role/list/list.go b/internal/cmd/project/role/list/list.go index 3dbc651a6..5605f3ddb 100644 --- a/internal/cmd/project/role/list/list.go +++ b/internal/cmd/project/role/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/authorization/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists roles and permissions of a project", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -68,11 +69,11 @@ func NewCmd() *cobra.Command { } roles := *resp.Roles if len(roles) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No roles found for project %q\n", projectLabel) + p.Info("No roles found for project %q\n", projectLabel) return nil } @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { roles = roles[:*model.Limit] } - return outputRolesResult(cmd, model.OutputFormat, roles) + return outputRolesResult(p, model.OutputFormat, roles) }, } configureFlags(cmd) @@ -116,7 +117,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *authorizati return apiClient.ListRoles(ctx, projectResourceType, model.GlobalFlagModel.ProjectId) } -func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authorization.Role) error { +func outputRolesResult(p *print.Printer, outputFormat string, roles []authorization.Role) error { switch outputFormat { case globalflags.JSONOutputFormat: // Show details @@ -124,7 +125,7 @@ func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authoriz if err != nil { return fmt.Errorf("marshal roles: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -139,7 +140,7 @@ func outputRolesResult(cmd *cobra.Command, outputFormat string, roles []authoriz table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/project/role/list/list_test.go b/internal/cmd/project/role/list/list_test.go index 6246fbac9..80ee22574 100644 --- a/internal/cmd/project/role/list/list_test.go +++ b/internal/cmd/project/role/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/project/role/role.go b/internal/cmd/project/role/role.go index 90780c604..c32d3d224 100644 --- a/internal/cmd/project/role/role.go +++ b/internal/cmd/project/role/role.go @@ -3,12 +3,13 @@ package role import ( "github.com/stackitcloud/stackit-cli/internal/cmd/project/role/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "role", Short: "Provides functionality regarding project roles", @@ -16,10 +17,10 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/project/update/update.go b/internal/cmd/project/update/update.go index e28aae98b..fe553cf0a 100644 --- a/internal/cmd/project/update/update.go +++ b/internal/cmd/project/update/update.go @@ -6,11 +6,11 @@ import ( "regexp" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" @@ -35,7 +35,7 @@ type inputModel struct { Labels *map[string]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "update", Short: "Updates a STACKIT project", @@ -61,19 +61,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -86,7 +86,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("update project: %w", err) } - cmd.Printf("Updated project %q\n", projectLabel) + p.Info("Updated project %q\n", projectLabel) return nil }, } diff --git a/internal/cmd/project/update/update_test.go b/internal/cmd/project/update/update_test.go index 1cff1088d..7a7f0454e 100644 --- a/internal/cmd/project/update/update_test.go +++ b/internal/cmd/project/update/update_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ParentId: utils.Ptr(testParentId), Name: utils.Ptr(nameFlag), @@ -88,6 +89,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, }, }, @@ -127,7 +129,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -196,6 +198,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, }, expectedRequest: testClient.PartialUpdateProject(testCtx, testProjectId). diff --git a/internal/cmd/rabbitmq/credentials/create/create.go b/internal/cmd/rabbitmq/credentials/create/create.go index 71e1bf2b0..ee75a5aa3 100644 --- a/internal/cmd/rabbitmq/credentials/create/create.go +++ b/internal/cmd/rabbitmq/credentials/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" @@ -28,7 +28,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for a RabbitMQ instance", @@ -50,7 +50,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -75,20 +75,20 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create RabbitMQ credentials: %w", err) } - cmd.Printf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty username := *resp.Raw.Credentials.Username if username != "" { - cmd.Printf("Username: %s\n", *resp.Raw.Credentials.Username) + p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } if model.HidePassword { - cmd.Printf("Password: \n") + p.Outputf("Password: \n") } else { - cmd.Printf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) } - cmd.Printf("Host: %s\n", *resp.Raw.Credentials.Host) - cmd.Printf("Port: %d\n", *resp.Raw.Credentials.Port) - cmd.Printf("URI: %s\n", *resp.Uri) + p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) + p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) + p.Outputf("URI: %s\n", *resp.Uri) return nil }, } diff --git a/internal/cmd/rabbitmq/credentials/create/create_test.go b/internal/cmd/rabbitmq/credentials/create/create_test.go index 898311b52..c68535494 100644 --- a/internal/cmd/rabbitmq/credentials/create/create_test.go +++ b/internal/cmd/rabbitmq/credentials/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -117,7 +118,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/credentials/credentials.go b/internal/cmd/rabbitmq/credentials/credentials.go index e6fd55a7e..38ec2c552 100644 --- a/internal/cmd/rabbitmq/credentials/credentials.go +++ b/internal/cmd/rabbitmq/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/credentials/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for RabbitMQ credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/rabbitmq/credentials/delete/delete.go b/internal/cmd/rabbitmq/credentials/delete/delete.go index 6a466de9e..b469f92b0 100644 --- a/internal/cmd/rabbitmq/credentials/delete/delete.go +++ b/internal/cmd/rabbitmq/credentials/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of a RabbitMQ instance", @@ -49,7 +49,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %s of instance %q? (This cannot be undone)", credentialsLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -79,7 +79,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete RabbitMQ credentials: %w", err) } - cmd.Printf("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) + p.Info("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/rabbitmq/credentials/delete/delete_test.go b/internal/cmd/rabbitmq/credentials/delete/delete_test.go index c9b53315d..ecf10d176 100644 --- a/internal/cmd/rabbitmq/credentials/delete/delete_test.go +++ b/internal/cmd/rabbitmq/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/credentials/describe/describe.go b/internal/cmd/rabbitmq/credentials/describe/describe.go index 136c78de8..c70489746 100644 --- a/internal/cmd/rabbitmq/credentials/describe/describe.go +++ b/internal/cmd/rabbitmq/credentials/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", credentialsIdArg), Short: "Shows details of credentials of a RabbitMQ instance", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("describe RabbitMQ credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -98,7 +99,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *rabbitmq.CredentialsResponse) error { +func outputResult(p *print.Printer, outputFormat string, credentials *rabbitmq.CredentialsResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -113,7 +114,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *rabbitmq table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) table.AddSeparator() table.AddRow("URI", *credentials.Raw.Credentials.Uri) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *rabbitmq if err != nil { return fmt.Errorf("marshal RabbitMQ credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/rabbitmq/credentials/describe/describe_test.go b/internal/cmd/rabbitmq/credentials/describe/describe_test.go index b71162bb4..b3bc93579 100644 --- a/internal/cmd/rabbitmq/credentials/describe/describe_test.go +++ b/internal/cmd/rabbitmq/credentials/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/credentials/list/list.go b/internal/cmd/rabbitmq/credentials/list/list.go index 0c53dad36..047f0b1db 100644 --- a/internal/cmd/rabbitmq/credentials/list/list.go +++ b/internal/cmd/rabbitmq/credentials/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials' IDs for a RabbitMQ instance", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = model.InstanceId } - cmd.Printf("No credentials found for instance %q\n", instanceLabel) + p.Info("No credentials found for instance %q\n", instanceLabel) return nil } @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -120,14 +121,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []rabbitmq.CredentialsListItem) error { +func outputResult(p *print.Printer, outputFormat string, credentials []rabbitmq.CredentialsListItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal RabbitMQ credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []rabbitm c := credentials[i] table.AddRow(*c.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/rabbitmq/credentials/list/list_test.go b/internal/cmd/rabbitmq/credentials/list/list_test.go index e8d2f9b24..ba398c659 100644 --- a/internal/cmd/rabbitmq/credentials/list/list_test.go +++ b/internal/cmd/rabbitmq/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Limit: utils.Ptr(int64(10)), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/instance/create/create.go b/internal/cmd/rabbitmq/instance/create/create.go index 15dfc9605..6ed1cead5 100644 --- a/internal/cmd/rabbitmq/instance/create/create.go +++ b/internal/cmd/rabbitmq/instance/create/create.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" @@ -55,7 +55,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a RabbitMQ instance", @@ -80,19 +80,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create an RabbitMQ instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/rabbitmq/instance/create/create_test.go b/internal/cmd/rabbitmq/instance/create/create_test.go index cf475a8a2..535db19fd 100644 --- a/internal/cmd/rabbitmq/instance/create/create_test.go +++ b/internal/cmd/rabbitmq/instance/create/create_test.go @@ -65,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), EnableMonitoring: utils.Ptr(true), @@ -151,6 +152,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -171,6 +173,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -272,7 +275,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -437,6 +440,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), }, diff --git a/internal/cmd/rabbitmq/instance/delete/delete.go b/internal/cmd/rabbitmq/instance/delete/delete.go index 2fd61f832..64411ddb8 100644 --- a/internal/cmd/rabbitmq/instance/delete/delete.go +++ b/internal/cmd/rabbitmq/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a RabbitMQ instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/rabbitmq/instance/delete/delete_test.go b/internal/cmd/rabbitmq/instance/delete/delete_test.go index 5f4c7f79b..f9c2f565a 100644 --- a/internal/cmd/rabbitmq/instance/delete/delete_test.go +++ b/internal/cmd/rabbitmq/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/instance/describe/describe.go b/internal/cmd/rabbitmq/instance/describe/describe.go index 4f90b6946..3b4f0b200 100644 --- a/internal/cmd/rabbitmq/instance/describe/describe.go +++ b/internal/cmd/rabbitmq/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a RabbitMQ instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read RabbitMQ instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *rabbitmq.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *rabbitmq.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -108,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *rabbitmq.In table.AddRow("ACL", aclStr) } } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -119,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *rabbitmq.In if err != nil { return fmt.Errorf("marshal RabbitMQ instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/rabbitmq/instance/describe/describe_test.go b/internal/cmd/rabbitmq/instance/describe/describe_test.go index 82625bf0d..616b7731a 100644 --- a/internal/cmd/rabbitmq/instance/describe/describe_test.go +++ b/internal/cmd/rabbitmq/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/rabbitmq/instance/instance.go b/internal/cmd/rabbitmq/instance/instance.go index 9e58a61e5..b9a73a3e0 100644 --- a/internal/cmd/rabbitmq/instance/instance.go +++ b/internal/cmd/rabbitmq/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for RabbitMQ instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/rabbitmq/instance/list/list.go b/internal/cmd/rabbitmq/instance/list/list.go index 576801ba2..3258a5444 100644 --- a/internal/cmd/rabbitmq/instance/list/list.go +++ b/internal/cmd/rabbitmq/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all RabbitMQ instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []rabbitmq.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []rabbitmq.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal RabbitMQ instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []rabbitmq. instance := instances[i] table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/rabbitmq/instance/list/list_test.go b/internal/cmd/rabbitmq/instance/list/list_test.go index 80556d791..e940eb894 100644 --- a/internal/cmd/rabbitmq/instance/list/list_test.go +++ b/internal/cmd/rabbitmq/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/rabbitmq/instance/update/update.go b/internal/cmd/rabbitmq/instance/update/update.go index 345d04a34..da36b8663 100644 --- a/internal/cmd/rabbitmq/instance/update/update.go +++ b/internal/cmd/rabbitmq/instance/update/update.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" rabbitmqUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -56,7 +56,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a RabbitMQ instance", @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -113,7 +113,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -126,7 +126,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/rabbitmq/instance/update/update_test.go b/internal/cmd/rabbitmq/instance/update/update_test.go index fe62bbd43..aa169639d 100644 --- a/internal/cmd/rabbitmq/instance/update/update_test.go +++ b/internal/cmd/rabbitmq/instance/update/update_test.go @@ -77,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, EnableMonitoring: utils.Ptr(true), @@ -162,6 +163,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, @@ -181,6 +183,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testPlanId), @@ -289,7 +292,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -462,6 +465,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, diff --git a/internal/cmd/rabbitmq/plans/plans.go b/internal/cmd/rabbitmq/plans/plans.go index fc26d00f0..610533e8b 100644 --- a/internal/cmd/rabbitmq/plans/plans.go +++ b/internal/cmd/rabbitmq/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/rabbitmq/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all RabbitMQ service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Offerings if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *rabbitmq.AP return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []rabbitmq.Offering) error { +func outputResult(p *print.Printer, outputFormat string, plans []rabbitmq.Offering) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal RabbitMQ plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -131,13 +132,13 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []rabbitmq.Offe for i := range plans { o := plans[i] for j := range *o.Plans { - p := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *p.Id, *p.Name, *p.Description) + plan := (*o.Plans)[j] + table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) } table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/rabbitmq/plans/plans_test.go b/internal/cmd/rabbitmq/plans/plans_test.go index 9829fe35d..87319bf6d 100644 --- a/internal/cmd/rabbitmq/plans/plans_test.go +++ b/internal/cmd/rabbitmq/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/rabbitmq/rabbitmq.go b/internal/cmd/rabbitmq/rabbitmq.go index 916e9cc9f..26b5db9bb 100644 --- a/internal/cmd/rabbitmq/rabbitmq.go +++ b/internal/cmd/rabbitmq/rabbitmq.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/rabbitmq/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "rabbitmq", Short: "Provides functionality for RabbitMQ", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/redis/credentials/create/create.go b/internal/cmd/redis/credentials/create/create.go index 8dbf3731a..273d1a7c1 100644 --- a/internal/cmd/redis/credentials/create/create.go +++ b/internal/cmd/redis/credentials/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" @@ -28,7 +28,7 @@ type inputModel struct { HidePassword bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates credentials for a Redis instance", @@ -50,7 +50,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create credentials for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -75,20 +75,20 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create Redis credentials: %w", err) } - cmd.Printf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Created credentials for instance %q. Credentials ID: %s\n\n", instanceLabel, *resp.Id) // The username field cannot be set by the user so we only display it if it's not returned empty username := *resp.Raw.Credentials.Username if username != "" { - cmd.Printf("Username: %s\n", *resp.Raw.Credentials.Username) + p.Outputf("Username: %s\n", *resp.Raw.Credentials.Username) } if model.HidePassword { - cmd.Printf("Password: \n") + p.Outputf("Password: \n") } else { - cmd.Printf("Password: %s\n", *resp.Raw.Credentials.Password) + p.Outputf("Password: %s\n", *resp.Raw.Credentials.Password) } - cmd.Printf("Host: %s\n", *resp.Raw.Credentials.Host) - cmd.Printf("Port: %d\n", *resp.Raw.Credentials.Port) - cmd.Printf("URI: %s\n", *resp.Uri) + p.Outputf("Host: %s\n", *resp.Raw.Credentials.Host) + p.Outputf("Port: %d\n", *resp.Raw.Credentials.Port) + p.Outputf("URI: %s\n", *resp.Uri) return nil }, } diff --git a/internal/cmd/redis/credentials/create/create_test.go b/internal/cmd/redis/credentials/create/create_test.go index aea102622..5f1a247f1 100644 --- a/internal/cmd/redis/credentials/create/create_test.go +++ b/internal/cmd/redis/credentials/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -117,7 +118,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/credentials/credentials.go b/internal/cmd/redis/credentials/credentials.go index 36eac3341..42e6226da 100644 --- a/internal/cmd/redis/credentials/credentials.go +++ b/internal/cmd/redis/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/redis/credentials/describe" "github.com/stackitcloud/stackit-cli/internal/cmd/redis/credentials/list" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for Redis credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) } diff --git a/internal/cmd/redis/credentials/delete/delete.go b/internal/cmd/redis/credentials/delete/delete.go index 78067568c..875d73243 100644 --- a/internal/cmd/redis/credentials/delete/delete.go +++ b/internal/cmd/redis/credentials/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", credentialsIdArg), Short: "Deletes credentials of a Redis instance", @@ -49,7 +49,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete credentials %s of instance %q? (This cannot be undone)", credentialsLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -79,7 +79,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete Redis credentials: %w", err) } - cmd.Printf("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) + p.Info("Deleted credentials %s of instance %q\n", credentialsLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/redis/credentials/delete/delete_test.go b/internal/cmd/redis/credentials/delete/delete_test.go index 42a6730bf..575dac9f0 100644 --- a/internal/cmd/redis/credentials/delete/delete_test.go +++ b/internal/cmd/redis/credentials/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/credentials/describe/describe.go b/internal/cmd/redis/credentials/describe/describe.go index 676c2ce5b..848813908 100644 --- a/internal/cmd/redis/credentials/describe/describe.go +++ b/internal/cmd/redis/credentials/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { CredentialsId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", credentialsIdArg), Short: "Shows details of credentials of a Redis instance", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -64,7 +65,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("describe Redis credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } configureFlags(cmd) @@ -98,7 +99,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *redis.CredentialsResponse) error { +func outputResult(p *print.Printer, outputFormat string, credentials *redis.CredentialsResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -113,7 +114,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *redis.Cr table.AddRow("PASSWORD", *credentials.Raw.Credentials.Password) table.AddSeparator() table.AddRow("URI", *credentials.Raw.Credentials.Uri) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *redis.Cr if err != nil { return fmt.Errorf("marshal Redis credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/redis/credentials/describe/describe_test.go b/internal/cmd/redis/credentials/describe/describe_test.go index d53abcd65..45f2fa6f5 100644 --- a/internal/cmd/redis/credentials/describe/describe_test.go +++ b/internal/cmd/redis/credentials/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, CredentialsId: testCredentialsId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/credentials/list/list.go b/internal/cmd/redis/credentials/list/list.go index 1919fda99..d3972638e 100644 --- a/internal/cmd/redis/credentials/list/list.go +++ b/internal/cmd/redis/credentials/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all credentials' IDs for a Redis instance", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = model.InstanceId } - cmd.Printf("No credentials found for instance %q\n", instanceLabel) + p.Info("No credentials found for instance %q\n", instanceLabel) return nil } @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Limit != nil && len(credentials) > int(*model.Limit) { credentials = credentials[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, credentials) + return outputResult(p, model.OutputFormat, credentials) }, } configureFlags(cmd) @@ -120,14 +121,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials []redis.CredentialsListItem) error { +func outputResult(p *print.Printer, outputFormat string, credentials []redis.CredentialsListItem) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(credentials, "", " ") if err != nil { return fmt.Errorf("marshal Redis credentials list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -137,7 +138,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials []redis.C c := credentials[i] table.AddRow(*c.Id) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/redis/credentials/list/list_test.go b/internal/cmd/redis/credentials/list/list_test.go index 5371e72fd..749a288d3 100644 --- a/internal/cmd/redis/credentials/list/list_test.go +++ b/internal/cmd/redis/credentials/list/list_test.go @@ -38,6 +38,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Limit: utils.Ptr(int64(10)), @@ -134,7 +135,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/instance/create/create.go b/internal/cmd/redis/instance/create/create.go index 621704854..2308eada5 100644 --- a/internal/cmd/redis/instance/create/create.go +++ b/internal/cmd/redis/instance/create/create.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" @@ -55,7 +55,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a Redis instance", @@ -80,19 +80,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a Redis instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -115,7 +115,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating instance") _, err = wait.CreateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -128,7 +128,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) + p.Outputf("%s instance for project %q. Instance ID: %s\n", operationState, projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/redis/instance/create/create_test.go b/internal/cmd/redis/instance/create/create_test.go index ed9e8bf55..5529a3627 100644 --- a/internal/cmd/redis/instance/create/create_test.go +++ b/internal/cmd/redis/instance/create/create_test.go @@ -65,6 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), EnableMonitoring: utils.Ptr(true), @@ -151,6 +152,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example-name"), PlanId: utils.Ptr(testPlanId), @@ -171,6 +173,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), InstanceName: utils.Ptr(""), @@ -272,7 +275,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -437,6 +440,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, PlanId: utils.Ptr(testPlanId), }, diff --git a/internal/cmd/redis/instance/delete/delete.go b/internal/cmd/redis/instance/delete/delete.go index a677aa4f3..9f424d480 100644 --- a/internal/cmd/redis/instance/delete/delete.go +++ b/internal/cmd/redis/instance/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -28,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a Redis instance", @@ -47,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,7 +59,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting instance") _, err = wait.DeleteInstanceWaitHandler(ctx, apiClient, model.ProjectId, model.InstanceId).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/redis/instance/delete/delete_test.go b/internal/cmd/redis/instance/delete/delete_test.go index 41a664543..e1e637428 100644 --- a/internal/cmd/redis/instance/delete/delete_test.go +++ b/internal/cmd/redis/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/instance/describe/describe.go b/internal/cmd/redis/instance/describe/describe.go index b7207c54b..29631c017 100644 --- a/internal/cmd/redis/instance/describe/describe.go +++ b/internal/cmd/redis/instance/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -28,7 +29,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a Redis instance", @@ -49,7 +50,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -61,7 +62,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read Redis instance: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -86,7 +87,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *redis.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instance *redis.Instance) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -108,7 +109,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *redis.Insta table.AddRow("ACL", aclStr) } } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -119,7 +120,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *redis.Insta if err != nil { return fmt.Errorf("marshal Redis instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/redis/instance/describe/describe_test.go b/internal/cmd/redis/instance/describe/describe_test.go index b8a4af50f..d19561e30 100644 --- a/internal/cmd/redis/instance/describe/describe_test.go +++ b/internal/cmd/redis/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/redis/instance/instance.go b/internal/cmd/redis/instance/instance.go index 920351de2..3518921b5 100644 --- a/internal/cmd/redis/instance/instance.go +++ b/internal/cmd/redis/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/redis/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/redis/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for Redis instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/redis/instance/list/list.go b/internal/cmd/redis/instance/list/list.go index 3a393c95e..eac41d481 100644 --- a/internal/cmd/redis/instance/list/list.go +++ b/internal/cmd/redis/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all Redis instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } instances := *resp.Instances if len(instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []redis.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []redis.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal Redis instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -132,7 +133,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []redis.Ins instance := instances[i] table.AddRow(*instance.InstanceId, *instance.Name, *instance.LastOperation.Type, *instance.LastOperation.State) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/redis/instance/list/list_test.go b/internal/cmd/redis/instance/list/list_test.go index 7788ac864..9a8ffc30b 100644 --- a/internal/cmd/redis/instance/list/list_test.go +++ b/internal/cmd/redis/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/redis/instance/update/update.go b/internal/cmd/redis/instance/update/update.go index 7fe63ca8f..af09b4ea1 100644 --- a/internal/cmd/redis/instance/update/update.go +++ b/internal/cmd/redis/instance/update/update.go @@ -7,11 +7,11 @@ import ( "strings" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" redisUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -56,7 +56,7 @@ type inputModel struct { PlanId *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a Redis instance", @@ -78,7 +78,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -113,7 +113,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating instance") _, err = wait.PartialUpdateInstanceWaitHandler(ctx, apiClient, model.ProjectId, instanceId).WaitWithContext(ctx) if err != nil { @@ -126,7 +126,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s instance %q\n", operationState, instanceLabel) + p.Info("%s instance %q\n", operationState, instanceLabel) return nil }, } diff --git a/internal/cmd/redis/instance/update/update_test.go b/internal/cmd/redis/instance/update/update_test.go index 73c49e3f1..1f913d7b3 100644 --- a/internal/cmd/redis/instance/update/update_test.go +++ b/internal/cmd/redis/instance/update/update_test.go @@ -77,6 +77,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, EnableMonitoring: utils.Ptr(true), @@ -162,6 +163,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, @@ -181,6 +183,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, PlanId: utils.Ptr(testPlanId), @@ -289,7 +292,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) @@ -462,6 +465,7 @@ func TestBuildRequest(t *testing.T) { model: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, }, diff --git a/internal/cmd/redis/plans/plans.go b/internal/cmd/redis/plans/plans.go index 4aadf5fdd..18c043710 100644 --- a/internal/cmd/redis/plans/plans.go +++ b/internal/cmd/redis/plans/plans.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/redis/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "plans", Short: "Lists all Redis service plans", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } plans := *resp.Offerings if len(plans) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No plans found for project %q\n", projectLabel) + p.Info("No plans found for project %q\n", projectLabel) return nil } @@ -78,7 +79,7 @@ func NewCmd() *cobra.Command { plans = plans[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, plans) + return outputResult(p, model.OutputFormat, plans) }, } @@ -115,14 +116,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *redis.APICl return req } -func outputResult(cmd *cobra.Command, outputFormat string, plans []redis.Offering) error { +func outputResult(p *print.Printer, outputFormat string, plans []redis.Offering) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(plans, "", " ") if err != nil { return fmt.Errorf("marshal Redis plans: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -131,13 +132,13 @@ func outputResult(cmd *cobra.Command, outputFormat string, plans []redis.Offerin for i := range plans { o := plans[i] for j := range *o.Plans { - p := (*o.Plans)[j] - table.AddRow(*o.Name, *o.Version, *p.Id, *p.Name, *p.Description) + plan := (*o.Plans)[j] + table.AddRow(*o.Name, *o.Version, *plan.Id, *plan.Name, *plan.Description) } table.AddSeparator() } table.EnableAutoMergeOnColumns(1, 2) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/redis/plans/plans_test.go b/internal/cmd/redis/plans/plans_test.go index ff0098767..43b6f9577 100644 --- a/internal/cmd/redis/plans/plans_test.go +++ b/internal/cmd/redis/plans/plans_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/redis/redis.go b/internal/cmd/redis/redis.go index 25e306217..3b07f00c9 100644 --- a/internal/cmd/redis/redis.go +++ b/internal/cmd/redis/redis.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/redis/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/redis/plans" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "redis", Short: "Provides functionality for Redis", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(plans.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(plans.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) } diff --git a/internal/cmd/root.go b/internal/cmd/root.go index 726bbd180..e8751569a 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -28,11 +28,12 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" ) -func NewRootCmd(version, date string) *cobra.Command { +func NewRootCmd(version, date string, p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "stackit", Short: "Manage STACKIT resources using the command line", @@ -41,16 +42,20 @@ func NewRootCmd(version, date string) *cobra.Command { SilenceErrors: true, // Error is beautified in a custom way before being printed SilenceUsage: true, DisableAutoGenTag: true, + PersistentPreRun: func(cmd *cobra.Command, args []string) { + p.Cmd = cmd + p.Verbosity = print.Level(globalflags.Parse(cmd).Verbosity) + }, RunE: func(cmd *cobra.Command, args []string) error { if flags.FlagToBoolValue(cmd, "version") { - cmd.Printf("STACKIT CLI (BETA)\n") + p.Outputf("STACKIT CLI (BETA)\n") parsedDate, err := time.Parse(time.RFC3339, date) if err != nil { - cmd.Printf("Version: %s\n", version) + p.Outputf("Version: %s\n", version) return nil } - cmd.Printf("Version: %s (%s)\n", version, parsedDate.Format(time.DateOnly)) + p.Outputf("Version: %s (%s)\n", version, parsedDate.Format(time.DateOnly)) return nil } @@ -62,7 +67,7 @@ func NewRootCmd(version, date string) *cobra.Command { err := configureFlags(cmd) cobra.CheckErr(err) - addSubcommands(cmd) + addSubcommands(cmd, p) // Cobra creates the help flag with "help for " as the description // We want to override that message by capitalizing the first letter to match the other flag descriptions @@ -84,25 +89,38 @@ func configureFlags(cmd *cobra.Command) error { return nil } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(argus.NewCmd()) - cmd.AddCommand(auth.NewCmd()) - cmd.AddCommand(config.NewCmd()) - cmd.AddCommand(curl.NewCmd()) - cmd.AddCommand(dns.NewCmd()) - cmd.AddCommand(logme.NewCmd()) - cmd.AddCommand(mariadb.NewCmd()) - cmd.AddCommand(mongodbflex.NewCmd()) - cmd.AddCommand(objectstorage.NewCmd()) - cmd.AddCommand(opensearch.NewCmd()) - cmd.AddCommand(organization.NewCmd()) - cmd.AddCommand(postgresflex.NewCmd()) - cmd.AddCommand(project.NewCmd()) - cmd.AddCommand(rabbitmq.NewCmd()) - cmd.AddCommand(redis.NewCmd()) - cmd.AddCommand(secretsmanager.NewCmd()) - cmd.AddCommand(serviceaccount.NewCmd()) - cmd.AddCommand(ske.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(argus.NewCmd(p)) + cmd.AddCommand(argus.NewCmd(p)) + cmd.AddCommand(auth.NewCmd(p)) + cmd.AddCommand(config.NewCmd(p)) + cmd.AddCommand(curl.NewCmd(p)) + cmd.AddCommand(dns.NewCmd(p)) + cmd.AddCommand(logme.NewCmd(p)) + cmd.AddCommand(mariadb.NewCmd(p)) + cmd.AddCommand(mongodbflex.NewCmd(p)) + cmd.AddCommand(objectstorage.NewCmd(p)) + cmd.AddCommand(opensearch.NewCmd(p)) + cmd.AddCommand(organization.NewCmd(p)) + cmd.AddCommand(postgresflex.NewCmd(p)) + cmd.AddCommand(logme.NewCmd(p)) + cmd.AddCommand(mariadb.NewCmd(p)) + cmd.AddCommand(mongodbflex.NewCmd(p)) + cmd.AddCommand(objectstorage.NewCmd(p)) + cmd.AddCommand(opensearch.NewCmd(p)) + cmd.AddCommand(organization.NewCmd(p)) + cmd.AddCommand(postgresflex.NewCmd(p)) + cmd.AddCommand(project.NewCmd(p)) + cmd.AddCommand(rabbitmq.NewCmd(p)) + cmd.AddCommand(redis.NewCmd(p)) + cmd.AddCommand(secretsmanager.NewCmd(p)) + cmd.AddCommand(serviceaccount.NewCmd(p)) + cmd.AddCommand(ske.NewCmd(p)) + cmd.AddCommand(rabbitmq.NewCmd(p)) + cmd.AddCommand(redis.NewCmd(p)) + cmd.AddCommand(secretsmanager.NewCmd(p)) + cmd.AddCommand(serviceaccount.NewCmd(p)) + cmd.AddCommand(ske.NewCmd(p)) } // traverseCommands calls f for c and all of its children. @@ -114,11 +132,18 @@ func traverseCommands(c *cobra.Command, f func(*cobra.Command)) { } func Execute(version, date string) { - cmd := NewRootCmd(version, date) + p := print.NewPrinter() + cmd := NewRootCmd(version, date, p) + + // We need to set the printer and verbosity here because the + // PersistentPreRun is not called when the command is wrongly called + p.Cmd = cmd + p.Verbosity = print.InfoLevel + err := cmd.Execute() if err != nil { err := beautifyUnknownAndMissingCommandsError(cmd, err) - cmd.PrintErrln(cmd.ErrPrefix(), err.Error()) + p.Error(err.Error()) os.Exit(1) } } diff --git a/internal/cmd/secrets-manager/instance/create/create.go b/internal/cmd/secrets-manager/instance/create/create.go index 42964c1e9..7a6d80886 100644 --- a/internal/cmd/secrets-manager/instance/create/create.go +++ b/internal/cmd/secrets-manager/instance/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { Acls *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a Secrets Manager instance", @@ -53,19 +53,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a Secrets Manager instance for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -91,7 +91,7 @@ If you want to retry configuring the ACLs, you can do it via: } } - cmd.Printf("Created instance for project %q. Instance ID: %s\n", projectLabel, instanceId) + p.Outputf("Created instance for project %q. Instance ID: %s\n", projectLabel, instanceId) return nil }, } diff --git a/internal/cmd/secrets-manager/instance/create/create_test.go b/internal/cmd/secrets-manager/instance/create/create_test.go index cd8df3d1c..76375bc58 100644 --- a/internal/cmd/secrets-manager/instance/create/create_test.go +++ b/internal/cmd/secrets-manager/instance/create/create_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr("example"), Acls: utils.Ptr([]string{"198.51.100.14/24"}), @@ -101,6 +102,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceName: utils.Ptr(""), Acls: &[]string{}, @@ -180,7 +182,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/instance/delete/delete.go b/internal/cmd/secrets-manager/instance/delete/delete.go index 85df4fd8b..42fff7fb4 100644 --- a/internal/cmd/secrets-manager/instance/delete/delete.go +++ b/internal/cmd/secrets-manager/instance/delete/delete.go @@ -6,10 +6,10 @@ import ( "github.com/spf13/cobra" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsmanagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -25,7 +25,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", instanceIdArg), Short: "Deletes a Secrets Manager instance", @@ -44,7 +44,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -56,7 +56,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete instance %q? (This cannot be undone)", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -69,7 +69,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete Secrets Manager instance: %w", err) } - cmd.Printf("Deleted instance %q \n", model.InstanceId) + p.Info("Deleted instance %q \n", model.InstanceId) return nil }, } diff --git a/internal/cmd/secrets-manager/instance/delete/delete_test.go b/internal/cmd/secrets-manager/instance/delete/delete_test.go index fff0cf83c..3fa907dfe 100644 --- a/internal/cmd/secrets-manager/instance/delete/delete_test.go +++ b/internal/cmd/secrets-manager/instance/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -135,7 +136,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/instance/describe/describe.go b/internal/cmd/secrets-manager/instance/describe/describe.go index 559f42f73..bcfe42cbb 100644 --- a/internal/cmd/secrets-manager/instance/describe/describe.go +++ b/internal/cmd/secrets-manager/instance/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -27,7 +28,7 @@ type inputModel struct { InstanceId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", instanceIdArg), Short: "Shows details of a Secrets Manager instance", @@ -48,7 +49,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -67,7 +68,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read Secrets Manager instance ACLs: %w", err) } - return outputResult(cmd, model.OutputFormat, instance, aclList) + return outputResult(p, model.OutputFormat, instance, aclList) }, } return cmd @@ -97,7 +98,7 @@ func buildListACLsRequest(ctx context.Context, model *inputModel, apiClient *sec return req } -func outputResult(cmd *cobra.Command, outputFormat string, instance *secretsmanager.Instance, aclList *secretsmanager.AclList) error { +func outputResult(p *print.Printer, outputFormat string, instance *secretsmanager.Instance, aclList *secretsmanager.AclList) error { switch outputFormat { case globalflags.PrettyOutputFormat: @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *secretsmana table.AddRow("ACL", strings.Join(cidrs, ",")) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -140,7 +141,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instance *secretsmana if err != nil { return fmt.Errorf("marshal Secrets Manager instance: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/secrets-manager/instance/describe/describe_test.go b/internal/cmd/secrets-manager/instance/describe/describe_test.go index da65fa1cc..6ec20eb30 100644 --- a/internal/cmd/secrets-manager/instance/describe/describe_test.go +++ b/internal/cmd/secrets-manager/instance/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, } @@ -143,7 +144,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/instance/instance.go b/internal/cmd/secrets-manager/instance/instance.go index 9a3283638..cc38f6ca7 100644 --- a/internal/cmd/secrets-manager/instance/instance.go +++ b/internal/cmd/secrets-manager/instance/instance.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/secrets-manager/instance/list" "github.com/stackitcloud/stackit-cli/internal/cmd/secrets-manager/instance/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "instance", Short: "Provides functionality for Secrets Manager instances", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/secrets-manager/instance/list/list.go b/internal/cmd/secrets-manager/instance/list/list.go index 08ce4d38d..57e6a5fe3 100644 --- a/internal/cmd/secrets-manager/instance/list/list.go +++ b/internal/cmd/secrets-manager/instance/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all Secrets Manager instances", @@ -52,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,11 +66,11 @@ func NewCmd() *cobra.Command { } if resp.Instances == nil || len(*resp.Instances) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No instances found for project %q\n", projectLabel) + p.Info("No instances found for project %q\n", projectLabel) return nil } instances := *resp.Instances @@ -79,7 +80,7 @@ func NewCmd() *cobra.Command { instances = instances[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, instances) + return outputResult(p, model.OutputFormat, instances) }, } @@ -116,14 +117,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *secretsmana return req } -func outputResult(cmd *cobra.Command, outputFormat string, instances []secretsmanager.Instance) error { +func outputResult(p *print.Printer, outputFormat string, instances []secretsmanager.Instance) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(instances, "", " ") if err != nil { return fmt.Errorf("marshal Secrets Manager instance list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -133,7 +134,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, instances []secretsma instance := instances[i] table.AddRow(*instance.Id, *instance.Name, *instance.State, *instance.SecretCount) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/secrets-manager/instance/list/list_test.go b/internal/cmd/secrets-manager/instance/list/list_test.go index 7fc0b159d..bc27b6ae4 100644 --- a/internal/cmd/secrets-manager/instance/list/list_test.go +++ b/internal/cmd/secrets-manager/instance/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/secrets-manager/instance/update/update.go b/internal/cmd/secrets-manager/instance/update/update.go index cb38c6d71..365477ea3 100644 --- a/internal/cmd/secrets-manager/instance/update/update.go +++ b/internal/cmd/secrets-manager/instance/update/update.go @@ -5,12 +5,12 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" cliErr "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -32,7 +32,7 @@ type inputModel struct { Acls *[]string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", instanceIdArg), Short: "Updates a Secrets Manager instance", @@ -51,7 +51,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -63,7 +63,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -76,7 +76,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("update Secrets Manager instance: %w", err) } - cmd.Printf("Updated instance %q\n", instanceLabel) + p.Info("Updated instance %q\n", instanceLabel) return nil }, } diff --git a/internal/cmd/secrets-manager/instance/update/update_test.go b/internal/cmd/secrets-manager/instance/update/update_test.go index ee62ce0b6..fb858ebdc 100644 --- a/internal/cmd/secrets-manager/instance/update/update_test.go +++ b/internal/cmd/secrets-manager/instance/update/update_test.go @@ -55,6 +55,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Acls: utils.Ptr([]string{testACL1}), @@ -195,7 +196,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/secrets_manager.go b/internal/cmd/secrets-manager/secrets_manager.go index a7753e5ad..d9c78f035 100644 --- a/internal/cmd/secrets-manager/secrets_manager.go +++ b/internal/cmd/secrets-manager/secrets_manager.go @@ -4,12 +4,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/secrets-manager/instance" "github.com/stackitcloud/stackit-cli/internal/cmd/secrets-manager/user" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "secrets-manager", Short: "Provides functionality for Secrets Manager", @@ -17,11 +18,11 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(instance.NewCmd()) - cmd.AddCommand(user.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(instance.NewCmd(p)) + cmd.AddCommand(user.NewCmd(p)) } diff --git a/internal/cmd/secrets-manager/user/create/create.go b/internal/cmd/secrets-manager/user/create/create.go index d8fae03d6..35ea18110 100644 --- a/internal/cmd/secrets-manager/user/create/create.go +++ b/internal/cmd/secrets-manager/user/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -32,7 +32,7 @@ type inputModel struct { Write *bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a Secrets Manager user", @@ -58,7 +58,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a user for instance %q?", instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,11 +83,11 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create Secrets Manager user: %w", err) } - cmd.Printf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *resp.Id) - cmd.Printf("Username: %s\n", *resp.Username) - cmd.Printf("Password: %s\n", *resp.Password) - cmd.Printf("Description: %s\n", *resp.Description) - cmd.Printf("Write Access: %t\n", *resp.Write) + p.Outputf("Created user for instance %q. User ID: %s\n\n", instanceLabel, *resp.Id) + p.Outputf("Username: %s\n", *resp.Username) + p.Outputf("Password: %s\n", *resp.Password) + p.Outputf("Description: %s\n", *resp.Description) + p.Outputf("Write Access: %t\n", *resp.Write) return nil }, diff --git a/internal/cmd/secrets-manager/user/create/create_test.go b/internal/cmd/secrets-manager/user/create/create_test.go index 1f1016ba4..d88b94e2a 100644 --- a/internal/cmd/secrets-manager/user/create/create_test.go +++ b/internal/cmd/secrets-manager/user/create/create_test.go @@ -40,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, Description: utils.Ptr("sample description"), diff --git a/internal/cmd/secrets-manager/user/delete/delete.go b/internal/cmd/secrets-manager/user/delete/delete.go index 618aaed2b..c2967c96b 100644 --- a/internal/cmd/secrets-manager/user/delete/delete.go +++ b/internal/cmd/secrets-manager/user/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +31,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", userIdArg), Short: "Deletes a Secrets Manager user", @@ -53,7 +53,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete user %s of instance %q? (This cannot be undone)", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -83,7 +83,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete Secrets Manager user: %w", err) } - cmd.Printf("Deleted user %s of instance %q\n", userLabel, instanceLabel) + p.Info("Deleted user %s of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/secrets-manager/user/delete/delete_test.go b/internal/cmd/secrets-manager/user/delete/delete_test.go index 2fec10573..0b4605d6d 100644 --- a/internal/cmd/secrets-manager/user/delete/delete_test.go +++ b/internal/cmd/secrets-manager/user/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -150,7 +151,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/user/describe/describe.go b/internal/cmd/secrets-manager/user/describe/describe.go index bca914815..c43fe6f08 100644 --- a/internal/cmd/secrets-manager/user/describe/describe.go +++ b/internal/cmd/secrets-manager/user/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -31,7 +32,7 @@ type inputModel struct { UserId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", userIdArg), Short: "Shows details of a Secrets Manager user", @@ -53,7 +54,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -65,7 +66,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get Secrets Manager user: %w", err) } - return outputResult(cmd, model.OutputFormat, *resp) + return outputResult(p, model.OutputFormat, *resp) }, } @@ -100,7 +101,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *secretsmana return req } -func outputResult(cmd *cobra.Command, outputFormat string, user secretsmanager.User) error { +func outputResult(p *print.Printer, outputFormat string, user secretsmanager.User) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() @@ -118,7 +119,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user secretsmanager.U } table.AddRow("WRITE ACCESS", *user.Write) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -129,7 +130,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, user secretsmanager.U if err != nil { return fmt.Errorf("marshal Secrets Manager user: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/secrets-manager/user/describe/describe_test.go b/internal/cmd/secrets-manager/user/describe/describe_test.go index 226967fe5..e9c055f93 100644 --- a/internal/cmd/secrets-manager/user/describe/describe_test.go +++ b/internal/cmd/secrets-manager/user/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -162,7 +163,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/user/list/list.go b/internal/cmd/secrets-manager/user/list/list.go index 92a4632b6..d5d9440ca 100644 --- a/internal/cmd/secrets-manager/user/list/list.go +++ b/internal/cmd/secrets-manager/user/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -30,7 +31,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all Secrets Manager users", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { if err != nil { instanceLabel = *model.InstanceId } - cmd.Printf("No users found for instance %q\n", instanceLabel) + p.Info("No users found for instance %q\n", instanceLabel) return nil } users := *resp.Users @@ -81,7 +82,7 @@ func NewCmd() *cobra.Command { users = users[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, users) + return outputResult(p, model.OutputFormat, users) }, } @@ -123,14 +124,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *secretsmana return req } -func outputResult(cmd *cobra.Command, outputFormat string, users []secretsmanager.User) error { +func outputResult(p *print.Printer, outputFormat string, users []secretsmanager.User) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(users, "", " ") if err != nil { return fmt.Errorf("marshal Secrets Manager user list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -140,7 +141,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, users []secretsmanage user := users[i] table.AddRow(*user.Id, *user.Username, *user.Description, *user.Write) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/secrets-manager/user/list/list_test.go b/internal/cmd/secrets-manager/user/list/list_test.go index 0f85250ee..b3e764903 100644 --- a/internal/cmd/secrets-manager/user/list/list_test.go +++ b/internal/cmd/secrets-manager/user/list/list_test.go @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: utils.Ptr(testInstanceId), Limit: utils.Ptr(int64(10)), diff --git a/internal/cmd/secrets-manager/user/update/update.go b/internal/cmd/secrets-manager/user/update/update.go index 9fe27207d..53a711592 100644 --- a/internal/cmd/secrets-manager/user/update/update.go +++ b/internal/cmd/secrets-manager/user/update/update.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/client" secretsManagerUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/secrets-manager/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -35,7 +35,7 @@ type inputModel struct { DisableWrite *bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", userIdArg), Short: "Updates the write privileges Secrets Manager user", @@ -57,7 +57,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update user %s of instance %q?", userLabel, instanceLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -91,7 +91,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("update Secrets Manager user: %w", err) } - cmd.Printf("Updated user %s of instance %q\n", userLabel, instanceLabel) + p.Info("Updated user %s of instance %q\n", userLabel, instanceLabel) return nil }, } diff --git a/internal/cmd/secrets-manager/user/update/update_test.go b/internal/cmd/secrets-manager/user/update/update_test.go index 3b80192ce..8d39b9c36 100644 --- a/internal/cmd/secrets-manager/user/update/update_test.go +++ b/internal/cmd/secrets-manager/user/update/update_test.go @@ -49,6 +49,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, InstanceId: testInstanceId, UserId: testUserId, @@ -186,7 +187,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/secrets-manager/user/user.go b/internal/cmd/secrets-manager/user/user.go index 76379621b..8dcd68410 100644 --- a/internal/cmd/secrets-manager/user/user.go +++ b/internal/cmd/secrets-manager/user/user.go @@ -2,6 +2,7 @@ package user import ( "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" @@ -12,7 +13,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/secrets-manager/user/update" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "user", Short: "Provides functionality for Secrets Manager users", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/service-account/create/create.go b/internal/cmd/service-account/create/create.go index 038a2067e..39931160e 100644 --- a/internal/cmd/service-account/create/create.go +++ b/internal/cmd/service-account/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" @@ -26,7 +26,7 @@ type inputModel struct { Name *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a service account", @@ -45,19 +45,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a service account for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -70,7 +70,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create service account: %w", err) } - cmd.Printf("Created service account for project %q. Email: %s\n", projectLabel, *resp.Email) + p.Outputf("Created service account for project %q. Email: %s\n", projectLabel, *resp.Email) return nil }, } diff --git a/internal/cmd/service-account/create/create_test.go b/internal/cmd/service-account/create/create_test.go index fa980d5cc..66c3da314 100644 --- a/internal/cmd/service-account/create/create_test.go +++ b/internal/cmd/service-account/create/create_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr("example"), } @@ -84,6 +85,7 @@ func TestParseInput(t *testing.T) { expectedModel: &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Name: utils.Ptr(""), }, @@ -113,7 +115,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/delete/delete.go b/internal/cmd/service-account/delete/delete.go index edcdccec6..cb8b525c7 100644 --- a/internal/cmd/service-account/delete/delete.go +++ b/internal/cmd/service-account/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/spf13/cobra" @@ -24,7 +24,7 @@ type inputModel struct { Email string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", emailArg), Short: "Deletes a service account", @@ -43,14 +43,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete service account %s? (This cannot be undone)", model.Email) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -66,7 +66,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete service account: %w", err) } - cmd.Printf("Service account %s deleted\n", model.Email) + p.Info("Service account %s deleted\n", model.Email) return nil }, } diff --git a/internal/cmd/service-account/delete/delete_test.go b/internal/cmd/service-account/delete/delete_test.go index b6b194c93..8653abe86 100644 --- a/internal/cmd/service-account/delete/delete_test.go +++ b/internal/cmd/service-account/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Email: testEmail, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/get-jwks/get_jwks.go b/internal/cmd/service-account/get-jwks/get_jwks.go index b06ba7736..02856e361 100644 --- a/internal/cmd/service-account/get-jwks/get_jwks.go +++ b/internal/cmd/service-account/get-jwks/get_jwks.go @@ -7,6 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/args" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/spf13/cobra" @@ -21,7 +22,7 @@ type inputModel struct { Email string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("get-jwks %s", emailArg), Short: "Shows the JWKS for a service account", @@ -40,7 +41,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -53,11 +54,11 @@ func NewCmd() *cobra.Command { } jwks := *resp.Keys if len(jwks) == 0 { - cmd.Printf("Empty JWKS for service account %s\n", model.Email) + p.Info("Empty JWKS for service account %s\n", model.Email) return nil } - return outputResult(cmd, jwks) + return outputResult(p, jwks) }, } @@ -77,11 +78,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceacco return req } -func outputResult(cmd *cobra.Command, serviceAccounts []serviceaccount.JWK) error { +func outputResult(p *print.Printer, serviceAccounts []serviceaccount.JWK) error { details, err := json.MarshalIndent(serviceAccounts, "", " ") if err != nil { return fmt.Errorf("marshal JWK list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/service-account/get-jwks/get_jwks_test.go b/internal/cmd/service-account/get-jwks/get_jwks_test.go index 893178fd5..616579f21 100644 --- a/internal/cmd/service-account/get-jwks/get_jwks_test.go +++ b/internal/cmd/service-account/get-jwks/get_jwks_test.go @@ -67,7 +67,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/key/create/create.go b/internal/cmd/service-account/key/create/create.go index 9e57769db..d2efaa40f 100644 --- a/internal/cmd/service-account/key/create/create.go +++ b/internal/cmd/service-account/key/create/create.go @@ -7,11 +7,11 @@ import ( "time" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -33,7 +33,7 @@ type inputModel struct { PublicKey *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates a service account key", @@ -62,7 +62,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -73,7 +73,7 @@ func NewCmd() *cobra.Command { validUntilInfo = fmt.Sprintf("The key will be valid for %d days", *model.ExpiresInDays) } prompt := fmt.Sprintf("Are you sure you want to create a key for service account %s? %s", model.ServiceAccountEmail, validUntilInfo) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -86,13 +86,13 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create service account key: %w", err) } - cmd.PrintErrf("Created key for service account %s with ID %q\n", model.ServiceAccountEmail, *resp.Id) + p.Info("Created key for service account %s with ID %q\n", model.ServiceAccountEmail, *resp.Id) key, err := json.MarshalIndent(resp, "", " ") if err != nil { return fmt.Errorf("marshal key: %w", err) } - cmd.Println(string(key)) + p.Outputln(string(key)) return nil }, } diff --git a/internal/cmd/service-account/key/create/create_test.go b/internal/cmd/service-account/key/create/create_test.go index b15b3b681..1a621d14b 100644 --- a/internal/cmd/service-account/key/create/create_test.go +++ b/internal/cmd/service-account/key/create/create_test.go @@ -41,6 +41,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, } @@ -139,7 +140,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/key/delete/delete.go b/internal/cmd/service-account/key/delete/delete.go index b54fdde92..b438fc13d 100644 --- a/internal/cmd/service-account/key/delete/delete.go +++ b/internal/cmd/service-account/key/delete/delete.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +30,7 @@ type inputModel struct { KeyId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", keyIdArg), Short: "Deletes a service account key", @@ -49,14 +49,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete the key %s from service account %s?", model.KeyId, model.ServiceAccountEmail) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -69,7 +69,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("delete key: %w", err) } - cmd.Printf("Deleted key %s from service account %s\n", model.KeyId, model.ServiceAccountEmail) + p.Info("Deleted key %s from service account %s\n", model.KeyId, model.ServiceAccountEmail) return nil }, } diff --git a/internal/cmd/service-account/key/delete/delete_test.go b/internal/cmd/service-account/key/delete/delete_test.go index 737e8b351..056e8c04c 100644 --- a/internal/cmd/service-account/key/delete/delete_test.go +++ b/internal/cmd/service-account/key/delete/delete_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, KeyId: testKeyId, @@ -146,7 +147,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/key/describe/describe.go b/internal/cmd/service-account/key/describe/describe.go index 1112f0694..18280e676 100644 --- a/internal/cmd/service-account/key/describe/describe.go +++ b/internal/cmd/service-account/key/describe/describe.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -30,7 +31,7 @@ type inputModel struct { KeyId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", keyIdArg), Short: "Shows details of a service account key", @@ -48,7 +49,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -60,7 +61,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read service account key: %w", err) } - return outputResult(cmd, resp) + return outputResult(p, resp) }, } configureFlags(cmd) @@ -102,11 +103,11 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceacco return req } -func outputResult(cmd *cobra.Command, key *serviceaccount.GetServiceAccountKeyResponse) error { +func outputResult(p *print.Printer, key *serviceaccount.GetServiceAccountKeyResponse) error { marshaledKey, err := json.MarshalIndent(key, "", " ") if err != nil { return fmt.Errorf("marshal service account key: %w", err) } - cmd.Println(string(marshaledKey)) + p.Outputln(string(marshaledKey)) return nil } diff --git a/internal/cmd/service-account/key/describe/describe_test.go b/internal/cmd/service-account/key/describe/describe_test.go index 7bd871b8a..06797196d 100644 --- a/internal/cmd/service-account/key/describe/describe_test.go +++ b/internal/cmd/service-account/key/describe/describe_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, KeyId: testKeyId, @@ -146,7 +147,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/key/key.go b/internal/cmd/service-account/key/key.go index b180160fd..96ec51ae3 100644 --- a/internal/cmd/service-account/key/key.go +++ b/internal/cmd/service-account/key/key.go @@ -7,12 +7,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/key/list" "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/key/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "key", Short: "Provides functionality regarding service account keys", @@ -20,14 +21,14 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/service-account/key/list/list.go b/internal/cmd/service-account/key/list/list.go index c3fcfbf5d..69c2b3667 100644 --- a/internal/cmd/service-account/key/list/list.go +++ b/internal/cmd/service-account/key/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all service account keys", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -67,7 +68,7 @@ func NewCmd() *cobra.Command { } keys := *resp.Items if len(keys) == 0 { - cmd.Printf("No keys found for service account %s\n", model.ServiceAccountEmail) + p.Info("No keys found for service account %s\n", model.ServiceAccountEmail) return nil } @@ -76,7 +77,7 @@ func NewCmd() *cobra.Command { keys = keys[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, keys) + return outputResult(p, model.OutputFormat, keys) }, } @@ -126,14 +127,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceacco return req } -func outputResult(cmd *cobra.Command, outputFormat string, keys []serviceaccount.ServiceAccountKeyListResponse) error { +func outputResult(p *print.Printer, outputFormat string, keys []serviceaccount.ServiceAccountKeyListResponse) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(keys, "", " ") if err != nil { return fmt.Errorf("marshal keys metadata: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -147,7 +148,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, keys []serviceaccount } table.AddRow(*k.Id, *k.Active, *k.CreatedAt, validUntil) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/service-account/key/list/list_test.go b/internal/cmd/service-account/key/list/list_test.go index 09ac930d6..574480c63 100644 --- a/internal/cmd/service-account/key/list/list_test.go +++ b/internal/cmd/service-account/key/list/list_test.go @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, Limit: utils.Ptr(int64(10)), diff --git a/internal/cmd/service-account/key/update/update.go b/internal/cmd/service-account/key/update/update.go index d0440c1d1..2aeda0da6 100644 --- a/internal/cmd/service-account/key/update/update.go +++ b/internal/cmd/service-account/key/update/update.go @@ -7,11 +7,11 @@ import ( "time" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -38,7 +38,7 @@ type inputModel struct { Deactivate bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", keyIdArg), Short: "Updates a service account key", @@ -66,14 +66,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update the key with ID %q?", model.KeyId) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -90,7 +90,7 @@ func NewCmd() *cobra.Command { if err != nil { return fmt.Errorf("marshal key: %w", err) } - cmd.Println(string(key)) + p.Info(string(key)) return nil }, } diff --git a/internal/cmd/service-account/key/update/update_test.go b/internal/cmd/service-account/key/update/update_test.go index ea573bf5c..9e15d4d14 100644 --- a/internal/cmd/service-account/key/update/update_test.go +++ b/internal/cmd/service-account/key/update/update_test.go @@ -51,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, KeyId: testKeyId, @@ -193,7 +194,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/list/list.go b/internal/cmd/service-account/list/list.go index 8f72f5ccf..b9f3377c5 100644 --- a/internal/cmd/service-account/list/list.go +++ b/internal/cmd/service-account/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -27,7 +28,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all service accounts", @@ -46,7 +47,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -59,11 +60,11 @@ func NewCmd() *cobra.Command { } serviceAccounts := *resp.Items if len(serviceAccounts) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No service accounts found for project %q\n", projectLabel) + p.Info("No service accounts found for project %q\n", projectLabel) return nil } @@ -72,7 +73,7 @@ func NewCmd() *cobra.Command { serviceAccounts = serviceAccounts[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, serviceAccounts) + return outputResult(p, model.OutputFormat, serviceAccounts) }, } @@ -109,14 +110,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceacco return req } -func outputResult(cmd *cobra.Command, outputFormat string, serviceAccounts []serviceaccount.ServiceAccount) error { +func outputResult(p *print.Printer, outputFormat string, serviceAccounts []serviceaccount.ServiceAccount) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(serviceAccounts, "", " ") if err != nil { return fmt.Errorf("marshal service accounts list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) default: table := tables.NewTable() table.SetHeader("ID", "EMAIL") @@ -124,7 +125,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, serviceAccounts []ser account := serviceAccounts[i] table.AddRow(*account.Id, *account.Email) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/service-account/list/list_test.go b/internal/cmd/service-account/list/list_test.go index 9f2da3a0e..e853aad3d 100644 --- a/internal/cmd/service-account/list/list_test.go +++ b/internal/cmd/service-account/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/service-account/service_account.go b/internal/cmd/service-account/service_account.go index 3669100d4..8a4f4634d 100644 --- a/internal/cmd/service-account/service_account.go +++ b/internal/cmd/service-account/service_account.go @@ -8,12 +8,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/list" "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/token" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "service-account", Short: "Provides functionality for service accounts", @@ -21,16 +22,16 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(getjwks.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(getjwks.NewCmd(p)) - cmd.AddCommand(key.NewCmd()) - cmd.AddCommand(token.NewCmd()) + cmd.AddCommand(key.NewCmd(p)) + cmd.AddCommand(token.NewCmd(p)) } diff --git a/internal/cmd/service-account/token/create/create.go b/internal/cmd/service-account/token/create/create.go index 71e050c05..66f0ab53c 100644 --- a/internal/cmd/service-account/token/create/create.go +++ b/internal/cmd/service-account/token/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/spf13/cobra" @@ -30,7 +30,7 @@ type inputModel struct { TTLDays *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "create", Short: "Creates an access token for a service account", @@ -56,14 +56,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create an access token for service account %s?", model.ServiceAccountEmail) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -76,9 +76,9 @@ func NewCmd() *cobra.Command { return fmt.Errorf("create access token: %w", err) } - cmd.Printf("Created access token for service account %s. Token ID: %s\n\n", model.ServiceAccountEmail, *token.Id) - cmd.Printf("Valid until: %s\n", *token.ValidUntil) - cmd.Printf("Token: %s\n", *token.Token) + p.Outputf("Created access token for service account %s. Token ID: %s\n\n", model.ServiceAccountEmail, *token.Id) + p.Outputf("Valid until: %s\n", *token.ValidUntil) + p.Outputf("Token: %s\n", *token.Token) return nil }, } diff --git a/internal/cmd/service-account/token/create/create_test.go b/internal/cmd/service-account/token/create/create_test.go index 0191bf84b..edaeca401 100644 --- a/internal/cmd/service-account/token/create/create_test.go +++ b/internal/cmd/service-account/token/create/create_test.go @@ -40,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, TTLDays: utils.Ptr(testTTLDays), @@ -118,7 +119,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/token/list/list.go b/internal/cmd/service-account/token/list/list.go index 66aa10dc3..cf9323ee0 100644 --- a/internal/cmd/service-account/token/list/list.go +++ b/internal/cmd/service-account/token/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -29,7 +30,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists access tokens of a service account", @@ -58,7 +59,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -71,7 +72,7 @@ func NewCmd() *cobra.Command { } tokensMetadata := *resp.Items if len(tokensMetadata) == 0 { - cmd.Printf("No tokens found for service account with email %q\n", model.ServiceAccountEmail) + p.Info("No tokens found for service account with email %q\n", model.ServiceAccountEmail) return nil } @@ -80,7 +81,7 @@ func NewCmd() *cobra.Command { tokensMetadata = tokensMetadata[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, tokensMetadata) + return outputResult(p, model.OutputFormat, tokensMetadata) }, } @@ -130,14 +131,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *serviceacco return req } -func outputResult(cmd *cobra.Command, outputFormat string, tokensMetadata []serviceaccount.AccessTokenMetadata) error { +func outputResult(p *print.Printer, outputFormat string, tokensMetadata []serviceaccount.AccessTokenMetadata) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(tokensMetadata, "", " ") if err != nil { return fmt.Errorf("marshal tokens metadata: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -147,7 +148,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, tokensMetadata []serv t := tokensMetadata[i] table.AddRow(*t.Id, *t.Active, *t.CreatedAt, *t.ValidUntil) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/service-account/token/list/list_test.go b/internal/cmd/service-account/token/list/list_test.go index 333c1b854..2f577572f 100644 --- a/internal/cmd/service-account/token/list/list_test.go +++ b/internal/cmd/service-account/token/list/list_test.go @@ -39,6 +39,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, Limit: utils.Ptr(int64(10)), diff --git a/internal/cmd/service-account/token/revoke/revoke.go b/internal/cmd/service-account/token/revoke/revoke.go index 15ab869a6..3ce6f0ef7 100644 --- a/internal/cmd/service-account/token/revoke/revoke.go +++ b/internal/cmd/service-account/token/revoke/revoke.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/service-account/client" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" @@ -29,7 +29,7 @@ type inputModel struct { TokenId string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("revoke %s", tokenIdArg), Short: "Revokes an access token of a service account", @@ -52,14 +52,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to revoke the access token with ID %q?", model.TokenId) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -72,7 +72,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("revoke access token: %w", err) } - cmd.Printf("Revoked access token with ID %q\n", model.TokenId) + p.Info("Revoked access token with ID %q\n", model.TokenId) return nil }, } diff --git a/internal/cmd/service-account/token/revoke/revoke_test.go b/internal/cmd/service-account/token/revoke/revoke_test.go index a9cb08739..824f210d5 100644 --- a/internal/cmd/service-account/token/revoke/revoke_test.go +++ b/internal/cmd/service-account/token/revoke/revoke_test.go @@ -47,6 +47,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ServiceAccountEmail: testServiceAccountEmail, TokenId: testTokenId, @@ -146,7 +147,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/service-account/token/token.go b/internal/cmd/service-account/token/token.go index 7233f8929..af6d363d4 100644 --- a/internal/cmd/service-account/token/token.go +++ b/internal/cmd/service-account/token/token.go @@ -5,12 +5,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/token/list" "github.com/stackitcloud/stackit-cli/internal/cmd/service-account/token/revoke" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "token", Short: "Provides functionality regarding service account tokens", @@ -18,12 +19,12 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(revoke.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(revoke.NewCmd(p)) } diff --git a/internal/cmd/ske/cluster/cluster.go b/internal/cmd/ske/cluster/cluster.go index 478bd0e32..c5bb7b36b 100644 --- a/internal/cmd/ske/cluster/cluster.go +++ b/internal/cmd/ske/cluster/cluster.go @@ -8,12 +8,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/ske/cluster/list" "github.com/stackitcloud/stackit-cli/internal/cmd/ske/cluster/update" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "cluster", Short: "Provides functionality for SKE cluster", @@ -21,15 +22,15 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(generatepayload.NewCmd()) - cmd.AddCommand(create.NewCmd()) - cmd.AddCommand(delete.NewCmd()) - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(list.NewCmd()) - cmd.AddCommand(update.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(generatepayload.NewCmd(p)) + cmd.AddCommand(create.NewCmd(p)) + cmd.AddCommand(delete.NewCmd(p)) + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(list.NewCmd(p)) + cmd.AddCommand(update.NewCmd(p)) } diff --git a/internal/cmd/ske/cluster/create/create.go b/internal/cmd/ske/cluster/create/create.go index 81c72d2f8..26ced6182 100644 --- a/internal/cmd/ske/cluster/create/create.go +++ b/internal/cmd/ske/cluster/create/create.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" @@ -33,7 +33,7 @@ type inputModel struct { Payload *ske.CreateOrUpdateClusterPayload } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("create %s", clusterNameArg), Short: "Creates an SKE cluster", @@ -67,19 +67,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a cluster for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -122,7 +122,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Creating cluster") _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient, model.ProjectId, name).WaitWithContext(ctx) if err != nil { @@ -135,7 +135,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered creation of" } - cmd.Printf("%s cluster for project %q. Cluster name: %s\n", operationState, projectLabel, name) + p.Outputf("%s cluster for project %q. Cluster name: %s\n", operationState, projectLabel, name) return nil }, } diff --git a/internal/cmd/ske/cluster/create/create_test.go b/internal/cmd/ske/cluster/create/create_test.go index db09309f1..2583bb864 100644 --- a/internal/cmd/ske/cluster/create/create_test.go +++ b/internal/cmd/ske/cluster/create/create_test.go @@ -124,6 +124,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, Payload: testPayload, @@ -224,7 +225,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/cluster/delete/delete.go b/internal/cmd/ske/cluster/delete/delete.go index fb8412554..83e3c574e 100644 --- a/internal/cmd/ske/cluster/delete/delete.go +++ b/internal/cmd/ske/cluster/delete/delete.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("delete %s", clusterNameArg), Short: "Deletes a SKE cluster", @@ -45,14 +45,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to delete cluster %q? (This cannot be undone)", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -67,7 +67,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Deleting cluster") _, err = wait.DeleteClusterWaitHandler(ctx, apiClient, model.ProjectId, model.ClusterName).WaitWithContext(ctx) if err != nil { @@ -80,7 +80,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered deletion of" } - cmd.Printf("%s cluster %q\n", operationState, model.ClusterName) + p.Info("%s cluster %q\n", operationState, model.ClusterName) return nil }, } diff --git a/internal/cmd/ske/cluster/delete/delete_test.go b/internal/cmd/ske/cluster/delete/delete_test.go index f95a3ed58..cb2d3aca0 100644 --- a/internal/cmd/ske/cluster/delete/delete_test.go +++ b/internal/cmd/ske/cluster/delete/delete_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/cluster/describe/describe.go b/internal/cmd/ske/cluster/describe/describe.go index 84687b7a8..0f6804914 100644 --- a/internal/cmd/ske/cluster/describe/describe.go +++ b/internal/cmd/ske/cluster/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -25,7 +26,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", clusterNameArg), Short: "Shows details of a SKE cluster", @@ -46,7 +47,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -58,7 +59,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read SKE cluster: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -83,7 +84,7 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, cluster *ske.Cluster) error { +func outputResult(p *print.Printer, outputFormat string, cluster *ske.Cluster) error { switch outputFormat { case globalflags.PrettyOutputFormat: @@ -100,7 +101,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, cluster *ske.Cluster) table.AddRow("VERSION", *cluster.Kubernetes.Version) table.AddSeparator() table.AddRow("ACL", acl) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -111,7 +112,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, cluster *ske.Cluster) if err != nil { return fmt.Errorf("marshal SKE cluster: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/ske/cluster/describe/describe_test.go b/internal/cmd/ske/cluster/describe/describe_test.go index 658cd69fa..833db3b0e 100644 --- a/internal/cmd/ske/cluster/describe/describe_test.go +++ b/internal/cmd/ske/cluster/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/cluster/generate-payload/generate_payload.go b/internal/cmd/ske/cluster/generate-payload/generate_payload.go index 94eab9704..195255455 100644 --- a/internal/cmd/ske/cluster/generate-payload/generate_payload.go +++ b/internal/cmd/ske/cluster/generate-payload/generate_payload.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" @@ -26,7 +27,7 @@ type inputModel struct { ClusterName *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "generate-payload", Short: "Generates a payload to create/update SKE clusters", @@ -55,7 +56,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -82,7 +83,7 @@ func NewCmd() *cobra.Command { } } - return outputResult(cmd, payload) + return outputResult(p, payload) }, } configureFlags(cmd) @@ -113,12 +114,12 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClie return req } -func outputResult(cmd *cobra.Command, payload *ske.CreateOrUpdateClusterPayload) error { +func outputResult(p *print.Printer, payload *ske.CreateOrUpdateClusterPayload) error { payloadBytes, err := json.MarshalIndent(*payload, "", " ") if err != nil { return fmt.Errorf("marshal payload: %w", err) } - cmd.Println(string(payloadBytes)) + p.Outputln(string(payloadBytes)) return nil } diff --git a/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go b/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go index 3f7e0adec..0b5500dcd 100644 --- a/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go +++ b/internal/cmd/ske/cluster/generate-payload/generate_payload_test.go @@ -36,6 +36,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: utils.Ptr("example-name"), } @@ -71,7 +72,7 @@ func TestParseInput(t *testing.T) { flagValues: map[string]string{}, isValid: true, expectedModel: &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, }, }, { @@ -109,7 +110,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/cluster/list/list.go b/internal/cmd/ske/cluster/list/list.go index d8468b0f8..d9baa2dec 100644 --- a/internal/cmd/ske/cluster/list/list.go +++ b/internal/cmd/ske/cluster/list/list.go @@ -10,6 +10,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" @@ -28,7 +29,7 @@ type inputModel struct { Limit *int64 } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "list", Short: "Lists all SKE clusters", @@ -53,7 +54,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -75,11 +76,11 @@ func NewCmd() *cobra.Command { } clusters := *resp.Items if len(clusters) == 0 { - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } - cmd.Printf("No clusters found for project %q\n", projectLabel) + p.Info("No clusters found for project %q\n", projectLabel) return nil } @@ -88,7 +89,7 @@ func NewCmd() *cobra.Command { clusters = clusters[:*model.Limit] } - return outputResult(cmd, model.OutputFormat, clusters) + return outputResult(p, model.OutputFormat, clusters) }, } @@ -125,14 +126,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, clusters []ske.Cluster) error { +func outputResult(p *print.Printer, outputFormat string, clusters []ske.Cluster) error { switch outputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(clusters, "", " ") if err != nil { return fmt.Errorf("marshal SKE cluster list: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: @@ -146,7 +147,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, clusters []ske.Cluste } table.AddRow(*c.Name, *c.Status.Aggregated, *c.Kubernetes.Version, len(*c.Nodepools), monitoring) } - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } diff --git a/internal/cmd/ske/cluster/list/list_test.go b/internal/cmd/ske/cluster/list/list_test.go index c9507f95e..898de77e0 100644 --- a/internal/cmd/ske/cluster/list/list_test.go +++ b/internal/cmd/ske/cluster/list/list_test.go @@ -37,6 +37,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, Limit: utils.Ptr(int64(10)), } diff --git a/internal/cmd/ske/cluster/update/update.go b/internal/cmd/ske/cluster/update/update.go index a20ea709b..cac74ea15 100644 --- a/internal/cmd/ske/cluster/update/update.go +++ b/internal/cmd/ske/cluster/update/update.go @@ -6,11 +6,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -32,7 +32,7 @@ type inputModel struct { Payload ske.CreateOrUpdateClusterPayload } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("update %s", clusterNameArg), Short: "Updates an SKE cluster", @@ -63,14 +63,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to update cluster %q?", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -95,7 +95,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Updating cluster") _, err = wait.CreateOrUpdateClusterWaitHandler(ctx, apiClient, model.ProjectId, name).WaitWithContext(ctx) if err != nil { @@ -108,7 +108,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered update of" } - cmd.Printf("%s cluster %q\n", operationState, model.ClusterName) + p.Info("%s cluster %q\n", operationState, model.ClusterName) return nil }, } diff --git a/internal/cmd/ske/cluster/update/update_test.go b/internal/cmd/ske/cluster/update/update_test.go index cfe07e8fd..74e98972c 100644 --- a/internal/cmd/ske/cluster/update/update_test.go +++ b/internal/cmd/ske/cluster/update/update_test.go @@ -124,6 +124,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, Payload: testPayload, @@ -212,7 +213,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go b/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go index d7953efe2..335488e53 100644 --- a/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go +++ b/internal/cmd/ske/credentials/complete-rotation/complete_rotation.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("complete-rotation %s", clusterNameArg), Short: "Completes the rotation of the credentials associated to a SKE cluster", @@ -62,14 +62,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to complete the rotation of the credentials for SKE cluster %q?", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -84,7 +84,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Completing credentials rotation") _, err = wait.CompleteCredentialsRotationWaitHandler(ctx, apiClient, model.ProjectId, model.ClusterName).WaitWithContext(ctx) if err != nil { @@ -97,8 +97,8 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered completion of credentials rotation" } - cmd.Printf("%s for cluster %q\n", operationState, model.ClusterName) - cmd.Printf("Consider updating your kubeconfig with the new credentials, create a new kubeconfig by running:\n $ stackit ske kubeconfig create %s\n", model.ClusterName) + p.Info("%s for cluster %q\n", operationState, model.ClusterName) + p.Warn("Consider updating your kubeconfig with the new credentials, create a new kubeconfig by running:\n $ stackit ske kubeconfig create %s\n", model.ClusterName) return nil }, } diff --git a/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go b/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go index 42bc1e71e..d90046e38 100644 --- a/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go +++ b/internal/cmd/ske/credentials/complete-rotation/complete_rotation_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/credentials/credentials.go b/internal/cmd/ske/credentials/credentials.go index 96c2f0d49..9d421ad7d 100644 --- a/internal/cmd/ske/credentials/credentials.go +++ b/internal/cmd/ske/credentials/credentials.go @@ -6,12 +6,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/ske/credentials/rotate" startrotation "github.com/stackitcloud/stackit-cli/internal/cmd/ske/credentials/start-rotation" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "credentials", Short: "Provides functionality for SKE credentials", @@ -19,13 +20,13 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(rotate.NewCmd()) - cmd.AddCommand(startrotation.NewCmd()) - cmd.AddCommand(completerotation.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(rotate.NewCmd(p)) + cmd.AddCommand(startrotation.NewCmd(p)) + cmd.AddCommand(completerotation.NewCmd(p)) } diff --git a/internal/cmd/ske/credentials/describe/describe.go b/internal/cmd/ske/credentials/describe/describe.go index 84c683a11..e53a8ca67 100644 --- a/internal/cmd/ske/credentials/describe/describe.go +++ b/internal/cmd/ske/credentials/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -26,7 +27,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("describe %s", clusterNameArg), Short: "Shows details of the credentials associated to a SKE cluster", @@ -54,7 +55,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -75,7 +76,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get SKE credentials: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -100,14 +101,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, credentials *ske.Credentials) error { +func outputResult(p *print.Printer, outputFormat string, credentials *ske.Credentials) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() table.AddRow("SERVER", *credentials.Server) table.AddSeparator() table.AddRow("TOKEN", *credentials.Token) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -118,7 +119,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, credentials *ske.Cred if err != nil { return fmt.Errorf("marshal SKE credentials: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/ske/credentials/describe/describe_test.go b/internal/cmd/ske/credentials/describe/describe_test.go index 4ce8e45f4..35dc8b801 100644 --- a/internal/cmd/ske/credentials/describe/describe_test.go +++ b/internal/cmd/ske/credentials/describe/describe_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/credentials/rotate/rotate.go b/internal/cmd/ske/credentials/rotate/rotate.go index 57b3c8a36..652349336 100644 --- a/internal/cmd/ske/credentials/rotate/rotate.go +++ b/internal/cmd/ske/credentials/rotate/rotate.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("rotate %s", clusterNameArg), Short: "Rotates credentials associated to a SKE cluster", @@ -52,14 +52,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to rotate credentials for SKE cluster %q? (The old credentials will be invalid after this operation)", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -74,7 +74,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Rotating credentials") _, err = wait.RotateCredentialsWaitHandler(ctx, apiClient, model.ProjectId, model.ClusterName).WaitWithContext(ctx) if err != nil { @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered rotation of" } - cmd.Printf("%s credentials for cluster %q\n", operationState, model.ClusterName) + p.Info("%s credentials for cluster %q\n", operationState, model.ClusterName) return nil }, } diff --git a/internal/cmd/ske/credentials/rotate/rotate_test.go b/internal/cmd/ske/credentials/rotate/rotate_test.go index aee433373..e7d5713be 100644 --- a/internal/cmd/ske/credentials/rotate/rotate_test.go +++ b/internal/cmd/ske/credentials/rotate/rotate_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/credentials/start-rotation/start_rotation.go b/internal/cmd/ske/credentials/start-rotation/start_rotation.go index da9b0cb91..154f15468 100644 --- a/internal/cmd/ske/credentials/start-rotation/start_rotation.go +++ b/internal/cmd/ske/credentials/start-rotation/start_rotation.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -26,7 +26,7 @@ type inputModel struct { ClusterName string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("start-rotation %s", clusterNameArg), Short: "Starts the rotation of the credentials associated to a SKE cluster", @@ -65,14 +65,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to start the rotation of the credentials for SKE cluster %q?", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -87,7 +87,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Starting credentials rotation") _, err = wait.StartCredentialsRotationWaitHandler(ctx, apiClient, model.ProjectId, model.ClusterName).WaitWithContext(ctx) if err != nil { @@ -100,8 +100,8 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered start of credentials rotation" } - cmd.Printf("%s for cluster %q\n", operationState, model.ClusterName) - cmd.Printf("Complete the rotation by running:\n $ stackit ske credentials complete-rotation %s\n", model.ClusterName) + p.Info("%s for cluster %q\n", operationState, model.ClusterName) + p.Info("Complete the rotation by running:\n $ stackit ske credentials complete-rotation %s\n", model.ClusterName) return nil }, } diff --git a/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go b/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go index 9960008d4..763fb93b2 100644 --- a/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go +++ b/internal/cmd/ske/credentials/start-rotation/start_rotation_test.go @@ -45,6 +45,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -123,7 +124,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/describe/describe.go b/internal/cmd/ske/describe/describe.go index 5fd32a095..5daff4193 100644 --- a/internal/cmd/ske/describe/describe.go +++ b/internal/cmd/ske/describe/describe.go @@ -9,6 +9,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -20,7 +21,7 @@ type inputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "describe", Short: "Shows overall details regarding SKE", @@ -38,7 +39,7 @@ func NewCmd() *cobra.Command { return err } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -50,7 +51,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("read SKE project details: %w", err) } - return outputResult(cmd, model.OutputFormat, resp) + return outputResult(p, model.OutputFormat, resp) }, } return cmd @@ -72,14 +73,14 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *ske.APIClie return req } -func outputResult(cmd *cobra.Command, outputFormat string, project *ske.ProjectResponse) error { +func outputResult(p *print.Printer, outputFormat string, project *ske.ProjectResponse) error { switch outputFormat { case globalflags.PrettyOutputFormat: table := tables.NewTable() table.AddRow("ID", *project.ProjectId) table.AddSeparator() table.AddRow("STATE", *project.State) - err := table.Display(cmd) + err := table.Display(p) if err != nil { return fmt.Errorf("render table: %w", err) } @@ -90,7 +91,7 @@ func outputResult(cmd *cobra.Command, outputFormat string, project *ske.ProjectR if err != nil { return fmt.Errorf("marshal SKE project details: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil } diff --git a/internal/cmd/ske/describe/describe_test.go b/internal/cmd/ske/describe/describe_test.go index 590762946..9f2407d44 100644 --- a/internal/cmd/ske/describe/describe_test.go +++ b/internal/cmd/ske/describe/describe_test.go @@ -35,6 +35,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/ske/disable/disable.go b/internal/cmd/ske/disable/disable.go index 3986b4e64..4001ad275 100644 --- a/internal/cmd/ske/disable/disable.go +++ b/internal/cmd/ske/disable/disable.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -22,7 +22,7 @@ type InputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "disable", Short: "Disables SKE for a project", @@ -41,19 +41,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to disable SKE for project %q? (This will delete all associated clusters)", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Disabling SKE") _, err = wait.DisableServiceWaitHandler(ctx, apiClient, model.ProjectId).WaitWithContext(ctx) if err != nil { @@ -81,7 +81,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered disablement of" } - cmd.Printf("%s SKE for project %q\n", operationState, projectLabel) + p.Info("%s SKE for project %q\n", operationState, projectLabel) return nil }, } diff --git a/internal/cmd/ske/disable/disable_test.go b/internal/cmd/ske/disable/disable_test.go index 51575b825..1d2831e0d 100644 --- a/internal/cmd/ske/disable/disable_test.go +++ b/internal/cmd/ske/disable/disable_test.go @@ -35,6 +35,7 @@ func fixtureInputModel(mods ...func(model *InputModel)) *InputModel { model := &InputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/ske/enable/enable.go b/internal/cmd/ske/enable/enable.go index 8a576e0ea..74b0cbd37 100644 --- a/internal/cmd/ske/enable/enable.go +++ b/internal/cmd/ske/enable/enable.go @@ -5,10 +5,10 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/projectname" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/spinner" @@ -22,7 +22,7 @@ type InputModel struct { *globalflags.GlobalFlagModel } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "enable", Short: "Enables SKE for a project", @@ -41,19 +41,19 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } - projectLabel, err := projectname.GetProjectName(ctx, cmd) + projectLabel, err := projectname.GetProjectName(ctx, cmd, p) if err != nil { projectLabel = model.ProjectId } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to enable SKE for project %q?", projectLabel) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -68,7 +68,7 @@ func NewCmd() *cobra.Command { // Wait for async operation, if async mode not enabled if !model.Async { - s := spinner.New(cmd) + s := spinner.New(p) s.Start("Enabling SKE") _, err = wait.EnableServiceWaitHandler(ctx, apiClient, model.ProjectId).WaitWithContext(ctx) if err != nil { @@ -81,7 +81,7 @@ func NewCmd() *cobra.Command { if model.Async { operationState = "Triggered enablement of" } - cmd.Printf("%s SKE for project %q\n", operationState, projectLabel) + p.Info("%s SKE for project %q\n", operationState, projectLabel) return nil }, } diff --git a/internal/cmd/ske/enable/enable_test.go b/internal/cmd/ske/enable/enable_test.go index a6755f27c..57505d7a0 100644 --- a/internal/cmd/ske/enable/enable_test.go +++ b/internal/cmd/ske/enable/enable_test.go @@ -35,6 +35,7 @@ func fixtureInputModel(mods ...func(model *InputModel)) *InputModel { model := &InputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, } for _, mod := range mods { diff --git a/internal/cmd/ske/kubeconfig/create/create.go b/internal/cmd/ske/kubeconfig/create/create.go index 6308a729a..ed4eee242 100644 --- a/internal/cmd/ske/kubeconfig/create/create.go +++ b/internal/cmd/ske/kubeconfig/create/create.go @@ -5,11 +5,11 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/args" - "github.com/stackitcloud/stackit-cli/internal/pkg/confirm" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" "github.com/stackitcloud/stackit-cli/internal/pkg/examples" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" skeUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/utils" @@ -31,7 +31,7 @@ type inputModel struct { ExpirationTime *string } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: fmt.Sprintf("create %s", clusterNameArg), Short: "Creates a kubeconfig for an SKE cluster", @@ -64,14 +64,14 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } if !model.AssumeYes { prompt := fmt.Sprintf("Are you sure you want to create a kubeconfig for SKE cluster %q? This will OVERWRITE your current kubeconfig file, if it exists.", model.ClusterName) - err = confirm.PromptForConfirmation(cmd, prompt) + err = p.PromptForConfirmation(prompt) if err != nil { return err } @@ -107,7 +107,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("write kubeconfig file: %w", err) } - fmt.Printf("Created kubeconfig file for cluster %s in %q, with expiration date %v (UTC)\n", model.ClusterName, kubeconfigPath, *resp.ExpirationTimestamp) + p.Outputf("Created kubeconfig file for cluster %s in %q, with expiration date %v (UTC)\n", model.ClusterName, kubeconfigPath, *resp.ExpirationTimestamp) return nil }, diff --git a/internal/cmd/ske/kubeconfig/create/create_test.go b/internal/cmd/ske/kubeconfig/create/create_test.go index ec907dbd3..6326ed3b3 100644 --- a/internal/cmd/ske/kubeconfig/create/create_test.go +++ b/internal/cmd/ske/kubeconfig/create/create_test.go @@ -46,6 +46,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ GlobalFlagModel: &globalflags.GlobalFlagModel{ ProjectId: testProjectId, + Verbosity: globalflags.VerbosityDefault, }, ClusterName: testClusterName, } @@ -148,7 +149,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/kubeconfig/kubeconfig.go b/internal/cmd/ske/kubeconfig/kubeconfig.go index 5411cd0a2..3370a8529 100644 --- a/internal/cmd/ske/kubeconfig/kubeconfig.go +++ b/internal/cmd/ske/kubeconfig/kubeconfig.go @@ -3,12 +3,13 @@ package kubeconfig import ( "github.com/stackitcloud/stackit-cli/internal/cmd/ske/kubeconfig/create" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "kubeconfig", Short: "Provides functionality for SKE kubeconfig", @@ -16,10 +17,10 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(create.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(create.NewCmd(p)) } diff --git a/internal/cmd/ske/options/options.go b/internal/cmd/ske/options/options.go index a68917298..57e02c19f 100644 --- a/internal/cmd/ske/options/options.go +++ b/internal/cmd/ske/options/options.go @@ -11,6 +11,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" "github.com/stackitcloud/stackit-cli/internal/pkg/pager" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/ske/client" "github.com/stackitcloud/stackit-cli/internal/pkg/tables" @@ -35,7 +36,7 @@ type inputModel struct { VolumeTypes bool } -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "options", Short: "Lists SKE provider options", @@ -63,7 +64,7 @@ func NewCmd() *cobra.Command { } // Configure API client - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return err } @@ -75,7 +76,7 @@ func NewCmd() *cobra.Command { return fmt.Errorf("get SKE provider options: %w", err) } - return outputResult(cmd, model, resp) + return outputResult(p, model, resp) }, } configureFlags(cmd) @@ -122,21 +123,21 @@ func buildRequest(ctx context.Context, apiClient *ske.APIClient) ske.ApiListProv return req } -func outputResult(cmd *cobra.Command, model *inputModel, options *ske.ProviderOptions) error { +func outputResult(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error { switch model.OutputFormat { case globalflags.JSONOutputFormat: details, err := json.MarshalIndent(options, "", " ") if err != nil { return fmt.Errorf("marshal SKE options: %w", err) } - cmd.Println(string(details)) + p.Outputln(string(details)) return nil default: - return outputResultAsTable(cmd, model, options) + return outputResultAsTable(p, model, options) } } -func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *ske.ProviderOptions) error { +func outputResultAsTable(p *print.Printer, model *inputModel, options *ske.ProviderOptions) error { content := "" if model.AvailabilityZones { content += renderAvailabilityZones(options) @@ -158,7 +159,7 @@ func outputResultAsTable(cmd *cobra.Command, model *inputModel, options *ske.Pro content += renderVolumeTypes(options) } - err := pager.Display(cmd, content) + err := pager.Display(p, content) if err != nil { return fmt.Errorf("display output: %w", err) } diff --git a/internal/cmd/ske/options/options_test.go b/internal/cmd/ske/options/options_test.go index 080cbf96e..05b1a50e0 100644 --- a/internal/cmd/ske/options/options_test.go +++ b/internal/cmd/ske/options/options_test.go @@ -32,7 +32,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, AvailabilityZones: false, KubernetesVersions: false, MachineImages: false, @@ -47,7 +47,7 @@ func fixtureInputModelAllFalse(mods ...func(model *inputModel)) *inputModel { func fixtureInputModelAllTrue(mods ...func(model *inputModel)) *inputModel { model := &inputModel{ - GlobalFlagModel: &globalflags.GlobalFlagModel{}, + GlobalFlagModel: &globalflags.GlobalFlagModel{Verbosity: globalflags.VerbosityDefault}, AvailabilityZones: true, KubernetesVersions: true, MachineImages: true, @@ -116,7 +116,7 @@ func TestParseInput(t *testing.T) { for _, tt := range tests { t.Run(tt.description, func(t *testing.T) { - cmd := NewCmd() + cmd := NewCmd(nil) err := globalflags.Configure(cmd.Flags()) if err != nil { t.Fatalf("configure global flags: %v", err) diff --git a/internal/cmd/ske/ske.go b/internal/cmd/ske/ske.go index 32a40662c..04438af65 100644 --- a/internal/cmd/ske/ske.go +++ b/internal/cmd/ske/ske.go @@ -9,12 +9,13 @@ import ( "github.com/stackitcloud/stackit-cli/internal/cmd/ske/kubeconfig" "github.com/stackitcloud/stackit-cli/internal/cmd/ske/options" "github.com/stackitcloud/stackit-cli/internal/pkg/args" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/utils" "github.com/spf13/cobra" ) -func NewCmd() *cobra.Command { +func NewCmd(p *print.Printer) *cobra.Command { cmd := &cobra.Command{ Use: "ske", Short: "Provides functionality for SKE", @@ -22,16 +23,16 @@ func NewCmd() *cobra.Command { Args: args.NoArgs, Run: utils.CmdHelp, } - addSubcommands(cmd) + addSubcommands(cmd, p) return cmd } -func addSubcommands(cmd *cobra.Command) { - cmd.AddCommand(describe.NewCmd()) - cmd.AddCommand(enable.NewCmd()) - cmd.AddCommand(kubeconfig.NewCmd()) - cmd.AddCommand(disable.NewCmd()) - cmd.AddCommand(cluster.NewCmd()) - cmd.AddCommand(credentials.NewCmd()) - cmd.AddCommand(options.NewCmd()) +func addSubcommands(cmd *cobra.Command, p *print.Printer) { + cmd.AddCommand(describe.NewCmd(p)) + cmd.AddCommand(enable.NewCmd(p)) + cmd.AddCommand(kubeconfig.NewCmd(p)) + cmd.AddCommand(disable.NewCmd(p)) + cmd.AddCommand(cluster.NewCmd(p)) + cmd.AddCommand(credentials.NewCmd(p)) + cmd.AddCommand(options.NewCmd(p)) } diff --git a/internal/pkg/auth/auth.go b/internal/pkg/auth/auth.go index 08e5a3fd4..c7372599c 100644 --- a/internal/pkg/auth/auth.go +++ b/internal/pkg/auth/auth.go @@ -6,9 +6,9 @@ import ( "time" "github.com/stackitcloud/stackit-cli/internal/pkg/config" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/golang-jwt/jwt/v5" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" ) @@ -22,7 +22,7 @@ type tokenClaims struct { // It returns the configuration option that can be used to create an authenticated SDK client. // // If the user was logged in and the user session expired, reauthorizeUserRoutine is called to reauthenticate the user again. -func AuthenticationConfig(cmd *cobra.Command, reauthorizeUserRoutine func() error) (authCfgOption sdkConfig.ConfigurationOption, err error) { +func AuthenticationConfig(p *print.Printer, reauthorizeUserRoutine func() error) (authCfgOption sdkConfig.ConfigurationOption, err error) { flow, err := GetAuthFlow() if err != nil { return nil, fmt.Errorf("get authentication flow: %w", err) @@ -57,13 +57,13 @@ func AuthenticationConfig(cmd *cobra.Command, reauthorizeUserRoutine func() erro authCfgOption = sdkConfig.WithCustomAuth(keyFlow) case AUTH_FLOW_USER_TOKEN: if userSessionExpired { - cmd.Println("Session expired, logging in again...") + p.Warn("Session expired, logging in again...\n") err = reauthorizeUserRoutine() if err != nil { return nil, fmt.Errorf("user login: %w", err) } } - userTokenFlow := UserTokenFlow(cmd) + userTokenFlow := UserTokenFlow(p) authCfgOption = sdkConfig.WithCustomAuth(userTokenFlow) default: return nil, fmt.Errorf("the provided authentication flow (%s) is not supported", flow) diff --git a/internal/pkg/auth/auth_test.go b/internal/pkg/auth/auth_test.go index 21b2867a3..18e61b158 100644 --- a/internal/pkg/auth/auth_test.go +++ b/internal/pkg/auth/auth_test.go @@ -15,6 +15,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/google/uuid" "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-sdk-go/core/clients" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/zalando/go-keyring" @@ -201,8 +202,9 @@ func TestAuthenticationConfig(t *testing.T) { cmd := &cobra.Command{} cmd.SetOut(io.Discard) // Suppresses console prints + p := &print.Printer{Cmd: cmd} - authCfgOption, err := AuthenticationConfig(cmd, reauthenticateUser) + authCfgOption, err := AuthenticationConfig(p, reauthenticateUser) if !tt.isValid { if err == nil { diff --git a/internal/pkg/auth/service_account.go b/internal/pkg/auth/service_account.go index be5e749c5..f04d0f388 100644 --- a/internal/pkg/auth/service_account.go +++ b/internal/pkg/auth/service_account.go @@ -6,6 +6,7 @@ import ( "net/http" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-sdk-go/core/clients" ) @@ -34,7 +35,7 @@ var _ http.RoundTripper = &keyFlowWithStorage{} // For the key flow, it fetches an access and refresh token from the Service Account API. // For the token flow, it just stores the provided token and doesn't check if it is valid. // It returns the email associated with the service account -func AuthenticateServiceAccount(rt http.RoundTripper) (email string, err error) { +func AuthenticateServiceAccount(p *print.Printer, rt http.RoundTripper) (email string, err error) { authFields := make(map[authFieldKey]string) var authFlowType AuthFlow switch flow := rt.(type) { @@ -43,6 +44,7 @@ func AuthenticateServiceAccount(rt http.RoundTripper) (email string, err error) accessToken, err := flow.GetAccessToken() if err != nil { + p.Debug(print.ErrorLevel, "get access token: %v", err) return "", &errors.ActivateServiceAccountError{} } serviceAccountKey := flow.GetConfig().ServiceAccountKey diff --git a/internal/pkg/auth/service_account_test.go b/internal/pkg/auth/service_account_test.go index 75251550a..a4b3a72ce 100644 --- a/internal/pkg/auth/service_account_test.go +++ b/internal/pkg/auth/service_account_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/stackitcloud/stackit-cli/internal/pkg/config" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/golang-jwt/jwt/v5" "github.com/stackitcloud/stackit-sdk-go/core/clients" @@ -151,7 +152,8 @@ func TestAuthenticateServiceAccount(t *testing.T) { flow = &http.Transport{} } - email, err := AuthenticateServiceAccount(flow) + p := print.NewPrinter() + email, err := AuthenticateServiceAccount(p, flow) if !tt.isValid { if err == nil { diff --git a/internal/pkg/auth/user_token_flow.go b/internal/pkg/auth/user_token_flow.go index dfbf77f7d..6c8ee0305 100644 --- a/internal/pkg/auth/user_token_flow.go +++ b/internal/pkg/auth/user_token_flow.go @@ -9,11 +9,11 @@ import ( "time" "github.com/golang-jwt/jwt/v5" - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" ) type userTokenFlow struct { - cmd *cobra.Command + printer *print.Printer reauthorizeUserRoutine func() error // Called if the user needs to login again client *http.Client authFlow AuthFlow @@ -25,9 +25,9 @@ type userTokenFlow struct { var _ http.RoundTripper = &userTokenFlow{} // Returns a round tripper that adds authentication according to the user token flow -func UserTokenFlow(cmd *cobra.Command) *userTokenFlow { +func UserTokenFlow(p *print.Printer) *userTokenFlow { return &userTokenFlow{ - cmd: cmd, + printer: p, reauthorizeUserRoutine: AuthorizeUser, client: &http.Client{}, } @@ -57,7 +57,7 @@ func (utf *userTokenFlow) RoundTrip(req *http.Request) (*http.Response, error) { } if !accessTokenValid { - utf.cmd.Println("Session expired, logging in again...") + utf.printer.Warn("Session expired, logging in again...") err = reauthenticateUser(utf) if err != nil { return nil, fmt.Errorf("reauthenticate user: %w", err) diff --git a/internal/pkg/auth/user_token_flow_test.go b/internal/pkg/auth/user_token_flow_test.go index 34192c071..66831292f 100644 --- a/internal/pkg/auth/user_token_flow_test.go +++ b/internal/pkg/auth/user_token_flow_test.go @@ -10,6 +10,7 @@ import ( "github.com/golang-jwt/jwt/v5" "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/zalando/go-keyring" ) @@ -277,9 +278,11 @@ func TestRoundTrip(t *testing.T) { cmd := &cobra.Command{} cmd.SetOut(io.Discard) // Suppresses console prints + p := &print.Printer{Cmd: cmd} + // Test RoundTripper rt := userTokenFlow{ - cmd: cmd, + printer: p, reauthorizeUserRoutine: authorizeUserRoutine, client: client, } diff --git a/internal/pkg/config/config.go b/internal/pkg/config/config.go index d5fb213b9..08eac0b98 100644 --- a/internal/pkg/config/config.go +++ b/internal/pkg/config/config.go @@ -15,6 +15,7 @@ const ( OutputFormatKey = "output_format" ProjectIdKey = "project_id" SessionTimeLimitKey = "session_time_limit" + VerbosityKey = "verbosity" ArgusCustomEndpointKey = "argus_custom_endpoint" AuthorizationCustomEndpointKey = "authorization_custom_endpoint" @@ -49,6 +50,7 @@ var ConfigKeys = []string{ OutputFormatKey, ProjectIdKey, SessionTimeLimitKey, + VerbosityKey, DNSCustomEndpointKey, LogMeCustomEndpointKey, diff --git a/internal/pkg/confirm/confirm.go b/internal/pkg/confirm/confirm.go deleted file mode 100644 index 99a2f2f96..000000000 --- a/internal/pkg/confirm/confirm.go +++ /dev/null @@ -1,36 +0,0 @@ -package confirm - -import ( - "bufio" - "errors" - "fmt" - "strings" - - "github.com/spf13/cobra" -) - -var errAborted = errors.New("operation aborted") - -// Prompts the user for confirmation. -// -// Returns nil only if the user (explicitly) answers positive. -// Returns ErrAborted if the user answers negative. -func PromptForConfirmation(cmd *cobra.Command, prompt string) error { - question := fmt.Sprintf("%s [y/N] ", prompt) - reader := bufio.NewReader(cmd.InOrStdin()) - for i := 0; i < 3; i++ { - cmd.Print(question) - answer, err := reader.ReadString('\n') - if err != nil { - continue - } - answer = strings.ToLower(strings.TrimSpace(answer)) - if answer == "y" || answer == "yes" { - return nil - } - if answer == "" || answer == "n" || answer == "no" { - return errAborted - } - } - return fmt.Errorf("max number of wrong inputs") -} diff --git a/internal/pkg/confirm/confirm_test.go b/internal/pkg/confirm/confirm_test.go deleted file mode 100644 index 84f792952..000000000 --- a/internal/pkg/confirm/confirm_test.go +++ /dev/null @@ -1,165 +0,0 @@ -package confirm - -import ( - "bytes" - "errors" - "io" - "testing" - - "github.com/spf13/cobra" -) - -func TestPromptForConfirmation(t *testing.T) { - tests := []struct { - description string - input string - isValid bool - isAborted bool - }{ - // Note: Some of these inputs have normal spaces, others have tabs - { - description: "yes - simple 1", - input: "y\n", - isValid: true, - }, - { - description: "yes - simple 2", - input: " Y \r\n", - isValid: true, - }, - { - description: "yes - simple 3", - input: " yes\n", - isValid: true, - }, - { - description: "yes - simple 4", - input: "YES\n", - isValid: true, - }, - { - description: "yes - retries 1", - input: "yrs\nyes\n", - isValid: true, - }, - { - description: "yes - retries 2", - input: "foo\nbar \n y\n", - isValid: true, - }, - { - description: "yes - retries 3", - input: "foo\r\nbar \nY \n", - isValid: true, - }, - { - description: "no - simple 1", - input: "n\n", - isValid: false, - isAborted: true, - }, - { - description: "no - simple 2", - input: " N \r\n", - isValid: false, - isAborted: true, - }, - { - description: "no - simple 3", - input: "no\n", - isValid: false, - isAborted: true, - }, - { - description: "no - simple 4", - input: " \n", - isValid: false, - isAborted: true, - }, - { - description: "no - simple 5", - input: " \r\n", - isValid: false, - isAborted: true, - }, - { - description: "no - retries 1", - input: "ni\n no \n", - isValid: false, - isAborted: true, - }, - { - description: "no - retries 2", - input: "foo\nbar\nn\n", - isValid: false, - isAborted: true, - }, - { - description: "no - retries 3", - input: "foo\r\nbar\nN\n", - isValid: false, - isAborted: true, - }, - { - description: "no - retries 4", - input: "m\n \n", - isValid: false, - isAborted: true, - }, - { - description: "no - retries 5", - input: "m\r\n \r\n", - isValid: false, - isAborted: true, - }, - { - description: "max retries 1", - input: "foo\nbar\nbaz\n", - isValid: false, - }, - { - description: "max retries 2", - input: "foo\r\nbar\r\nbaz\r\n", - isValid: false, - }, - { - description: "max retries 3", - input: "foo\nbar\nbaz\ny\n", - isValid: false, - }, - { - description: "no input", - input: "", - isValid: false, - }, - } - - for _, tt := range tests { - t.Run(tt.description, func(t *testing.T) { - buffer := &bytes.Buffer{} - _, err := buffer.WriteString(tt.input) - if err != nil { - t.Fatalf("failed to initialize mock input: %v", err) - } - - cmd := &cobra.Command{} - cmd.SetOut(io.Discard) // Suppresses console prints - cmd.SetIn(buffer) - - err = PromptForConfirmation(cmd, "") - - if tt.isValid && err != nil { - t.Errorf("should not have failed: %v", err) - } - if !tt.isValid && err == nil { - t.Errorf("should have failed") - } - if tt.isAborted && !errors.Is(err, errAborted) { - t.Errorf("should have returned aborted error, instead returned: %v", err) - } - if !tt.isAborted && errors.Is(err, errAborted) { - t.Errorf("should not have returned aborted error") - } - }) - } -} diff --git a/internal/pkg/globalflags/global_flags.go b/internal/pkg/globalflags/global_flags.go index 144033314..6a6aef335 100644 --- a/internal/pkg/globalflags/global_flags.go +++ b/internal/pkg/globalflags/global_flags.go @@ -5,6 +5,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -16,18 +17,28 @@ const ( AssumeYesFlag = "assume-yes" OutputFormatFlag = "output-format" ProjectIdFlag = "project-id" + VerbosityFlag = "verbosity" JSONOutputFormat = "json" PrettyOutputFormat = "pretty" + + DebugVerbosity = string(print.DebugLevel) + InfoVerbosity = string(print.InfoLevel) + WarningVerbosity = string(print.WarningLevel) + ErrorVerbosity = string(print.ErrorLevel) + + VerbosityDefault = InfoVerbosity ) var outputFormatFlagOptions = []string{JSONOutputFormat, PrettyOutputFormat} +var verbosityFlagOptions = []string{DebugVerbosity, InfoVerbosity, WarningVerbosity, ErrorVerbosity} type GlobalFlagModel struct { Async bool AssumeYes bool OutputFormat string ProjectId string + Verbosity string } func Configure(flagSet *pflag.FlagSet) error { @@ -50,6 +61,13 @@ func Configure(flagSet *pflag.FlagSet) error { } flagSet.BoolP(AssumeYesFlag, "y", false, "If set, skips all confirmation prompts") + + flagSet.Var(flags.EnumFlag(true, VerbosityDefault, verbosityFlagOptions...), VerbosityFlag, fmt.Sprintf("Verbosity of the CLI, one of %q", verbosityFlagOptions)) + err = viper.BindPFlag(config.VerbosityKey, flagSet.Lookup(VerbosityFlag)) + if err != nil { + return fmt.Errorf("bind --%s flag to config: %w", VerbosityFlag, err) + } + return nil } @@ -59,5 +77,6 @@ func Parse(cmd *cobra.Command) *GlobalFlagModel { AssumeYes: flags.FlagToBoolValue(cmd, AssumeYesFlag), OutputFormat: viper.GetString(config.OutputFormatKey), ProjectId: viper.GetString(config.ProjectIdKey), + Verbosity: viper.GetString(config.VerbosityKey), } } diff --git a/internal/pkg/pager/pager.go b/internal/pkg/pager/pager.go index 401f95080..b3b89104c 100644 --- a/internal/pkg/pager/pager.go +++ b/internal/pkg/pager/pager.go @@ -5,14 +5,14 @@ import ( "os/exec" "strings" - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" ) // Shows the content in the command's stdout using the "less" command -func Display(cmd *cobra.Command, content string) error { +func Display(p *print.Printer, content string) error { lessCmd := exec.Command("less", "-F", "-S", "-w") lessCmd.Stdin = strings.NewReader(content) - lessCmd.Stdout = cmd.OutOrStdout() + lessCmd.Stdout = p.Cmd.OutOrStdout() err := lessCmd.Run() if err != nil { diff --git a/internal/pkg/print/print.go b/internal/pkg/print/print.go new file mode 100644 index 000000000..7cf7b0571 --- /dev/null +++ b/internal/pkg/print/print.go @@ -0,0 +1,113 @@ +package print + +import ( + "bufio" + "errors" + "fmt" + "log/slog" + "os" + "strings" + + "github.com/spf13/cobra" +) + +type Level string + +const ( + DebugLevel Level = "debug" + InfoLevel Level = "info" + WarningLevel Level = "warning" + ErrorLevel Level = "error" +) + +var errAborted = errors.New("operation aborted") + +type Printer struct { + Cmd *cobra.Command + Verbosity Level +} + +// Creates a new printer, including setting up the default logger. +func NewPrinter() *Printer { + logger := slog.New(slog.NewTextHandler(os.Stderr, &slog.HandlerOptions{AddSource: true, Level: slog.LevelDebug})) + slog.SetDefault(logger) + + return &Printer{} +} + +// Print an output using Printf to the defined output (falling back to Stderr if not set). +func (p *Printer) Outputf(msg string, args ...any) { + p.Cmd.Printf(msg, args...) +} + +// Print an output using Println to the defined output (falling back to Stderr if not set). +func (p *Printer) Outputln(msg string) { + p.Cmd.Println(msg) +} + +// Print a Debug level log through the "slog" package. +// If the verbosity level is not Debug, it does nothing +func (p *Printer) Debug(level Level, msg string, args ...any) { + if p.Verbosity != DebugLevel { + return + } + switch level { + case DebugLevel: + slog.Debug(msg, args...) + case InfoLevel: + slog.Info(msg, args...) + case WarningLevel: + slog.Warn(msg, args...) + case ErrorLevel: + slog.Error(msg, args...) + } +} + +// Print an Info level output to the defined Err output (falling back to Stderr if not set). +// If the verbosity level is not Debug or Info, it does nothing. +func (p *Printer) Info(msg string, args ...any) { + if p.Verbosity != DebugLevel && p.Verbosity != InfoLevel { + return + } + p.Cmd.PrintErrf(msg, args...) +} + +// Print a Warn level output to the defined Err output (falling back to Stderr if not set). +// If the verbosity level is not Debug, Info, or Warn, it does nothing. +func (p *Printer) Warn(msg string, args ...any) { + if p.Verbosity != DebugLevel && p.Verbosity != InfoLevel && p.Verbosity != WarningLevel { + return + } + warning := fmt.Sprintf(msg, args...) + p.Cmd.PrintErrf("Warning: %s", warning) +} + +// Print an Error level output to the defined Err output (falling back to Stderr if not set). +func (p *Printer) Error(msg string, args ...any) { + err := fmt.Sprintf(msg, args...) + p.Cmd.PrintErrln(p.Cmd.ErrPrefix(), err) +} + +// Prompts the user for confirmation. +// +// Returns nil only if the user (explicitly) answers positive. +// Returns ErrAborted if the user answers negative. +func (p *Printer) PromptForConfirmation(prompt string) error { + question := fmt.Sprintf("%s [y/N] ", prompt) + reader := bufio.NewReader(p.Cmd.InOrStdin()) + for i := 0; i < 3; i++ { + p.Cmd.PrintErr(question) + answer, err := reader.ReadString('\n') + if err != nil { + continue + } + answer = strings.ToLower(strings.TrimSpace(answer)) + if answer == "y" || answer == "yes" { + return nil + } + if answer == "" || answer == "n" || answer == "no" { + return errAborted + } + } + return fmt.Errorf("max number of wrong inputs") +} diff --git a/internal/pkg/print/print_test.go b/internal/pkg/print/print_test.go new file mode 100644 index 000000000..ac277cc97 --- /dev/null +++ b/internal/pkg/print/print_test.go @@ -0,0 +1,580 @@ +package print + +import ( + "bytes" + "errors" + "fmt" + "io" + "log/slog" + "testing" + + "github.com/spf13/cobra" +) + +func TestOutputf(t *testing.T) { + tests := []struct { + description string + message string + args []any + verbosity Level + }{ + { + description: "debug verbosity", + message: "Test message", + verbosity: DebugLevel, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + }, + { + description: "info verbosity - with args", + message: "Test message with args: %s, %s", + args: []any{"arg1", "arg2"}, + verbosity: DebugLevel, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + if len(tt.args) == 0 { + p.Outputf(tt.message) + } else { + p.Outputf(tt.message, tt.args...) + } + + expectedOutput := tt.message + if len(tt.args) > 0 { + expectedOutput = fmt.Sprintf(tt.message, tt.args...) + } + output := buf.String() + if output != expectedOutput { + t.Errorf("unexpected output: got %q, want %q", output, expectedOutput) + } + }) + } +} + +func TestOutputln(t *testing.T) { + tests := []struct { + description string + message string + verbosity Level + }{ + { + description: "debug verbosity", + message: "Test message", + verbosity: DebugLevel, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + p.Outputln(tt.message) + + expectedOutput := fmt.Sprintf("%s\n", tt.message) + output := buf.String() + if output != expectedOutput { + t.Errorf("unexpected output: got %q, want %q", output, expectedOutput) + } + }) + } +} + +func TestDebug(t *testing.T) { + tests := []struct { + description string + message string + args []any + verbosity Level + expectsLog bool + logLevel Level + }{ + { + description: "debug verbosity - debug log", + message: "Test message", + verbosity: DebugLevel, + expectsLog: true, + logLevel: DebugLevel, + }, + { + description: "debug verbosity - info log", + message: "Test message", + verbosity: DebugLevel, + expectsLog: true, + logLevel: InfoLevel, + }, + { + description: "debug verbosity - warning log", + message: "Test message", + verbosity: DebugLevel, + expectsLog: true, + logLevel: WarningLevel, + }, + { + description: "debug verbosity - error log", + message: "Test message", + verbosity: DebugLevel, + expectsLog: true, + logLevel: ErrorLevel, + }, + { + description: "debug verbosity - error log with args", + message: "Test message", + args: []any{"arg1", "arg2"}, + verbosity: DebugLevel, + expectsLog: true, + logLevel: ErrorLevel, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + expectsLog: false, + logLevel: DebugLevel, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + expectsLog: false, + logLevel: DebugLevel, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + expectsLog: false, + logLevel: DebugLevel, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + logger := slog.New(slog.NewTextHandler(&buf, &slog.HandlerOptions{AddSource: true, Level: slog.LevelDebug})) + slog.SetDefault(logger) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + if len(tt.args) == 0 { + p.Debug(tt.logLevel, tt.message) + } + if len(tt.args) > 0 { + p.Debug(tt.logLevel, tt.message, tt.args...) + } + + output := buf.String() + // We only check if a log is printed, as the content of the log as fields that change such as the time + if tt.expectsLog && output == "" { + t.Errorf("expected a log but got none") + } + if !tt.expectsLog && output != "" { + t.Errorf("got log when it wasn't expected: got %q", output) + } + }) + } +} + +func TestInfo(t *testing.T) { + tests := []struct { + description string + message string + verbosity Level + shouldPrint bool + }{ + { + description: "debug verbosity", + message: "Test message", + verbosity: DebugLevel, + shouldPrint: true, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + shouldPrint: true, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + shouldPrint: false, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + shouldPrint: false, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + p.Info(tt.message) + + expectedOutput := tt.message + output := buf.String() + if tt.shouldPrint { + if output != expectedOutput { + t.Errorf("unexpected output: got %q, want %q", output, expectedOutput) + } + } else { + if output != "" { + t.Errorf("unexpected output: got %q, want %q", output, "") + } + } + }) + } +} + +func TestWarn(t *testing.T) { + tests := []struct { + description string + message string + verbosity Level + shouldPrint bool + }{ + { + description: "debug verbosity", + message: "Test message", + verbosity: DebugLevel, + shouldPrint: true, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + shouldPrint: true, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + shouldPrint: true, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + shouldPrint: false, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + p.Warn(tt.message) + + expectedOutput := fmt.Sprintf("Warning: %s", tt.message) + output := buf.String() + if tt.shouldPrint { + if output != expectedOutput { + t.Errorf("unexpected output: got %q, want %q", output, expectedOutput) + } + } else { + if output != "" { + t.Errorf("unexpected output: got %q, want %q", output, "") + } + } + }) + } +} + +func TestError(t *testing.T) { + tests := []struct { + description string + message string + verbosity Level + shouldPrint bool + }{ + { + description: "debug verbosity", + message: "Test message", + verbosity: DebugLevel, + shouldPrint: true, + }, + { + description: "info verbosity", + message: "Test message", + verbosity: InfoLevel, + shouldPrint: true, + }, + { + description: "warning verbosity", + message: "Test message", + verbosity: WarningLevel, + shouldPrint: true, + }, + { + description: "error verbosity", + message: "Test message", + verbosity: ErrorLevel, + shouldPrint: true, + }, + } + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + var buf bytes.Buffer + cmd := &cobra.Command{} + cmd.SetOutput(&buf) + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + p.Error(tt.message) + + expectedOutput := fmt.Sprintf("Error: %s\n", tt.message) + output := buf.String() + if tt.shouldPrint { + if output != expectedOutput { + t.Errorf("unexpected output: got %q, want %q", output, expectedOutput) + } + } else { + if output != "" { + t.Errorf("unexpected output: got %q, want %q", output, "") + } + } + }) + } +} + +func TestPromptForConfirmation(t *testing.T) { + tests := []struct { + description string + input string + verbosity Level + isValid bool + isAborted bool + }{ + // Note: Some of these inputs have normal spaces, others have tabs + { + description: "yes - simple 1", + input: "y\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - simple 2", + input: " Y \r\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - simple 3", + input: " yes\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - simple 4", + input: "YES\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - retries 1", + input: "yrs\nyes\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - retries 2", + input: "foo\nbar \n y\n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "yes - retries 3", + input: "foo\r\nbar \nY \n", + verbosity: DebugLevel, + isValid: true, + }, + { + description: "no - simple 1", + input: "n\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - simple 2", + input: " N \r\n", + isValid: false, + verbosity: DebugLevel, + isAborted: true, + }, + { + description: "no - simple 3", + input: "no\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - simple 4", + input: " \n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - simple 5", + input: " \r\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - retries 1", + input: "ni\n no \n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - retries 2", + input: "foo\nbar\nn\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - retries 3", + input: "foo\r\nbar\nN\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - retries 4", + input: "m\n \n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "no - retries 5", + input: "m\r\n \r\n", + verbosity: DebugLevel, + isValid: false, + isAborted: true, + }, + { + description: "max retries 1", + input: "foo\nbar\nbaz\n", + verbosity: DebugLevel, + isValid: false, + }, + { + description: "max retries 2", + input: "foo\r\nbar\r\nbaz\r\n", + verbosity: DebugLevel, + isValid: false, + }, + { + description: "max retries 3", + input: "foo\nbar\nbaz\ny\n", + verbosity: DebugLevel, + isValid: false, + }, + { + description: "no input", + input: "", + verbosity: DebugLevel, + isValid: false, + }, + } + + for _, tt := range tests { + t.Run(tt.description, func(t *testing.T) { + buffer := &bytes.Buffer{} + _, err := buffer.WriteString(tt.input) + if err != nil { + t.Fatalf("failed to initialize mock input: %v", err) + } + + cmd := &cobra.Command{} + cmd.SetOut(io.Discard) // Suppresses console prints + cmd.SetErr(io.Discard) + cmd.SetIn(buffer) + + p := &Printer{ + Cmd: cmd, + Verbosity: tt.verbosity, + } + + err = p.PromptForConfirmation("") + + if tt.isValid && err != nil { + t.Errorf("should not have failed: %v", err) + } + if !tt.isValid && err == nil { + t.Errorf("should have failed") + } + if tt.isAborted && !errors.Is(err, errAborted) { + t.Errorf("should have returned aborted error, instead returned: %v", err) + } + if !tt.isAborted && errors.Is(err, errAborted) { + t.Errorf("should not have returned aborted error") + } + }) + } +} diff --git a/internal/pkg/projectname/project_name.go b/internal/pkg/projectname/project_name.go index f80cbedd8..d2a54ff0a 100644 --- a/internal/pkg/projectname/project_name.go +++ b/internal/pkg/projectname/project_name.go @@ -7,6 +7,7 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/flags" "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/stackitcloud/stackit-cli/internal/pkg/services/resourcemanager/client" "github.com/spf13/cobra" @@ -16,7 +17,7 @@ import ( // Returns the project name associated to the project ID set in config // // Uses the one stored in config if it's valid, otherwise gets it from the API -func GetProjectName(ctx context.Context, cmd *cobra.Command) (string, error) { +func GetProjectName(ctx context.Context, cmd *cobra.Command, p *print.Printer) (string, error) { // If we can use the project name from config, return it if useProjectNameFromConfig(cmd) { return viper.GetString(config.ProjectNameKey), nil @@ -27,7 +28,7 @@ func GetProjectName(ctx context.Context, cmd *cobra.Command) (string, error) { return "", fmt.Errorf("found empty project ID and name") } - apiClient, err := client.ConfigureClient(cmd) + apiClient, err := client.ConfigureClient(p) if err != nil { return "", fmt.Errorf("configure resource manager client: %w", err) } diff --git a/internal/pkg/services/argus/client/client.go b/internal/pkg/services/argus/client/client.go index ebf90f114..44125b4ea 100644 --- a/internal/pkg/services/argus/client/client.go +++ b/internal/pkg/services/argus/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/argus" ) -func ConfigureClient(cmd *cobra.Command) (*argus.APIClient, error) { +func ConfigureClient(p *print.Printer) (*argus.APIClient, error) { var err error var apiClient *argus.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/authorization/client/client.go b/internal/pkg/services/authorization/client/client.go index 11e170a2f..41f268c94 100644 --- a/internal/pkg/services/authorization/client/client.go +++ b/internal/pkg/services/authorization/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/authorization" ) -func ConfigureClient(cmd *cobra.Command) (*authorization.APIClient, error) { +func ConfigureClient(p *print.Printer) (*authorization.APIClient, error) { var err error var apiClient *authorization.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/dns/client/client.go b/internal/pkg/services/dns/client/client.go index 4b0024c7f..9440f939c 100644 --- a/internal/pkg/services/dns/client/client.go +++ b/internal/pkg/services/dns/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/dns" ) -func ConfigureClient(cmd *cobra.Command) (*dns.APIClient, error) { +func ConfigureClient(p *print.Printer) (*dns.APIClient, error) { var err error var apiClient *dns.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/logme/client/client.go b/internal/pkg/services/logme/client/client.go index 5020ba1f4..d701f1b10 100644 --- a/internal/pkg/services/logme/client/client.go +++ b/internal/pkg/services/logme/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/logme" ) -func ConfigureClient(cmd *cobra.Command) (*logme.APIClient, error) { +func ConfigureClient(p *print.Printer) (*logme.APIClient, error) { var err error var apiClient *logme.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/mariadb/client/client.go b/internal/pkg/services/mariadb/client/client.go index dac6c2c5d..01baa5193 100644 --- a/internal/pkg/services/mariadb/client/client.go +++ b/internal/pkg/services/mariadb/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/mariadb" ) -func ConfigureClient(cmd *cobra.Command) (*mariadb.APIClient, error) { +func ConfigureClient(p *print.Printer) (*mariadb.APIClient, error) { var err error var apiClient *mariadb.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/mongodbflex/client/client.go b/internal/pkg/services/mongodbflex/client/client.go index 386c84a02..4291cf753 100644 --- a/internal/pkg/services/mongodbflex/client/client.go +++ b/internal/pkg/services/mongodbflex/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/mongodbflex" ) -func ConfigureClient(cmd *cobra.Command) (*mongodbflex.APIClient, error) { +func ConfigureClient(p *print.Printer) (*mongodbflex.APIClient, error) { var err error var apiClient *mongodbflex.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/object-storage/client/client.go b/internal/pkg/services/object-storage/client/client.go index 6091f08ab..8f7de8ed0 100644 --- a/internal/pkg/services/object-storage/client/client.go +++ b/internal/pkg/services/object-storage/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/objectstorage" ) -func ConfigureClient(cmd *cobra.Command) (*objectstorage.APIClient, error) { +func ConfigureClient(p *print.Printer) (*objectstorage.APIClient, error) { var err error var apiClient *objectstorage.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/opensearch/client/client.go b/internal/pkg/services/opensearch/client/client.go index 6f9852f56..f5679a88c 100644 --- a/internal/pkg/services/opensearch/client/client.go +++ b/internal/pkg/services/opensearch/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/opensearch" ) -func ConfigureClient(cmd *cobra.Command) (*opensearch.APIClient, error) { +func ConfigureClient(p *print.Printer) (*opensearch.APIClient, error) { var err error var apiClient *opensearch.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/postgresflex/client/client.go b/internal/pkg/services/postgresflex/client/client.go index 1fa8cfea7..c37181bf3 100644 --- a/internal/pkg/services/postgresflex/client/client.go +++ b/internal/pkg/services/postgresflex/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/postgresflex" ) -func ConfigureClient(cmd *cobra.Command) (*postgresflex.APIClient, error) { +func ConfigureClient(p *print.Printer) (*postgresflex.APIClient, error) { var err error var apiClient *postgresflex.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/rabbitmq/client/client.go b/internal/pkg/services/rabbitmq/client/client.go index c31b00f1c..84e9fa583 100644 --- a/internal/pkg/services/rabbitmq/client/client.go +++ b/internal/pkg/services/rabbitmq/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/rabbitmq" ) -func ConfigureClient(cmd *cobra.Command) (*rabbitmq.APIClient, error) { +func ConfigureClient(p *print.Printer) (*rabbitmq.APIClient, error) { var err error var apiClient *rabbitmq.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/redis/client/client.go b/internal/pkg/services/redis/client/client.go index ace824e1d..e376cd150 100644 --- a/internal/pkg/services/redis/client/client.go +++ b/internal/pkg/services/redis/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/redis" ) -func ConfigureClient(cmd *cobra.Command) (*redis.APIClient, error) { +func ConfigureClient(p *print.Printer) (*redis.APIClient, error) { var err error var apiClient *redis.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/resourcemanager/client/client.go b/internal/pkg/services/resourcemanager/client/client.go index ae2e0cc42..6e0158b07 100644 --- a/internal/pkg/services/resourcemanager/client/client.go +++ b/internal/pkg/services/resourcemanager/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/resourcemanager" ) -func ConfigureClient(cmd *cobra.Command) (*resourcemanager.APIClient, error) { +func ConfigureClient(p *print.Printer) (*resourcemanager.APIClient, error) { var err error var apiClient *resourcemanager.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/secrets-manager/client/client.go b/internal/pkg/services/secrets-manager/client/client.go index 5063cbd1e..712ead723 100644 --- a/internal/pkg/services/secrets-manager/client/client.go +++ b/internal/pkg/services/secrets-manager/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/secretsmanager" ) -func ConfigureClient(cmd *cobra.Command) (*secretsmanager.APIClient, error) { +func ConfigureClient(p *print.Printer) (*secretsmanager.APIClient, error) { var err error var apiClient *secretsmanager.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/service-account/client/client.go b/internal/pkg/services/service-account/client/client.go index 1346db23c..a348cc896 100644 --- a/internal/pkg/services/service-account/client/client.go +++ b/internal/pkg/services/service-account/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/serviceaccount" ) -func ConfigureClient(cmd *cobra.Command) (*serviceaccount.APIClient, error) { +func ConfigureClient(p *print.Printer) (*serviceaccount.APIClient, error) { var err error var apiClient *serviceaccount.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/services/ske/client/client.go b/internal/pkg/services/ske/client/client.go index a730c8328..4397cdba7 100644 --- a/internal/pkg/services/ske/client/client.go +++ b/internal/pkg/services/ske/client/client.go @@ -4,19 +4,19 @@ import ( "github.com/stackitcloud/stackit-cli/internal/pkg/auth" "github.com/stackitcloud/stackit-cli/internal/pkg/config" "github.com/stackitcloud/stackit-cli/internal/pkg/errors" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" - "github.com/spf13/cobra" "github.com/spf13/viper" sdkConfig "github.com/stackitcloud/stackit-sdk-go/core/config" "github.com/stackitcloud/stackit-sdk-go/services/ske" ) -func ConfigureClient(cmd *cobra.Command) (*ske.APIClient, error) { +func ConfigureClient(p *print.Printer) (*ske.APIClient, error) { var err error var apiClient *ske.APIClient var cfgOptions []sdkConfig.ConfigurationOption - authCfgOption, err := auth.AuthenticationConfig(cmd, auth.AuthorizeUser) + authCfgOption, err := auth.AuthenticationConfig(p, auth.AuthorizeUser) if err != nil { return nil, &errors.AuthError{} } diff --git a/internal/pkg/spinner/spinner.go b/internal/pkg/spinner/spinner.go index 8035fac2b..23635a44e 100644 --- a/internal/pkg/spinner/spinner.go +++ b/internal/pkg/spinner/spinner.go @@ -3,11 +3,11 @@ package spinner import ( "time" - "github.com/spf13/cobra" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" ) type Spinner struct { - cmd *cobra.Command + printer *print.Printer message string states []string startTime time.Time @@ -15,9 +15,9 @@ type Spinner struct { done chan bool } -func New(cmd *cobra.Command) *Spinner { +func New(p *print.Printer) *Spinner { return &Spinner{ - cmd: cmd, + printer: p, states: []string{"|", "/", "-", "\\"}, startTime: time.Now(), delay: 100 * time.Millisecond, @@ -33,7 +33,7 @@ func (s *Spinner) Start(message string) { func (s *Spinner) Stop() { s.done <- true close(s.done) - s.cmd.Printf("\r%s ✓ \n", s.message) + s.printer.Info("\r%s ✓ \n", s.message) } func (s *Spinner) animate() { @@ -43,7 +43,7 @@ func (s *Spinner) animate() { case <-s.done: return default: - s.cmd.Printf("\r%s %s ", s.message, s.states[i%len(s.states)]) + s.printer.Info("\r%s %s ", s.message, s.states[i%len(s.states)]) i++ time.Sleep(s.delay) } diff --git a/internal/pkg/tables/tables.go b/internal/pkg/tables/tables.go index 4d1018706..45ea21efb 100644 --- a/internal/pkg/tables/tables.go +++ b/internal/pkg/tables/tables.go @@ -4,9 +4,9 @@ import ( "fmt" "github.com/stackitcloud/stackit-cli/internal/pkg/pager" + "github.com/stackitcloud/stackit-cli/internal/pkg/print" "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" ) type Table struct { @@ -57,6 +57,6 @@ func (t *Table) Render() string { } // Displays the table in the command's stdout -func (t *Table) Display(cmd *cobra.Command) error { - return pager.Display(cmd, t.Render()) +func (t *Table) Display(p *print.Printer) error { + return pager.Display(p, t.Render()) } diff --git a/scripts/generate.go b/scripts/generate.go index 479e68a18..878078862 100644 --- a/scripts/generate.go +++ b/scripts/generate.go @@ -38,7 +38,7 @@ func main() { linkHandler := func(filename string) string { return fmt.Sprintf("./%s", filename) } - err = doc.GenMarkdownTreeCustom(cmd.NewRootCmd("", ""), docsDir, filePrepender, linkHandler) + err = doc.GenMarkdownTreeCustom(cmd.NewRootCmd("", "", nil), docsDir, filePrepender, linkHandler) if err != nil { log.Fatalf("Error generating documentation: %v", err) }