better get func
This commit is contained in:
parent
6bd898ee54
commit
8963d80942
3 changed files with 11 additions and 16 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue