flags : return HelpError and print at the callsite

This commit is contained in:
bth 2026-01-29 10:23:11 -08:00
commit d4015598be
9 changed files with 107 additions and 34 deletions

View file

@ -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)