{"modulePath":"github.phpd.cn/thought-machine/please","version":"v13.4.0+incompatible","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package cli\n\nPackage cli contains helper functions related to flag parsing and logging.\n\n## Constants\n\n```go\nconst GiByte = humanize.GiByte\n```\nGiByte is a re-export for convenience of other things using it.\n\n```go\nconst MaxVerbosity = cli.MaxVerbosity\n```\nMaxVerbosity is the maximum verbosity we support.\n\n```go\nconst MinVerbosity = cli.MinVerbosity\n```\nMinVerbosity is the minimum verbosity we support.\n\n## Variables\n\n```go\nvar StdErrIsATerminal = terminal.IsTerminal(int(os.Stderr.Fd()))\n```\nStdErrIsATerminal is true if the process' stderr is an interactive TTY.\n\n```go\nvar StdOutIsATerminal = terminal.IsTerminal(int(os.Stdout.Fd()))\n```\nStdOutIsATerminal is true if the process' stdout is an interactive TTY.\n\n```go\nvar StripAnsi = regexp.MustCompile(\"\\x1b[^m]+m\")\n```\nStripAnsi is a regex to find \u0026 replace ANSI console escape sequences.\n\n## Functions\n\n```go\nfunc ActiveCommand(command *flags.Command) string\n```\nActiveCommand returns the name of the currently active command.\n\n```go\nfunc ContainsString(needle string, haystack []string) bool\n```\nContainsString returns true if the given slice contains an individual string.\n\n```go\nfunc Fprintf(w io.Writer, msg string, args ...interface{})\n```\nFprintf implements essentially fmt.Fprintf with replacements of some ANSI sequences, e.g. ${BOLD\\_RED} -\u003e \\\\x1bwhatever.\n\n```go\nfunc InitFileLogging(logFile string, logFileLevel Verbosity)\n```\nInitFileLogging initialises an optional logging backend to a file.\n\n```go\nfunc InitLogging(verbosity Verbosity)\n```\nInitLogging initialises logging backends.\n\n```go\nfunc NewProgressReader(reader io.ReadCloser, total string) io.ReadCloser\n```\nNewProgressReader returns a new progress bar reader.\n\n```go\nfunc ParseFlags(appname string, data interface{}, args []string, opts flags.Options, completionHandler cli.CompletionHandler) (*flags.Parser, []string, error)\n```\nParseFlags parses the app's flags and returns the parser, any extra arguments, and any error encountered. It may exit if certain options are encountered (eg. --help).\n\n```go\nfunc ParseFlagsFromArgsOrDie(appname string, data interface{}, args []string) string\n```\nParseFlagsFromArgsOrDie is similar to ParseFlagsOrDie but allows control over the flags passed. It returns the active command if there is one.\n\n```go\nfunc ParseFlagsOrDie(appname string, data interface{}) string\n```\nParseFlagsOrDie parses the app's flags and dies if unsuccessful. Also dies if any unexpected arguments are passed. It returns the active command if there is one.\n\n```go\nfunc PrintCompletions(items []flags.Completion)\n```\nPrintCompletions prints a set of completions to stdout.\n\n```go\nfunc Printf(msg string, args ...interface{})\n```\nPrintf is a convenience wrapper to Fprintf that always writes to stderr.\n\n```go\nfunc ReadAllStdin() []string\n```\nReadAllStdin reads standard input in its entirety to a slice. Since this reads it completely before returning it won't handle a slow input very nicely. ReadStdin is therefore preferable when possible.\n\n```go\nfunc ReadStdin() \u003c-chan string\n```\nReadStdin reads a sequence of space-delimited words from standard input. Words are pushed onto the returned channel asynchronously.\n\n```go\nfunc WindowSize() (int, int, error)\n```\nWindowSize finds and returns the size of the console window as (rows, columns)\n\n## Types\n\n```go\ntype Arch struct {\n\tOS, Arch string\n}\n```\nArch represents a combined Go-style operating system and architecture pair, as in \"linux\\_amd64\".\n\n```go\nfunc NewArch(os, arch string) Arch\n```\nNewArch constructs a new Arch instance.\n\n```go\nfunc (arch *Arch) GoArch() string\n```\nGoArch returns the architecture as Go would name it.\n\n```go\nfunc (arch *Arch) String() string\n```\nString prints this Arch to its string representation.\n\n```go\nfunc (arch *Arch) UnmarshalFlag(in string) error\n```\nUnmarshalFlag implements the flags.Unmarshaler interface.\n\n```go\nfunc (arch *Arch) UnmarshalText(text []byte) error\n```\nUnmarshalText implements the encoding.TextUnmarshaler interface\n\n```go\nfunc (arch *Arch) XArch() string\n```\nXArch returns the \"alternative\" architecture spelling which some things prefer. In this case amd64 is instead returned as x86\\_64 and x86 as x86\\_32.\n\n```go\nfunc (arch *Arch) XOS() string\n```\nXOS returns the \"alternative\" OS spelling which some things prefer. The difference here is that \"darwin\" is instead returned as \"osx\".\n\n```go\ntype ByteSize uint64\n```\nA ByteSize is used for flags that represent some quantity of bytes that can be passed as human-readable quantities (eg. \"10G\").\n\n```go\nfunc (b *ByteSize) UnmarshalFlag(in string) error\n```\nUnmarshalFlag implements the flags.Unmarshaler interface.\n\n```go\nfunc (b *ByteSize) UnmarshalText(text []byte) error\n```\nUnmarshalText implements the encoding.TextUnmarshaler interface\n\n```go\ntype Duration time.Duration\n```\nA Duration is used for flags that represent a time duration; it's just a wrapper around time.Duration that implements the flags.Unmarshaler and encoding.TextUnmarshaler interfaces.\n\n```go\nfunc (d *Duration) UnmarshalFlag(in string) error\n```\nUnmarshalFlag implements the flags.Unmarshaler interface.\n\n```go\nfunc (d *Duration) UnmarshalText(text []byte) error\n```\nUnmarshalText implements the encoding.TextUnmarshaler interface\n\n```go\ntype Filepath string\n```\nA Filepath implements completion for file paths. This is distinct from upstream's in that it knows about completing into directories.\n\n```go\nfunc (f *Filepath) Complete(match string) []flags.Completion\n```\nComplete implements the flags.Completer interface.\n\n```go\ntype LogBackend struct {\n\tsync.Mutex                                                  // Protects access to LogMessages\n\tRows, Cols, MaxRecords, InteractiveRows, MaxInteractiveRows int\n\tOutput                                                      []string\n\tLogMessages                                                 *list.List\n\tFormatter                                                   logging.Formatter // TODO(pebers): seems a bit weird that we have to have this here, but it doesn't\n\t// contains filtered or unexported fields\n} //               seem to be possible to retrieve the formatter from outside the package?\n\n```\nLogBackend is the backend we use for logging during the interactive console display.\n\n```go\nfunc NewLogBackend(interactiveRows int) *LogBackend\n```\nNewLogBackend constructs a new logging backend.\n\n```go\nfunc (backend *LogBackend) Deactivate()\n```\nDeactivate removes this backend as the currently active log backend.\n\n```go\nfunc (backend *LogBackend) RecalcLines()\n```\nRecalcLines recalculates how many lines we have available, typically in response to the window size changing\n\n```go\nfunc (backend *LogBackend) SetActive()\n```\nSetActive sets this backend as the currently active log backend.\n\n```go\ntype StdinStrings []string\n```\nStdinStrings is a type used for flags; it accepts a slice of strings but also if it's a single - it reads its contents from stdin.\n\n```go\nfunc (s StdinStrings) Get() []string\n```\nGet reads stdin if needed and returns the contents of this slice.\n\n```go\ntype URL string\n```\nA URL is used for flags or config fields that represent a URL. It's just a string because it's more convenient that way; we haven't needed them as a net.URL so far.\n\n```go\nfunc (u *URL) String() string\n```\nString implements the fmt.Stringer interface\n\n```go\nfunc (u *URL) UnmarshalFlag(in string) error\n```\nUnmarshalFlag implements the flags.Unmarshaler interface.\n\n```go\nfunc (u *URL) UnmarshalText(text []byte) error\n```\nUnmarshalText implements the encoding.TextUnmarshaler interface\n\n```go\ntype Verbosity = cli.Verbosity\n```\nA Verbosity is used as a flag to define logging verbosity.\n\n```go\ntype Version struct {\n\tsemver.Version\n\tIsGTE bool\n\tIsSet bool\n}\n```\nA Version is an extension to semver.Version extending it with the ability to recognise \u003e= prefixes.\n\n```go\nfunc MustNewVersion(in string) *Version\n```\nMustNewVersion creates a new version and dies if it is not parseable.\n\n```go\nfunc NewVersion(in string) (*Version, error)\n```\nNewVersion creates a new version from the given string.\n\n```go\nfunc (v *Version) Semver() semver.Version\n```\nSemver converts a Version to a semver.Version\n\n```go\nfunc (v Version) String() string\n```\nString implements the fmt.Stringer interface\n\n```go\nfunc (v *Version) UnmarshalFlag(in string) error\n```\nUnmarshalFlag implements the flags.Unmarshaler interface.\n\n```go\nfunc (v *Version) UnmarshalText(text []byte) error\n```\nUnmarshalText implements the encoding.TextUnmarshaler interface\n\n```go\nfunc (v *Version) Unset()\n```\nUnset resets this version to the default.\n\n```go\nfunc (v *Version) VersionString() string\n```\nVersionString returns just the version, without any preceding \u003e=.\n\n","path":"github.phpd.cn/thought-machine/please/src/cli","name":"cli","synopsis":"Package cli contains helper functions related to flag parsing and logging.","isRedistributable":true}
