Establish initial Go application skeleton
This commit is contained in:
45
internal/cli/root.go
Normal file
45
internal/cli/root.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user