Skip to content

Commit

Permalink
Make "pretty" the default output format for describe commands (#289)
Browse files Browse the repository at this point in the history
* initial implementation

* address PR comments

* update describe examples

* generate docs
  • Loading branch information
DiogoFerrao authored May 6, 2024
1 parent 7f0388e commit 758acb2
Show file tree
Hide file tree
Showing 51 changed files with 346 additions and 350 deletions.
8 changes: 4 additions & 4 deletions docs/stackit_argus_grafana_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ stackit argus grafana describe INSTANCE_ID [flags]
Get details of the Grafana configuration of an Argus instance with ID "xxx"
$ stackit argus credentials describe xxx
Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format
$ stackit argus credentials describe xxx --output-format pretty
Get details of the Grafana configuration of an Argus instance with ID "xxx" and show the initial admin password
$ stackit argus credentials describe xxx --output-format pretty --show-password
$ stackit argus credentials describe xxx --show-password
Get details of the Grafana configuration of an Argus instance with ID "xxx" in JSON format
$ stackit argus credentials describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_argus_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit argus instance describe INSTANCE_ID [flags]
Get details of an Argus instance with ID "xxx"
$ stackit argus instance describe xxx
Get details of an Argus instance with ID "xxx" in a table format
$ stackit argus instance describe xxx --output-format pretty
Get details of an Argus instance with ID "xxx" in JSON format
$ stackit argus instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_argus_scrape-config_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit argus scrape-config describe JOB_NAME [flags]
Get details of a scrape configuration with name "my-config" from Argus instance "xxx"
$ stackit argus scrape-config describe my-config --instance-id xxx
Get details of a scrape configuration with name "my-config" from Argus instance "xxx" in a table format
$ stackit argus scrape-config describe my-config --output-format pretty
Get details of a scrape configuration with name "my-config" from Argus instance "xxx" in JSON format
$ stackit argus scrape-config describe my-config --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_dns_record-set_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit dns record-set describe RECORD_SET_ID [flags]
Get details of DNS record set with ID "xxx" in zone with ID "yyy"
$ stackit dns record-set describe xxx --zone-id yyy
Get details of DNS record set with ID "xxx" in zone with ID "yyy" in a table format
$ stackit dns record-set describe xxx --zone-id yyy --output-format pretty
Get details of DNS record set with ID "xxx" in zone with ID "yyy" in JSON format
$ stackit dns record-set describe xxx --zone-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_dns_zone_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit dns zone describe ZONE_ID [flags]
Get details of a DNS zone with ID "xxx"
$ stackit dns zone describe xxx
Get details of a DNS zone with ID "xxx" in a table format
$ stackit dns zone describe xxx --output-format pretty
Get details of a DNS zone with ID "xxx" in JSON format
$ stackit dns zone describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_logme_credentials_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit logme credentials describe CREDENTIALS_ID [flags]
Get details of credentials with ID "xxx" from instance with ID "yyy"
$ stackit logme credentials describe xxx --instance-id yyy
Get details of credentials with ID "xxx" from instance with ID "yyy" in a table format
$ stackit logme credentials describe xxx --instance-id yyy --output-format pretty
Get details of credentials with ID "xxx" from instance with ID "yyy" in JSON format
$ stackit logme credentials describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_logme_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit logme instance describe INSTANCE_ID [flags]
Get details of a LogMe instance with ID "xxx"
$ stackit logme instance describe xxx
Get details of a LogMe instance with ID "xxx" in a table format
$ stackit logme instance describe xxx --output-format pretty
Get details of a LogMe instance with ID "xxx" in JSON format
$ stackit logme instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_mariadb_credentials_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit mariadb credentials describe CREDENTIALS_ID [flags]
Get details of credentials with ID "xxx" from instance with ID "yyy"
$ stackit mariadb credentials describe xxx --instance-id yyy
Get details of credentials with ID "xxx" from instance with ID "yyy" in a table format
$ stackit mariadb credentials describe xxx --instance-id yyy --output-format pretty
Get details of credentials with ID "xxx" from instance with ID "yyy" in JSON format
$ stackit mariadb credentials describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_mariadb_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit mariadb instance describe INSTANCE_ID [flags]
Get details of a MariaDB instance with ID "xxx"
$ stackit mariadb instance describe xxx
Get details of a MariaDB instance with ID "xxx" in a table format
$ stackit mariadb instance describe xxx --output-format pretty
Get details of a MariaDB instance with ID "xxx" in JSON format
$ stackit mariadb instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_mongodbflex_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit mongodbflex instance describe INSTANCE_ID [flags]
Get details of a MongoDB Flex instance with ID "xxx"
$ stackit mongodbflex instance describe xxx
Get details of a MongoDB Flex instance with ID "xxx" in a table format
$ stackit mongodbflex instance describe xxx --output-format pretty
Get details of a MongoDB Flex instance with ID "xxx" in JSON format
$ stackit mongodbflex instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_mongodbflex_user_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ stackit mongodbflex user describe USER_ID [flags]
Get details of a MongoDB Flex user with ID "xxx" of instance with ID "yyy"
$ stackit mongodbflex user list xxx --instance-id yyy
Get details of a MongoDB Flex user with ID "xxx" of instance with ID "yyy" in table format
$ stackit mongodbflex user list xxx --instance-id yyy --output-format pretty
Get details of a MongoDB Flex user with ID "xxx" of instance with ID "yyy" in JSON format
$ stackit mongodbflex user list xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_object-storage_bucket_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit object-storage bucket describe BUCKET_NAME [flags]
Get details of an Object Storage bucket with name "my-bucket"
$ stackit object-storage bucket describe my-bucket
Get details of an Object Storage bucket with name "my-bucket" in a table format
$ stackit object-storage bucket describe my-bucket --output-format pretty
Get details of an Object Storage bucket with name "my-bucket" in JSON format
$ stackit object-storage bucket describe my-bucket --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_opensearch_credentials_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit opensearch credentials describe CREDENTIALS_ID [flags]
Get details of credentials with ID "xxx" from instance with ID "yyy"
$ stackit opensearch credentials describe xxx --instance-id yyy
Get details of credentials with ID "xxx" from instance with ID "yyy" in a table format
$ stackit opensearch credentials describe xxx --instance-id yyy --output-format pretty
Get details of credentials with ID "xxx" from instance with ID "yyy" in JSON format
$ stackit opensearch credentials describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_opensearch_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit opensearch instance describe INSTANCE_ID [flags]
Get details of an OpenSearch instance with ID "xxx"
$ stackit opensearch instance describe xxx
Get details of an OpenSearch instance with ID "xxx" in a table format
$ stackit opensearch instance describe xxx --output-format pretty
Get details of an OpenSearch instance with ID "xxx" in JSON format
$ stackit opensearch instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_postgresflex_backup_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit postgresflex backup describe BACKUP_ID [flags]
Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy"
$ stackit postgresflex backup describe xxx --instance-id yyy
Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in a table format
$ stackit postgresflex backup describe xxx --instance-id yyy --output-format pretty
Get details of a backup with ID "xxx" for a PostgreSQL Flex instance with ID "yyy" in JSON format
$ stackit postgresflex backup describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_postgresflex_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit postgresflex instance describe INSTANCE_ID [flags]
Get details of a PostgreSQL Flex instance with ID "xxx"
$ stackit postgresflex instance describe xxx
Get details of a PostgreSQL Flex instance with ID "xxx" in a table format
$ stackit postgresflex instance describe xxx --output-format pretty
Get details of a PostgreSQL Flex instance with ID "xxx" in JSON format
$ stackit postgresflex instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_postgresflex_user_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ stackit postgresflex user describe USER_ID [flags]
Get details of a PostgreSQL Flex user with ID "xxx" of instance with ID "yyy"
$ stackit postgresflex user list xxx --instance-id yyy
Get details of a PostgreSQL Flex user with ID "xxx" of instance with ID "yyy" in table format
$ stackit postgresflex user list xxx --instance-id yyy --output-format pretty
Get details of a PostgreSQL Flex user with ID "xxx" of instance with ID "yyy" in JSON format
$ stackit postgresflex user list xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_rabbitmq_credentials_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit rabbitmq credentials describe CREDENTIALS_ID [flags]
Get details of credentials with ID "xxx" from instance with ID "yyy"
$ stackit rabbitmq credentials describe xxx --instance-id yyy
Get details of credentials with ID "xxx" from instance with ID "yyy" in a table format
$ stackit rabbitmq credentials describe xxx --instance-id yyy --output-format pretty
Get details of credentials with ID "xxx" from instance with ID "yyy" in JSON format
$ stackit rabbitmq credentials describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_rabbitmq_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit rabbitmq instance describe INSTANCE_ID [flags]
Get details of a RabbitMQ instance with ID "xxx"
$ stackit rabbitmq instance describe xxx
Get details of a RabbitMQ instance with ID "xxx" in a table format
$ stackit rabbitmq instance describe xxx --output-format pretty
Get details of a RabbitMQ instance with ID "xxx" in JSON format
$ stackit rabbitmq instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_redis_credentials_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit redis credentials describe CREDENTIALS_ID [flags]
Get details of credentials with ID "xxx" from instance with ID "yyy"
$ stackit redis credentials describe xxx --instance-id yyy
Get details of credentials with ID "xxx" from instance with ID "yyy" in a table format
$ stackit redis credentials describe xxx --instance-id yyy --output-format pretty
Get details of credentials with ID "xxx" from instance with ID "yyy" in JSON format
$ stackit redis credentials describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_redis_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit redis instance describe INSTANCE_ID [flags]
Get details of a Redis instance with ID "xxx"
$ stackit redis instance describe xxx
Get details of a Redis instance with ID "xxx" in a table format
$ stackit redis instance describe xxx --output-format pretty
Get details of a Redis instance with ID "xxx" in JSON format
$ stackit redis instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_secrets-manager_instance_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit secrets-manager instance describe INSTANCE_ID [flags]
Get details of a Secrets Manager instance with ID "xxx"
$ stackit secrets-manager instance describe xxx
Get details of a Secrets Manager instance with ID "xxx" in a table format
$ stackit secrets-manager instance describe xxx --output-format pretty
Get details of a Secrets Manager instance with ID "xxx" in JSON format
$ stackit secrets-manager instance describe xxx --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_secrets-manager_user_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit secrets-manager user describe USER_ID [flags]
Get details of a Secrets Manager user with ID "xxx" of instance with ID "yyy"
$ stackit secrets-manager user describe xxx --instance-id yyy
Get details of a Secrets Manager user with ID "xxx" of instance with ID "yyy" in table format
$ stackit secrets-manager user describe xxx --instance-id yyy --output-format pretty
Get details of a Secrets Manager user with ID "xxx" of instance with ID "yyy" in JSON format
$ stackit secrets-manager user describe xxx --instance-id yyy --output-format json
```

### Options
Expand Down
4 changes: 2 additions & 2 deletions docs/stackit_ske_cluster_describe.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ stackit ske cluster describe CLUSTER_NAME [flags]
Get details of an SKE cluster with name "my-cluster"
$ stackit ske cluster describe my-cluster
Get details of an SKE cluster with name "my-cluster" in a table format
$ stackit ske cluster describe my-cluster --output-format pretty
Get details of an SKE cluster with name "my-cluster" in JSON format
$ stackit ske cluster describe my-cluster --output-format json
```

### Options
Expand Down
26 changes: 13 additions & 13 deletions internal/cmd/argus/grafana/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@ func NewCmd(p *print.Printer) *cobra.Command {
examples.NewExample(
`Get details of the Grafana configuration of an Argus instance with ID "xxx"`,
"$ stackit argus credentials describe xxx"),
examples.NewExample(
`Get details of the Grafana configuration of an Argus instance with ID "xxx" in a table format`,
"$ stackit argus credentials describe xxx --output-format pretty"),
examples.NewExample(
`Get details of the Grafana configuration of an Argus instance with ID "xxx" and show the initial admin password`,
"$ stackit argus credentials describe xxx --output-format pretty --show-password"),
"$ stackit argus credentials describe xxx --show-password"),
examples.NewExample(
`Get details of the Grafana configuration of an Argus instance with ID "xxx" in JSON format`,
"$ stackit argus credentials describe xxx --output-format json"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -125,7 +125,15 @@ func buildGetInstanceRequest(ctx context.Context, model *inputModel, apiClient *

func outputResult(p *print.Printer, inputModel *inputModel, grafanaConfigs *argus.GrafanaConfigs, instance *argus.GetInstanceResponse) error {
switch inputModel.OutputFormat {
case print.PrettyOutputFormat:
case print.JSONOutputFormat:
details, err := json.MarshalIndent(grafanaConfigs, "", " ")
if err != nil {
return fmt.Errorf("marshal Grafana configs: %w", err)
}
p.Outputln(string(details))

return nil
default:
initialAdminPassword := *instance.Instance.GrafanaAdminPassword
if !inputModel.ShowPassword {
initialAdminPassword = "<hidden>"
Expand All @@ -146,14 +154,6 @@ func outputResult(p *print.Printer, inputModel *inputModel, grafanaConfigs *argu
return fmt.Errorf("render table: %w", err)
}

return nil
default:
details, err := json.MarshalIndent(grafanaConfigs, "", " ")
if err != nil {
return fmt.Errorf("marshal Grafana configs: %w", err)
}
p.Outputln(string(details))

return nil
}
}
21 changes: 10 additions & 11 deletions internal/cmd/argus/instance/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func NewCmd(p *print.Printer) *cobra.Command {
`Get details of an Argus instance with ID "xxx"`,
"$ stackit argus instance describe xxx"),
examples.NewExample(
`Get details of an Argus instance with ID "xxx" in a table format`,
"$ stackit argus instance describe xxx --output-format pretty"),
`Get details of an Argus instance with ID "xxx" in JSON format`,
"$ stackit argus instance describe xxx --output-format json"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -98,8 +98,15 @@ func buildRequest(ctx context.Context, model *inputModel, apiClient *argus.APICl

func outputResult(p *print.Printer, outputFormat string, instance *argus.GetInstanceResponse) error {
switch outputFormat {
case print.PrettyOutputFormat:
case print.JSONOutputFormat:
details, err := json.MarshalIndent(instance, "", " ")
if err != nil {
return fmt.Errorf("marshal Argus instance: %w", err)
}
p.Outputln(string(details))

return nil
default:
table := tables.NewTable()
table.AddRow("ID", *instance.Id)
table.AddSeparator()
Expand All @@ -126,14 +133,6 @@ func outputResult(p *print.Printer, outputFormat string, instance *argus.GetInst
return fmt.Errorf("render table: %w", err)
}

return nil
default:
details, err := json.MarshalIndent(instance, "", " ")
if err != nil {
return fmt.Errorf("marshal Argus instance: %w", err)
}
p.Outputln(string(details))

return nil
}
}
Loading

0 comments on commit 758acb2

Please sign in to comment.