camlistore.org: camlistore.org/pkg/cmdmain Index | Files

package cmdmain

import "camlistore.org/pkg/cmdmain"

Package cmdmain contains the shared implementation for camget, camput, camtool, and other Camlistore command-line tools.

Index

Package Files

cmdmain.go

Variables

var (
    FlagVersion = flag.Bool("version", false, "show version")
    FlagHelp    = flag.Bool("help", false, "print usage")
    FlagVerbose = flag.Bool("verbose", false, "extra debug logging")
    FlagLegal   = flag.Bool("legal", false, "show licenses")
)
var (
    // ExtraFlagRegistration allows to add more flags from
    // other packages (with AddFlags) when Main starts.
    ExtraFlagRegistration = func() {}
    // PostFlag runs code that needs to happen after flags were parsed, but
    // before the subcommand is run.
    PostFlag = func() {}
    // PreExit runs after the subcommand, but before Main terminates
    // with either success or the error from the subcommand.
    PreExit = func() {}
    // ExitWithFailure determines whether the command exits
    // with a non-zero exit status.
    ExitWithFailure bool
)
var (

    // Indirections for replacement by tests
    Stderr io.Writer = os.Stderr
    Stdout io.Writer = os.Stdout
    Stdin  io.Reader = os.Stdin

    Exit = realExit
)
var ErrUsage = UsageError("invalid command")

func Errorf Uses

func Errorf(format string, args ...interface{})

Errorf prints to Stderr, regardless of FlagVerbose.

func Logf Uses

func Logf(format string, v ...interface{})

Logf logs to Stderr if FlagVerbose, and is silent otherwise.

func Main Uses

func Main()

Main is meant to be the core of a command that has subcommands (modes), such as camput or camtool.

func PrintLicenses Uses

func PrintLicenses()

PrintLicenses prints all the licences registered by go4.org/legal for this program.

func Printf Uses

func Printf(format string, args ...interface{})

Printf prints to Stderr if FlagVerbose, and is silent otherwise.

func RegisterCommand Uses

func RegisterCommand(mode string, makeCmd func(Flags *flag.FlagSet) CommandRunner)

RegisterCommand adds a mode to the list of modes for the main command. It is meant to be called in init() for each subcommand.

type CommandRunner Uses

type CommandRunner interface {
    Usage()
    RunCommand(args []string) error
}

CommandRunner is the type that a command mode should implement.

type UsageError Uses

type UsageError string

func (UsageError) Error Uses

func (ue UsageError) Error() string

Package cmdmain imports 9 packages (graph) and is imported by 46 packages. Updated 2018-02-18. Refresh now. Tools for package owners.