Documentation
¶
Overview ¶
Package cmdutil exports shared logic for implementing command-line subcommands using the github.com/google/subcommands package.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Info ¶
type Info struct {
// contains filtered or unexported fields
}
Info implements the methods of the subcommands.Command interface that handle the command name and documentation. It also provides a noop default SetFlags method and a default Execute method that prints its usage and exits.
func NewInfo ¶
NewInfo constructs an Info that reports the specified arguments for command name, brief synopsis, and usage.
Example ¶
package main
import (
"context"
"flag"
"fmt"
"github.com/google/subcommands"
"kythe.io/kythe/go/util/cmdutil"
)
func main() {
cmd := struct {
cmdutil.Info
}{
Info: cmdutil.NewInfo("example", "Demonstrate how to set up a subcommand",
`Show the user how to use the cmdutil.NewInfo function.`),
}
// Set up a flag set for demo purposes; most tools will use the default
// command line flags from the flag package.
fs := flag.NewFlagSet("test", flag.ExitOnError)
fs.Parse([]string{"example", "foo"})
// Register a command with the dispatcher.
cmdr := subcommands.NewCommander(fs, "cmdutil_test")
cmdr.Register(cmd, "examples")
// Execute...
fmt.Println(cmdr.Execute(context.Background(), fs))
}
Output: Show the user how to use the cmdutil.NewInfo function. 0
func (Info) Execute ¶
func (i Info) Execute(context.Context, *flag.FlagSet, ...any) subcommands.ExitStatus
Execute implements part of subcommands.Command. It prints the usage string to stdout and returns success.
func (Info) Fail ¶
func (i Info) Fail(msg string, args ...any) subcommands.ExitStatus
Fail logs an error message and returns subcommands.ExitFailure.