Documentation
¶
Overview ¶
message from the author:
+--------------------------------------------------------------+ | * * * ░░░░░░░░░░░░░░░░░░░░ Hello ░░░░░░░░░░░░░░░░░░░░░░░░░░| +--------------------------------------------------------------+ | | | ++ ______________________________________ | | ++++ / \ | | ++++ | | | | ++++++++++ | Feel free to contribute to this | | | +++ | | project or contact me on | | | ++ | | manfred.life if you like this | | | + -== ==| | project! | | | ( <*> <*> | | | | | | /| :) | | | | _) / | | | | | +++ / \______________________________________/ | | \ =+ / | | \ + | | |\++++++ | | | ++++ ||// | | ___| |___ _||/__ __| | / --- \ \| ||| __ _ ___ __ __/ /| |/ | | \ \ / / ' \/ _ \/ // / / | || | | | | | /_/_/_/\___/\_,_/_/ | +--------------------------------------------------------------+
Example ¶
package main
import (
"context"
"flag"
"fmt"
"log"
"os"
"moul.io/climan"
)
func main() {
var opts struct {
Debug bool
}
root := &climan.Command{
Name: "example",
ShortUsage: "example [global flags] <subcommand> [flags] [args...]",
ShortHelp: "example's short help",
LongHelp: "example's longer help.\nwith more details.",
FlagSetBuilder: func(fs *flag.FlagSet) {
fs.BoolVar(&opts.Debug, "debug", opts.Debug, "debug mode")
},
Exec: func(ctx context.Context, args []string) error {
fmt.Println("args", args)
return nil
},
Subcommands: []*climan.Command{
&climan.Command{
Name: "sub",
},
},
// Options: []climan.Option{climan.WithEnvVarPrefix("EXAMPLE")},
}
if err := root.Parse(os.Args[1:]); err != nil {
log.Fatal(fmt.Errorf("parse error: %w", err))
}
if err := root.Run(context.Background()); err != nil {
log.Fatal(fmt.Errorf("run error: %w", err))
}
}
Output:
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DefaultUsageFunc ¶
Types ¶
type Command ¶
type Command struct {
Name string
Exec func(context.Context, []string) error
FlagSetBuilder func(fs *flag.FlagSet)
Subcommands []*Command
ShortUsage string
ShortHelp string
LongHelp string
FFOptions []ff.Option
FlagSet *flag.FlagSet
UsageFunc func(c *Command) string
// contains filtered or unexported fields
}
Click to show internal directories.
Click to hide internal directories.
