cmdutil

package
v0.0.67 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 14, 2024 License: Apache-2.0, NCSA Imports: 6 Imported by: 11

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

func NewInfo(name, synopsis, usage string) Info

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

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.

func (Info) Name

func (i Info) Name() string

Name implements part of subcommands.Command.

func (Info) SetFlags

func (i Info) SetFlags(*flag.FlagSet)

SetFlags implements part of subcommands.Command.

func (Info) Synopsis

func (i Info) Synopsis() string

Synopsis implements part of subcommands.Command.

func (Info) Usage

func (i Info) Usage() string

Usage implements part of subcommands.Command.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL