Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions docs/commands/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -212,6 +213,18 @@ scw config profile delete <name ...> [arg=value ...]



### List all profiles in the config file



**Usage:**

```
scw config profile list
```



## Reset the config


Expand Down
50 changes: 50 additions & 0 deletions internal/namespaces/config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os"
"os/exec"
"reflect"
"sort"
"strings"

"github.com/fatih/color"
Expand All @@ -29,6 +30,7 @@ func GetCommands() *core.Commands {
configUnsetCommand(),
configDumpCommand(),
configProfileCommand(),
configListProfilesCommand(),
configDeleteProfileCommand(),
configActivateProfileCommand(),
configResetCommand(),
Expand Down Expand Up @@ -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 {
Expand Down
Loading