Skip to content

Commit

Permalink
imp: Aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
hedzr committed Feb 2, 2022
1 parent 392e98f commit 0cb2a15
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
25 changes: 25 additions & 0 deletions build_xref.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,27 @@ func (w *ExecWorker) _addCommandsForAliasesGroup(root *RootCommand, aliases *ali
return
}

func (w *ExecWorker) _toolChkFlags(cc *Command) (err error) {
for _, f := range cc.Flags {
if f.owner == nil {
f.owner = cc
}
if f.DefaultValueType != "" && f.DefaultValue == nil {
//var kind = reflect.String
//for x := reflect.Bool; x <= reflect.Complex128; x++ {
// if x.String() == f.DefaultValueType {
// kind = x
// break
// }
//}

//typ := reflect.Kind.String()
//f.DefaultValue = reflect.New(typ)
}
}
return
}

func (w *ExecWorker) _toolAddCmd(parent *Command, groupName string, cc *Command) (err error) {
if cc.Group == "" {
cc.Group = groupName
Expand All @@ -157,6 +178,8 @@ func (w *ExecWorker) _toolAddCmd(parent *Command, groupName string, cc *Command)
parent.allCmds[groupName] = make(map[string]*Command)
}

err = w._toolChkFlags(cc)

cmdName := cc.GetTitleName()
if _, ok := parent.allCmds[groupName][cmdName]; !ok {
if cc.Action == nil {
Expand Down Expand Up @@ -288,10 +311,12 @@ func (w *ExecWorker) expandTmplWithExecutiveEnv(source string, cmd *Command, arg
Cmd *Command
Args []string
ArgsString string
Store *Options
}{
cmd,
args,
strings.Join(args, " "),
w.rxxtOptions,
})
return
}
Expand Down
6 changes: 6 additions & 0 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,9 @@ func (f *Flag) Delete() {
}
}
}

// GetDottedNamePath return the dotted key path of this flag
// in the options store.
func (f *Flag) GetDottedNamePath() string {
return f.owner.GetDottedNamePath() + "." + f.GetTitleName()
}
5 changes: 5 additions & 0 deletions options_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ func (s *Options) GetDuration(key string, defaultVal ...time.Duration) (ir time.
return
}

// Wrap wraps a key with [RxxtPrefix], for [GetXxx(key)] and [GetXxxP(prefix,key)]
func (s *Options) Wrap(key string) string {
return wrapWithRxxtPrefix(key)
}

// GetString returns the string value of an `Option` key.
func (s *Options) GetString(key string, defaultVal ...string) (ret string) {
ret = s.GetStringNoExpand(key, defaultVal...)
Expand Down

0 comments on commit 0cb2a15

Please sign in to comment.