From cd8f1001364d77a6c58657db59b6f60ee6bd7762 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 1 Dec 2025 13:30:19 +0100 Subject: [PATCH 1/2] feat: add support for scw config profile list --- ...all-usage-config-profile-list-usage.golden | 15 ++++++ ...test-all-usage-config-profile-usage.golden | 1 + internal/namespaces/config/commands.go | 50 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 cmd/scw/testdata/test-all-usage-config-profile-list-usage.golden diff --git a/cmd/scw/testdata/test-all-usage-config-profile-list-usage.golden b/cmd/scw/testdata/test-all-usage-config-profile-list-usage.golden new file mode 100644 index 0000000000..a6fcc879cb --- /dev/null +++ b/cmd/scw/testdata/test-all-usage-config-profile-list-usage.golden @@ -0,0 +1,15 @@ +🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲 +πŸŸ₯πŸŸ₯πŸŸ₯ STDERR️️ πŸŸ₯πŸŸ₯πŸŸ₯️ +List all profiles in the config file + +USAGE: + scw config profile list + +FLAGS: + -h, --help help for list + +GLOBAL FLAGS: + -c, --config string The path to the config file + -D, --debug Enable debug mode + -o, --output string Output format: json or human, see 'scw help output' for more info (default "human") + -p, --profile string The config profile to use diff --git a/cmd/scw/testdata/test-all-usage-config-profile-usage.golden b/cmd/scw/testdata/test-all-usage-config-profile-usage.golden index 1282b18b95..ed5f26b879 100644 --- a/cmd/scw/testdata/test-all-usage-config-profile-usage.golden +++ b/cmd/scw/testdata/test-all-usage-config-profile-usage.golden @@ -8,6 +8,7 @@ USAGE: CONFIGURATION COMMANDS: activate Mark a profile as active in the config file delete Delete a profile from the config file + list List all profiles in the config file FLAGS: -h, --help help for profile diff --git a/internal/namespaces/config/commands.go b/internal/namespaces/config/commands.go index 3a5c0010f6..ad03f1e5de 100644 --- a/internal/namespaces/config/commands.go +++ b/internal/namespaces/config/commands.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "reflect" + "sort" "strings" "github.com/fatih/color" @@ -29,6 +30,7 @@ func GetCommands() *core.Commands { configUnsetCommand(), configDumpCommand(), configProfileCommand(), + configListProfilesCommand(), configDeleteProfileCommand(), configActivateProfileCommand(), configResetCommand(), @@ -424,6 +426,54 @@ func configProfileCommand() *core.Command { } } +// configListProfilesCommand lists all profiles in the config file +func configListProfilesCommand() *core.Command { + return &core.Command{ + Groups: []string{"config"}, + Short: `List all profiles in the config file`, + Namespace: "config", + Resource: "profile", + Verb: "list", + AllowAnonymousClient: true, + ArgsType: reflect.TypeOf(struct{}{}), + ArgSpecs: core.ArgSpecs{}, + Run: func(ctx context.Context, argsI any) (i any, e error) { + configPath := core.ExtractConfigPath(ctx) + config, err := scw.LoadConfigFromPath(configPath) + type profile struct { + Name string + DefaultZone *string + DefaultRegion *string + DefaultProjectID *string + DefaultOrganizationID *string + APIURL *string + } + if err != nil { + return nil, err + } + + profiles := []profile{} + + for key, value := range config.Profiles { + profiles = append(profiles, profile{ + Name: key, + DefaultRegion: value.DefaultRegion, + DefaultZone: value.DefaultZone, + DefaultOrganizationID: value.DefaultOrganizationID, + DefaultProjectID: value.DefaultProjectID, + APIURL: value.APIURL, + }) + } + + sort.Slice(profiles, func(i, j int) bool { + return profiles[i].Name < profiles[j].Name + }) + + return profiles, nil + }, + } +} + // configDeleteProfileCommand deletes a profile from the config func configDeleteProfileCommand() *core.Command { type configDeleteProfileArgs struct { From 1035b200f425eedb1fd2ff8d5b6cd8de0a798ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Mon, 1 Dec 2025 13:31:41 +0100 Subject: [PATCH 2/2] fix docs --- docs/commands/config.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/docs/commands/config.md b/docs/commands/config.md index f1b75804cd..7543ff5318 100644 --- a/docs/commands/config.md +++ b/docs/commands/config.md @@ -35,6 +35,7 @@ Read more about the config management engine at https://github.com/scaleway/scal - [Allows the activation and deletion of a profile from the config file](#allows-the-activation-and-deletion-of-a-profile-from-the-config-file) - [Mark a profile as active in the config file](#mark-a-profile-as-active-in-the-config-file) - [Delete a profile from the config file](#delete-a-profile-from-the-config-file) + - [List all profiles in the config file](#list-all-profiles-in-the-config-file) - [Reset the config](#reset-the-config) - [Set a line from the config file](#set-a-line-from-the-config-file) - [Unset a line from the config file](#unset-a-line-from-the-config-file) @@ -212,6 +213,18 @@ scw config profile delete [arg=value ...] +### List all profiles in the config file + + + +**Usage:** + +``` +scw config profile list +``` + + + ## Reset the config