Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
b13651e
Implement `GetProfile` (#309)
joaopalet May 9, 2024
1856fd0
Choose config folder based on profile in InitConfig (#310)
joaopalet May 9, 2024
cebf8dc
Implement `stackit config profile` commands (#312)
joaopalet May 10, 2024
81d4448
Improvements to profiles functionality (#315)
joaopalet May 13, 2024
adcbc5f
Implement profiles for auth settings (#326)
GokceGK May 20, 2024
f579141
Add warnings when set/unset profile with no auth (#327)
DiogoFerrao May 20, 2024
bbdb98f
address acceptance comments (#328)
DiogoFerrao May 20, 2024
74c5fa3
Rework active profile handling in auth (#329)
GokceGK May 21, 2024
919fe7a
Merge latest updates from `main` into `feature/multi-config` (#330)
joaopalet May 21, 2024
7949c82
Fix encoded file path for profiles (#333)
GokceGK May 22, 2024
37cbab0
Merge branch 'main' into jp/merge-main-updates
May 22, 2024
807d688
Merge pull request #336 from stackitcloud/jp/merge-main-updates
joaopalet May 22, 2024
2bfc711
Merge branch 'main' into df/multi-config-merge-main
DiogoFerrao May 24, 2024
1b22400
move config/fileutils to new package
DiogoFerrao May 24, 2024
e927d15
Merge pull request #343 from stackitcloud/df/multi-config-merge-main
DiogoFerrao May 24, 2024
286c9c8
Add `stackit profile create` command and refactor `set` command (#351)
DiogoFerrao May 28, 2024
48f881b
fix profile existence check (#356)
DiogoFerrao May 28, 2024
5601f19
fix issues in acceptance (#357)
DiogoFerrao May 29, 2024
bd2f2c5
improve set profile error message (#362)
DiogoFerrao May 31, 2024
bc7ae7e
Add `stackit config profile list/delete` commands (#359)
DiogoFerrao May 31, 2024
44c1e0c
Don't allow deleting the default configuration profile (#363)
DiogoFerrao May 31, 2024
b242821
address acceptance issues (#365)
DiogoFerrao Jun 3, 2024
9013b11
Merge branch 'main' into feature/multi-config
DiogoFerrao Jun 3, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions docs/stackit_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ Provides functionality for CLI configuration options

### Synopsis

Provides functionality for CLI configuration options
The configuration is stored in a file in the user's config directory, which is OS dependent.
Windows: %APPDATA%\stackit
Linux: $XDG_CONFIG_HOME/stackit
macOS: $HOME/Library/Application Support/stackit
The configuration file is named `cli-config.json` and is created automatically in your first CLI run.
Provides functionality for CLI configuration options.
You can set and unset different configuration options via the "stackit config set" and "stackit config unset" commands.

Additionally, you can configure the CLI to use different profiles, each with its own configuration.
Additional profiles can be configured via the "STACKIT_CLI_PROFILE" environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.

```
stackit config [flags]
Expand All @@ -35,6 +35,7 @@ stackit config [flags]

* [stackit](./stackit.md) - Manage STACKIT resources using the command line
* [stackit config list](./stackit_config_list.md) - Lists the current CLI configuration values
* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles
* [stackit config set](./stackit_config_set.md) - Sets CLI configuration options
* [stackit config unset](./stackit_config_unset.md) - Unsets CLI configuration options

40 changes: 40 additions & 0 deletions docs/stackit_config_profile.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit config profile

Manage the CLI configuration profiles

### Synopsis

Manage the CLI configuration profiles.
The profile to be used can be managed via the "STACKIT_CLI_PROFILE" environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.
When no profile is set, the default profile is used.

```
stackit config profile [flags]
```

### Options

```
-h, --help Help for "stackit config profile"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config](./stackit_config.md) - Provides functionality for CLI configuration options
* [stackit config profile create](./stackit_config_profile_create.md) - Creates a CLI configuration profile
* [stackit config profile delete](./stackit_config_profile_delete.md) - Delete a CLI configuration profile
* [stackit config profile list](./stackit_config_profile_list.md) - Lists all CLI configuration profiles
* [stackit config profile set](./stackit_config_profile_set.md) - Set a CLI configuration profile
* [stackit config profile unset](./stackit_config_profile_unset.md) - Unset the current active CLI configuration profile

48 changes: 48 additions & 0 deletions docs/stackit_config_profile_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## stackit config profile create

Creates a CLI configuration profile

### Synopsis

Creates a CLI configuration profile based on the currently active profile and sets it as active.
The profile name can be provided via the STACKIT_CLI_PROFILE environment variable or as an argument in this command.
The environment variable takes precedence over the argument.
If you do not want to set the profile as active, use the --no-set flag.
If you want to create the new profile with the initial default configurations, use the --empty flag.

```
stackit config profile create PROFILE [flags]
```

### Examples

```
Create a new configuration profile "my-profile" with the current configuration, setting it as the active profile
$ stackit config profile create my-profile

Create a new configuration profile "my-profile" with a default initial configuration and don't set it as the active profile
$ stackit config profile create my-profile --empty --no-set
```

### Options

```
--empty Create the profile with the initial default configurations
-h, --help Help for "stackit config profile create"
--no-set Do not set the profile as the active profile
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

40 changes: 40 additions & 0 deletions docs/stackit_config_profile_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit config profile delete

Delete a CLI configuration profile

### Synopsis

Delete a CLI configuration profile.
If the deleted profile is the active profile, the default profile will be set to active.

```
stackit config profile delete PROFILE [flags]
```

### Examples

```
Delete the configuration profile "my-profile"
$ stackit config profile delete my-profile
```

### Options

```
-h, --help Help for "stackit config profile delete"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

42 changes: 42 additions & 0 deletions docs/stackit_config_profile_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## stackit config profile list

Lists all CLI configuration profiles

### Synopsis

Lists all CLI configuration profiles.

```
stackit config profile list [flags]
```

### Examples

```
List the configuration profiles
$ stackit config profile list

List the configuration profiles in a json format
$ stackit config profile list --output-format json
```

### Options

```
-h, --help Help for "stackit config profile list"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

42 changes: 42 additions & 0 deletions docs/stackit_config_profile_set.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
## stackit config profile set

Set a CLI configuration profile

### Synopsis

Set a CLI configuration profile as the active profile.
The profile to be used can be managed via the STACKIT_CLI_PROFILE environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.
The environment variable takes precedence over what is set via the commands.
When no profile is set, the default profile is used.

```
stackit config profile set PROFILE [flags]
```

### Examples

```
Set the configuration profile "my-profile" as the active profile
$ stackit config profile set my-profile
```

### Options

```
-h, --help Help for "stackit config profile set"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

40 changes: 40 additions & 0 deletions docs/stackit_config_profile_unset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## stackit config profile unset

Unset the current active CLI configuration profile

### Synopsis

Unset the current active CLI configuration profile.
When no profile is set, the default profile will be used.

```
stackit config profile unset [flags]
```

### Examples

```
Unset the currently active configuration profile. The default profile will be used.
$ stackit config profile unset
```

### Options

```
-h, --help Help for "stackit config profile unset"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, one of ["json" "pretty" "none" "yaml"]
-p, --project-id string Project ID
--verbosity string Verbosity of the CLI, one of ["debug" "info" "warning" "error"] (default "info")
```

### SEE ALSO

* [stackit config profile](./stackit_config_profile.md) - Manage the CLI configuration profiles

14 changes: 8 additions & 6 deletions internal/cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"

"github.com/stackitcloud/stackit-cli/internal/cmd/config/list"
"github.com/stackitcloud/stackit-cli/internal/cmd/config/profile"
"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"
Expand All @@ -17,12 +18,12 @@ func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: "config",
Short: "Provides functionality for CLI configuration options",
Long: fmt.Sprintf("%s\n%s\n%s\n%s\n%s\n%s", "Provides functionality for CLI configuration options",
"The configuration is stored in a file in the user's config directory, which is OS dependent.",
"Windows: %APPDATA%\\stackit",
"Linux: $XDG_CONFIG_HOME/stackit",
"macOS: $HOME/Library/Application Support/stackit",
"The configuration file is named `cli-config.json` and is created automatically in your first CLI run.",
Long: fmt.Sprintf("%s\n%s\n\n%s\n%s\n%s",
"Provides functionality for CLI configuration options.",
`You can set and unset different configuration options via the "stackit config set" and "stackit config unset" commands.`,
"Additionally, you can configure the CLI to use different profiles, each with its own configuration.",
`Additional profiles can be configured via the "STACKIT_CLI_PROFILE" environment variable or using the "stackit config profile set PROFILE" and "stackit config profile unset" commands.`,
"The environment variable takes precedence over what is set via the commands.",
),
Args: args.NoArgs,
Run: utils.CmdHelp,
Expand All @@ -35,4 +36,5 @@ func addSubcommands(cmd *cobra.Command, p *print.Printer) {
cmd.AddCommand(list.NewCmd(p))
cmd.AddCommand(set.NewCmd(p))
cmd.AddCommand(unset.NewCmd(p))
cmd.AddCommand(profile.NewCmd(p))
}
17 changes: 15 additions & 2 deletions internal/cmd/config/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ func NewCmd(p *print.Printer) *cobra.Command {
configData := viper.AllSettings()

model := parseInput(p, cmd)
return outputResult(p, model.OutputFormat, configData)

activeProfile, err := config.GetProfile()
if err != nil {
return fmt.Errorf("get profile: %w", err)
}

return outputResult(p, model.OutputFormat, configData, activeProfile)
},
}
return cmd
Expand All @@ -65,9 +71,12 @@ func parseInput(p *print.Printer, cmd *cobra.Command) *inputModel {
}
}

func outputResult(p *print.Printer, outputFormat string, configData map[string]any) error {
func outputResult(p *print.Printer, outputFormat string, configData map[string]any, activeProfile string) error {
switch outputFormat {
case print.JSONOutputFormat:
if activeProfile != "" {
configData["profile"] = activeProfile
}
details, err := json.MarshalIndent(configData, "", " ")
if err != nil {
return fmt.Errorf("marshal config list: %w", err)
Expand All @@ -83,6 +92,7 @@ func outputResult(p *print.Printer, outputFormat string, configData map[string]a

return nil
default:

// Sort the config options by key
configKeys := make([]string, 0, len(configData))
for k := range configData {
Expand All @@ -91,6 +101,9 @@ func outputResult(p *print.Printer, outputFormat string, configData map[string]a
sort.Strings(configKeys)

table := tables.NewTable()
if activeProfile != "" {
table.SetTitle(fmt.Sprintf("Profile: %q", activeProfile))
}
table.SetHeader("NAME", "VALUE")
for _, key := range configKeys {
value := configData[key]
Expand Down
Loading