46 lines
850 B
Go
46 lines
850 B
Go
package cli
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"io"
|
|
)
|
|
|
|
const helpText = `weatherreporter prepares weather reports from normalized forecast data.
|
|
|
|
Usage:
|
|
weatherreporter --help
|
|
|
|
Options:
|
|
-h, --help Show this help message.
|
|
`
|
|
|
|
// Run parses the root command and executes the selected behavior.
|
|
func Run(ctx context.Context, args []string, stdout io.Writer, stderr io.Writer) error {
|
|
_ = ctx
|
|
_ = stderr
|
|
|
|
fs := flag.NewFlagSet("weatherreporter", flag.ContinueOnError)
|
|
fs.SetOutput(io.Discard)
|
|
|
|
help := fs.Bool("help", false, "show help")
|
|
fs.BoolVar(help, "h", false, "show help")
|
|
|
|
if err := fs.Parse(args); err != nil {
|
|
return err
|
|
}
|
|
|
|
if *help {
|
|
_, err := fmt.Fprint(stdout, helpText)
|
|
return err
|
|
}
|
|
|
|
if fs.NArg() > 0 {
|
|
return fmt.Errorf("unknown argument %q", fs.Arg(0))
|
|
}
|
|
|
|
_, err := fmt.Fprint(stdout, helpText)
|
|
return err
|
|
}
|