Skip to content

Commit cefddda

Browse files
hcsa73Henrique Santos
andauthored
Config fixes (#75)
* Change description * Reword descriptions, simplify examples * Add to description * Add session time limit flag * Change async default to bool * Reword description * Fix unset to set the default value * Fix list not showing bool vars * Reword docs * Reword descriptions * Rewrite field descriptions * Fix description typo * Add details --------- Co-authored-by: Henrique Santos <henrique.santos@freiheit.com>
1 parent faf7099 commit cefddda

File tree

10 files changed

+114
-75
lines changed

10 files changed

+114
-75
lines changed

docs/stackit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ stackit [flags]
2626
### SEE ALSO
2727

2828
* [stackit auth](./stackit_auth.md) - Provides authentication functionality
29-
* [stackit config](./stackit_config.md) - CLI configuration options
29+
* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
3030
* [stackit curl](./stackit_curl.md) - Executes an authenticated HTTP request to an endpoint
3131
* [stackit dns](./stackit_dns.md) - Provides functionality for DNS
3232
* [stackit logme](./stackit_logme.md) - Provides functionality for LogMe

docs/stackit_config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
## stackit config
22

3-
CLI configuration options
3+
Provides functionality for CLI configuration options
44

55
### Synopsis
66

7-
CLI configuration options.
7+
Provides functionality for CLI configuration options.
88

99
```
1010
stackit config [flags]

docs/stackit_config_list.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@ Lists the current CLI configuration values
44

55
### Synopsis
66

7-
Lists the current CLI configuration values.
7+
Lists the current CLI configuration values, based on the following sources (in order of precedence):
8+
- Environment variable
9+
The environment variable is the name of the setting, with underscores ("_") instead of dashes ("-") and the "STACKIT" prefix.
10+
Example: you can set the project ID by setting the environment variable STACKIT_PROJECT_ID.
11+
- Configuration set in CLI
12+
These are set using the "stackit config set" command
13+
Example: you can set the project ID by running "stackit config set --project-id xxx"
814

915
```
1016
stackit config list [flags]
@@ -34,5 +40,5 @@ stackit config list [flags]
3440

3541
### SEE ALSO
3642

37-
* [stackit config](./stackit_config.md) - CLI configuration options
43+
* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
3844

docs/stackit_config_set.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Sets CLI configuration options
55
### Synopsis
66

77
Sets CLI configuration options.
8-
All of the configuration options can be set using an environment variable, which takes precedence over what is configured.
8+
All of the configuration options can be set using an environment variable, which takes precedence over what is configured using this command.
99
The environment variable is the name of the flag, with underscores ("_") instead of dashes ("-") and the "STACKIT" prefix.
1010
Example: to set the project ID you can set the environment variable STACKIT_PROJECT_ID.
1111

@@ -16,33 +16,33 @@ stackit config set [flags]
1616
### Examples
1717

1818
```
19-
Set a project ID in your active configuration. This project ID will be used by every command, as long as it's not overridden by the "STACKIT_PROJECT_ID" environment variable or the command flag
19+
Set a project ID in your active configuration. This project ID will be used by every command (unless overridden by the "STACKIT_PROJECT_ID" environment variable)
2020
$ stackit config set --project-id xxx
2121
22-
Set the session time limit to 1 hour. After this time you will be prompted to login again to be able to execute commands that need authentication
22+
Set the session time limit to 1 hour
2323
$ stackit config set --session-time-limit 1h
2424
25-
Set the DNS custom endpoint. This endpoint will be used on all calls to the DNS API, unless overridden by the "STACKIT_DNS_CUSTOM_ENDPOINT" environment variable
25+
Set the DNS custom endpoint. This endpoint will be used on all calls to the DNS API (unless overridden by the "STACKIT_DNS_CUSTOM_ENDPOINT" environment variable)
2626
$ stackit config set --dns-custom-endpoint https://dns.stackit.cloud
2727
```
2828

2929
### Options
3030

3131
```
32-
--authorization-custom-endpoint string Authorization custom endpoint
33-
--dns-custom-endpoint string DNS custom endpoint
32+
--authorization-custom-endpoint string Authorization API base URL, used in calls to this API
33+
--dns-custom-endpoint string DNS API base URL, used in calls to this API
3434
-h, --help Help for "stackit config set"
35-
--logme-custom-endpoint string LogMe custom endpoint
36-
--mariadb-custom-endpoint string MariaDB custom endpoint
37-
--mongodbflex-custom-endpoint string MongoDB Flex custom endpoint
38-
--opensearch-custom-endpoint string OpenSearch custom endpoint
39-
--postgresflex-custom-endpoint string PostgreSQL Flex custom endpoint
40-
--rabbitmq-custom-endpoint string RabbitMQ custom endpoint
41-
--redis-custom-endpoint string Redis custom endpoint
42-
--resource-manager-custom-endpoint string Resource manager custom endpoint
43-
--service-account-custom-endpoint string Service Account custom endpoint
44-
--session-time-limit string Maximum time before authentication is required again. Can't be larger than 24h. Examples: 3h, 5h30m40s (BETA: currently values greater than 2h have no effect)
45-
--ske-custom-endpoint string SKE custom endpoint
35+
--logme-custom-endpoint string LogMe API base URL, used in calls to this API
36+
--mariadb-custom-endpoint string MariaDB API base URL, used in calls to this API
37+
--mongodbflex-custom-endpoint string MongoDB Flex API base URL, used in calls to this API
38+
--opensearch-custom-endpoint string OpenSearch API base URL, used in calls to this API
39+
--postgresflex-custom-endpoint string PostgreSQL Flex API base URL, used in calls to this API
40+
--rabbitmq-custom-endpoint string RabbitMQ API base URL, used in calls to this API
41+
--redis-custom-endpoint string Redis API base URL, used in calls to this API
42+
--resource-manager-custom-endpoint string Resource Manager API base URL, used in calls to this API
43+
--service-account-custom-endpoint string Service Account API base URL, used in calls to this API
44+
--session-time-limit string Maximum time before authentication is required again. After this time, you will be prompted to login again to execute commands that require authentication. Can't be larger than 24h. Requires authentication after being set to take effect. Examples: 3h, 5h30m40s (BETA: currently values greater than 2h have no effect)
45+
--ske-custom-endpoint string SKE API base URL, used in calls to this API
4646
```
4747

4848
### Options inherited from parent commands
@@ -56,5 +56,5 @@ stackit config set [flags]
5656

5757
### SEE ALSO
5858

59-
* [stackit config](./stackit_config.md) - CLI configuration options
59+
* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
6060

docs/stackit_config_unset.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Unsets CLI configuration options
44

55
### Synopsis
66

7-
Unsets CLI configuration options.
7+
Unsets CLI configuration options, undoing past usages of the `stackit config set` command.
88

99
```
1010
stackit config unset [flags]
@@ -27,21 +27,22 @@ stackit config unset [flags]
2727

2828
```
2929
--async Configuration option to run commands asynchronously
30-
--authorization-custom-endpoint Authorization custom endpoint
31-
--dns-custom-endpoint DNS custom endpoint
30+
--authorization-custom-endpoint Authorization API base URL. If unset, uses the default base URL
31+
--dns-custom-endpoint DNS API base URL. If unset, uses the default base URL
3232
-h, --help Help for "stackit config unset"
33-
--logme-custom-endpoint LogMe custom endpoint
34-
--mariadb-custom-endpoint MariaDB custom endpoint
35-
--mongodbflex-custom-endpoint MongoDB Flex custom endpoint
36-
--opensearch-custom-endpoint OpenSearch custom endpoint
33+
--logme-custom-endpoint LogMe API base URL. If unset, uses the default base URL
34+
--mariadb-custom-endpoint MariaDB API base URL. If unset, uses the default base URL
35+
--mongodbflex-custom-endpoint MongoDB Flex API base URL. If unset, uses the default base URL
36+
--opensearch-custom-endpoint OpenSearch API base URL. If unset, uses the default base URL
3737
--output-format Output format
38-
--postgresflex-custom-endpoint PostgreSQL Flex custom endpoint
38+
--postgresflex-custom-endpoint PostgreSQL Flex API base URL. If unset, uses the default base URL
3939
--project-id Project ID
40-
--rabbitmq-custom-endpoint RabbitMQ custom endpoint
41-
--redis-custom-endpoint Redis custom endpoint
42-
--resource-manager-custom-endpoint Resource Manager custom endpoint
43-
--service-account-custom-endpoint SKE custom endpoint
44-
--ske-custom-endpoint SKE custom endpoint
40+
--rabbitmq-custom-endpoint RabbitMQ API base URL. If unset, uses the default base URL
41+
--redis-custom-endpoint Redis API base URL. If unset, uses the default base URL
42+
--resource-manager-custom-endpoint Resource Manager API base URL. If unset, uses the default base URL
43+
--service-account-custom-endpoint SKE API base URL. If unset, uses the default base URL
44+
--session-time-limit Maximum time before authentication is required again. If unset, defaults to 2h
45+
--ske-custom-endpoint SKE API base URL. If unset, uses the default base URL
4546
```
4647

4748
### Options inherited from parent commands
@@ -52,5 +53,5 @@ stackit config unset [flags]
5253

5354
### SEE ALSO
5455

55-
* [stackit config](./stackit_config.md) - CLI configuration options
56+
* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
5657

internal/cmd/config/config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
func NewCmd() *cobra.Command {
1414
cmd := &cobra.Command{
1515
Use: "config",
16-
Short: "CLI configuration options",
17-
Long: "CLI configuration options.",
16+
Short: "Provides functionality for CLI configuration options",
17+
Long: "Provides functionality for CLI configuration options.",
1818
Args: args.NoArgs,
1919
Run: utils.CmdHelp,
2020
}

internal/cmd/config/list/list.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"fmt"
55
"slices"
66
"sort"
7+
"strconv"
78
"strings"
89

910
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -19,8 +20,16 @@ func NewCmd() *cobra.Command {
1920
cmd := &cobra.Command{
2021
Use: "list",
2122
Short: "Lists the current CLI configuration values",
22-
Long: "Lists the current CLI configuration values.",
23-
Args: args.NoArgs,
23+
Long: fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s\n%s",
24+
"Lists the current CLI configuration values, based on the following sources (in order of precedence):",
25+
"- Environment variable",
26+
` The environment variable is the name of the setting, with underscores ("_") instead of dashes ("-") and the "STACKIT" prefix.`,
27+
" Example: you can set the project ID by setting the environment variable STACKIT_PROJECT_ID.",
28+
"- Configuration set in CLI",
29+
` These are set using the "stackit config set" command`,
30+
` Example: you can set the project ID by running "stackit config set --project-id xxx"`,
31+
),
32+
Args: args.NoArgs,
2433
Example: examples.Build(
2534
examples.NewExample(
2635
`List your active configuration`,
@@ -45,8 +54,20 @@ func NewCmd() *cobra.Command {
4554
table.SetHeader("NAME", "VALUE")
4655
for _, key := range configKeys {
4756
value := configData[key]
57+
58+
// Convert value to string
59+
// (Assuming value is either string or bool)
4860
valueString, ok := value.(string)
49-
if !ok || valueString == "" {
61+
if !ok {
62+
valueBool, ok := value.(bool)
63+
if !ok {
64+
continue
65+
}
66+
valueString = strconv.FormatBool(valueBool)
67+
}
68+
69+
// Don't show unset values
70+
if valueString == "" {
5071
continue
5172
}
5273

internal/cmd/config/set/set.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,20 @@ func NewCmd() *cobra.Command {
4444
Short: "Sets CLI configuration options",
4545
Long: fmt.Sprintf("%s\n%s\n%s\n%s",
4646
"Sets CLI configuration options.",
47-
"All of the configuration options can be set using an environment variable, which takes precedence over what is configured.",
47+
"All of the configuration options can be set using an environment variable, which takes precedence over what is configured using this command.",
4848
`The environment variable is the name of the flag, with underscores ("_") instead of dashes ("-") and the "STACKIT" prefix.`,
4949
"Example: to set the project ID you can set the environment variable STACKIT_PROJECT_ID.",
5050
),
5151
Args: args.NoArgs,
5252
Example: examples.Build(
5353
examples.NewExample(
54-
`Set a project ID in your active configuration. This project ID will be used by every command, as long as it's not overridden by the "STACKIT_PROJECT_ID" environment variable or the command flag`,
54+
`Set a project ID in your active configuration. This project ID will be used by every command (unless overridden by the "STACKIT_PROJECT_ID" environment variable)`,
5555
"$ stackit config set --project-id xxx"),
5656
examples.NewExample(
57-
`Set the session time limit to 1 hour. After this time you will be prompted to login again to be able to execute commands that need authentication`,
57+
`Set the session time limit to 1 hour`,
5858
"$ stackit config set --session-time-limit 1h"),
5959
examples.NewExample(
60-
`Set the DNS custom endpoint. This endpoint will be used on all calls to the DNS API, unless overridden by the "STACKIT_DNS_CUSTOM_ENDPOINT" environment variable`,
60+
`Set the DNS custom endpoint. This endpoint will be used on all calls to the DNS API (unless overridden by the "STACKIT_DNS_CUSTOM_ENDPOINT" environment variable)`,
6161
"$ stackit config set --dns-custom-endpoint https://dns.stackit.cloud"),
6262
),
6363
RunE: func(cmd *cobra.Command, args []string) error {
@@ -88,20 +88,20 @@ func NewCmd() *cobra.Command {
8888
}
8989

9090
func configureFlags(cmd *cobra.Command) {
91-
cmd.Flags().String(sessionTimeLimitFlag, "", "Maximum time before authentication is required again. Can't be larger than 24h. Examples: 3h, 5h30m40s (BETA: currently values greater than 2h have no effect)")
92-
93-
cmd.Flags().String(authorizationCustomEndpointFlag, "", "Authorization custom endpoint")
94-
cmd.Flags().String(dnsCustomEndpointFlag, "", "DNS custom endpoint")
95-
cmd.Flags().String(logMeCustomEndpointFlag, "", "LogMe custom endpoint")
96-
cmd.Flags().String(mariaDBCustomEndpointFlag, "", "MariaDB custom endpoint")
97-
cmd.Flags().String(mongoDBFlexCustomEndpointFlag, "", "MongoDB Flex custom endpoint")
98-
cmd.Flags().String(openSearchCustomEndpointFlag, "", "OpenSearch custom endpoint")
99-
cmd.Flags().String(postgresFlexCustomEndpointFlag, "", "PostgreSQL Flex custom endpoint")
100-
cmd.Flags().String(rabbitMQCustomEndpointFlag, "", "RabbitMQ custom endpoint")
101-
cmd.Flags().String(redisCustomEndpointFlag, "", "Redis custom endpoint")
102-
cmd.Flags().String(resourceManagerCustomEndpointFlag, "", "Resource manager custom endpoint")
103-
cmd.Flags().String(serviceAccountCustomEndpointFlag, "", "Service Account custom endpoint")
104-
cmd.Flags().String(skeCustomEndpointFlag, "", "SKE custom endpoint")
91+
cmd.Flags().String(sessionTimeLimitFlag, "", "Maximum time before authentication is required again. After this time, you will be prompted to login again to execute commands that require authentication. Can't be larger than 24h. Requires authentication after being set to take effect. Examples: 3h, 5h30m40s (BETA: currently values greater than 2h have no effect)")
92+
93+
cmd.Flags().String(authorizationCustomEndpointFlag, "", "Authorization API base URL, used in calls to this API")
94+
cmd.Flags().String(dnsCustomEndpointFlag, "", "DNS API base URL, used in calls to this API")
95+
cmd.Flags().String(logMeCustomEndpointFlag, "", "LogMe API base URL, used in calls to this API")
96+
cmd.Flags().String(mariaDBCustomEndpointFlag, "", "MariaDB API base URL, used in calls to this API")
97+
cmd.Flags().String(mongoDBFlexCustomEndpointFlag, "", "MongoDB Flex API base URL, used in calls to this API")
98+
cmd.Flags().String(openSearchCustomEndpointFlag, "", "OpenSearch API base URL, used in calls to this API")
99+
cmd.Flags().String(postgresFlexCustomEndpointFlag, "", "PostgreSQL Flex API base URL, used in calls to this API")
100+
cmd.Flags().String(rabbitMQCustomEndpointFlag, "", "RabbitMQ API base URL, used in calls to this API")
101+
cmd.Flags().String(redisCustomEndpointFlag, "", "Redis API base URL, used in calls to this API")
102+
cmd.Flags().String(resourceManagerCustomEndpointFlag, "", "Resource Manager API base URL, used in calls to this API")
103+
cmd.Flags().String(serviceAccountCustomEndpointFlag, "", "Service Account API base URL, used in calls to this API")
104+
cmd.Flags().String(skeCustomEndpointFlag, "", "SKE API base URL, used in calls to this API")
105105

106106
err := viper.BindPFlag(config.AuthorizationCustomEndpointKey, cmd.Flags().Lookup(authorizationCustomEndpointFlag))
107107
cobra.CheckErr(err)

0 commit comments

Comments
 (0)