flags : return HelpError and print at the callsite
This commit is contained in:
parent
b9809e332b
commit
d4015598be
9 changed files with 107 additions and 34 deletions
14
sort/sort.go
14
sort/sort.go
|
|
@ -1,6 +1,7 @@
|
|||
package sort
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
|
@ -69,11 +70,18 @@ func write(file string, content string) {
|
|||
|
||||
func Sort(args []string) {
|
||||
opts := initOpts()
|
||||
flags.ParseArgs(CMD, SUMMARY, args, &opts)
|
||||
if err := flags.ParseArgs(CMD, SUMMARY, args, &opts); err != nil {
|
||||
var herr flags.HelpError
|
||||
if errors.As(err, &herr) {
|
||||
fmt.Println(herr)
|
||||
return
|
||||
}
|
||||
log.Fatalf("um %s: %s", CMD, err)
|
||||
}
|
||||
// BORK: by hand for now:
|
||||
if !opts.Key.IsSet() {
|
||||
flags.HelpRequired(CMD, opts.Key.Long)
|
||||
flags.Help(CMD, SUMMARY, opts)
|
||||
fmt.Println(flags.HelpRequired(CMD, opts.Key.Long))
|
||||
return
|
||||
}
|
||||
|
||||
sslice, err := pipe.FileListSplitMaybeStdin(opts.Source.Val)
|
||||
|
|
|
|||
Loading…
Reference in a new issue