Skip to content

Commit

Permalink
feat(config): add simple get extraction
Browse files Browse the repository at this point in the history
  • Loading branch information
remyleone committed May 27, 2020
1 parent 205e828 commit 039a797
Showing 1 changed file with 13 additions and 27 deletions.
40 changes: 13 additions & 27 deletions internal/namespaces/config/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,6 @@ func configGetCommand() *core.Command {
},
},
Run: func(ctx context.Context, argsI interface{}) (i interface{}, e error) {
// profileKeyValue is a custom type used for displaying configGetCommand result
type profileKeyValue struct {
Profile string `json:"profile"`
Key string `json:"key"`
Value string `json:"value"`
}

config, err := scw.LoadConfig()
if err != nil {
return nil, err
Expand All @@ -129,27 +122,20 @@ func configGetCommand() *core.Command {
if len(rawArgs) == 0 {
return nil, notEnoughArgsForConfigGetError()
}
profileKeyValues := []*profileKeyValue(nil)
for _, arg := range rawArgs {
profileName, key, err := splitProfileKey(arg)
if err != nil {
return nil, err
}
profile, err := getProfile(config, profileName)
if err != nil {
return nil, err
}
value, err := getProfileValue(profile, key)
if err != nil {
return nil, err
}
profileKeyValues = append(profileKeyValues, &profileKeyValue{
Profile: profileName,
Key: key,
Value: value,
})

profileName, key, err := splitProfileKey(rawArgs.GetPositionalArgs()[0])
if err != nil {
return nil, err
}
profile, err := getProfile(config, profileName)
if err != nil {
return nil, err
}
value, err := getProfileValue(profile, key)
if err != nil {
return nil, err
}
return profileKeyValues, nil
return value, nil
},
}
}
Expand Down

0 comments on commit 039a797

Please sign in to comment.