diff --git a/command/alias.go b/command/alias.go index 2922a7830..da005a4ab 100644 --- a/command/alias.go +++ b/command/alias.go @@ -73,11 +73,12 @@ func aliasSet(cmd *cobra.Command, args []string) error { successMsg := fmt.Sprintf("%s Added alias.", utils.Green("✓")) - if aliasCfg.Exists(alias) { + oldExpansion, ok := aliasCfg.Get(alias) + if ok { successMsg = fmt.Sprintf("%s Changed alias %s from %s to %s", utils.Green("✓"), utils.Bold(alias), - utils.Bold(aliasCfg.Get(alias)), + utils.Bold(oldExpansion), utils.Bold(expansionStr), ) } @@ -188,11 +189,11 @@ func aliasDelete(cmd *cobra.Command, args []string) error { return fmt.Errorf("couldn't read aliases config: %w", err) } - if !aliasCfg.Exists(alias) { + expansion, ok := aliasCfg.Get(alias) + if !ok { return fmt.Errorf("no such alias %s", alias) - } - expansion := aliasCfg.Get(alias) + } err = aliasCfg.Delete(alias) if err != nil { diff --git a/command/root.go b/command/root.go index db76509ed..e7cea4c1a 100644 --- a/command/root.go +++ b/command/root.go @@ -464,9 +464,9 @@ func ExpandAlias(args []string) ([]string, error) { return empty, err } - if aliases.Exists(args[1]) { + expansion, ok := aliases.Get(args[1]) + if ok { extraArgs := []string{} - expansion := aliases.Get(args[1]) for i, a := range args[2:] { if !strings.Contains(expansion, "$") { extraArgs = append(extraArgs, a) diff --git a/internal/config/alias_config.go b/internal/config/alias_config.go index fd99006c8..148eb21f9 100644 --- a/internal/config/alias_config.go +++ b/internal/config/alias_config.go @@ -9,19 +9,13 @@ type AliasConfig struct { Parent Config } -func (a *AliasConfig) Exists(alias string) bool { +func (a *AliasConfig) Get(alias string) (string, bool) { if a.Empty() { - return false + return "", false } value, _ := a.GetStringValue(alias) - return value != "" -} - -func (a *AliasConfig) Get(alias string) string { - value, _ := a.GetStringValue(alias) - - return value + return value, value != "" } func (a *AliasConfig) Add(alias, expansion string) error {