Skip to content

Commit

Permalink
feat: merge config reset commands
Browse files Browse the repository at this point in the history
Signed-off-by: Marko Kungla <[email protected]>
  • Loading branch information
mkungla committed Aug 17, 2024
1 parent aeea8ba commit 68d7382
Showing 1 changed file with 22 additions and 33 deletions.
55 changes: 22 additions & 33 deletions sdk/config/config-cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ func Command() *command.Command {
configSet(),
configGet(),
configReset(),
configResetAll(),
)

return cmd
Expand Down Expand Up @@ -253,7 +252,29 @@ func configReset() *command.Command {

cmd.Usage("--profile=<profile-name>")

cmd.WithFlags(varflag.BoolFunc("all", false, "reset all settings", "a"))

cmd.Do(func(sess *session.Context, args action.Args) error {
if args.Flag("all").Present() {
profileFilePath := filepath.Join(sess.Get("app.fs.path.profile").String(), "profile.preferences")
internal.Log(sess.Log(), "profile.save",
slog.String("profile", sess.Get("app.profile.name").String()),
slog.String("file", profileFilePath),
)

if err := os.WriteFile(profileFilePath, []byte{}, 0600); err != nil {
return err
}

internal.Log(
sess.Log(),
"saved profile",
slog.String("profile", sess.Get("app.profile.name").String()),
slog.String("file", profileFilePath),
)
return nil
}

key := args.Arg(0).String()
if !sess.Settings().Has(key) {
return fmt.Errorf("setting %q does not exist", key)
Expand Down Expand Up @@ -300,35 +321,3 @@ func configReset() *command.Command {

return cmd
}

func configResetAll() *command.Command {
cmd := command.New(command.Config{
Name: "reset-all",
Description: "Reset all settings to their default values",
})

cmd.Usage("--profile=<profile-name>")

cmd.Do(func(sess *session.Context, args action.Args) error {

profileFilePath := filepath.Join(sess.Get("app.fs.path.profile").String(), "profile.preferences")
internal.Log(sess.Log(), "profile.save",
slog.String("profile", sess.Get("app.profile.name").String()),
slog.String("file", profileFilePath),
)

if err := os.WriteFile(profileFilePath, []byte{}, 0600); err != nil {
return err
}

internal.Log(
sess.Log(),
"saved profile",
slog.String("profile", sess.Get("app.profile.name").String()),
slog.String("file", profileFilePath),
)
return nil
})

return cmd
}

0 comments on commit 68d7382

Please sign in to comment.