flags : reflection-powered general ParseArgs : uglier than tidy switch statements per cmd, but much easier to add new flags
This commit is contained in:
parent
924024fa73
commit
6f9f5dbb23
5 changed files with 93 additions and 87 deletions
18
last/last.go
18
last/last.go
|
|
@ -31,20 +31,6 @@ func initOpts() options {
|
|||
}
|
||||
}
|
||||
|
||||
func parseArgs(args []string) options {
|
||||
opts := initOpts()
|
||||
for _, arg := range args {
|
||||
switch {
|
||||
case arg == opts.Help.Long || arg == opts.Help.Short:
|
||||
flags.Help(CMD, SUMMARY, opts)
|
||||
default:
|
||||
flags.HelpInvalidArg(CMD, arg)
|
||||
flags.Help(CMD, SUMMARY, opts)
|
||||
}
|
||||
}
|
||||
return opts
|
||||
}
|
||||
|
||||
// get the lexical last file from GLOB
|
||||
func GlobLast(glob string) (string, error) {
|
||||
// NOTE: filepath.Glob is more reliable than a manual ls call:
|
||||
|
|
@ -59,7 +45,9 @@ func GlobLast(glob string) (string, error) {
|
|||
}
|
||||
|
||||
func Last(args []string) {
|
||||
_ = parseArgs(args)
|
||||
opts := initOpts()
|
||||
flags.ParseArgs(CMD, SUMMARY, args, &opts)
|
||||
|
||||
s, err := GlobLast(GLOB)
|
||||
if err != nil {
|
||||
log.Fatalf("um %s: %v", cmd.Last, err)
|
||||
|
|
|
|||
Loading…
Reference in a new issue