please: github.com/thought-machine/please/src/cli Index | Files

package cli

import "github.com/thought-machine/please/src/cli"

Package cli contains helper functions related to flag parsing and logging.

Index

Package Files

flags.go logging.go progress.go replacements.go stdin.go window.go

Constants

const GiByte = humanize.GiByte

GiByte is a re-export for convenience of other things using it.

const MaxVerbosity = cli.MaxVerbosity

MaxVerbosity is the maximum verbosity we support.

const MinVerbosity = cli.MinVerbosity

MinVerbosity is the minimum verbosity we support.

Variables

var StdErrIsATerminal = terminal.IsTerminal(int(os.Stderr.Fd()))

StdErrIsATerminal is true if the process' stderr is an interactive TTY.

var StdOutIsATerminal = terminal.IsTerminal(int(os.Stdout.Fd()))

StdOutIsATerminal is true if the process' stdout is an interactive TTY.

var StripAnsi = regexp.MustCompile("\x1b[^m]+m")

StripAnsi is a regex to find & replace ANSI console escape sequences.

func ActiveCommand Uses

func ActiveCommand(command *flags.Command) string

ActiveCommand returns the name of the currently active command.

func ContainsString Uses

func ContainsString(needle string, haystack []string) bool

ContainsString returns true if the given slice contains an individual string.

func Fprintf Uses

func Fprintf(w io.Writer, msg string, args ...interface{})

Fprintf implements essentially fmt.Fprintf with replacements of some ANSI sequences, e.g. ${BOLD_RED} -> \x1bwhatever.

func InitFileLogging Uses

func InitFileLogging(logFile string, logFileLevel Verbosity)

InitFileLogging initialises an optional logging backend to a file.

func InitLogging Uses

func InitLogging(verbosity Verbosity)

InitLogging initialises logging backends.

func NewProgressReader Uses

func NewProgressReader(reader io.ReadCloser, total string) io.ReadCloser

NewProgressReader returns a new progress bar reader.

func ParseFlags Uses

func ParseFlags(appname string, data interface{}, args []string, opts flags.Options, completionHandler cli.CompletionHandler) (*flags.Parser, []string, error)

ParseFlags 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).

func ParseFlagsFromArgsOrDie Uses

func ParseFlagsFromArgsOrDie(appname string, data interface{}, args []string) string

ParseFlagsFromArgsOrDie is similar to ParseFlagsOrDie but allows control over the flags passed. It returns the active command if there is one.

func ParseFlagsOrDie Uses

func ParseFlagsOrDie(appname string, data interface{}) string

ParseFlagsOrDie 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.

func PrintCompletions Uses

func PrintCompletions(items []flags.Completion)

PrintCompletions prints a set of completions to stdout.

func Printf Uses

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

Printf is a convenience wrapper to Fprintf that always writes to stderr.

func ReadAllStdin Uses

func ReadAllStdin() []string

ReadAllStdin 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.

func ReadStdin Uses

func ReadStdin() <-chan string

ReadStdin reads a sequence of space-delimited words from standard input. Words are pushed onto the returned channel asynchronously.

func WindowSize Uses

func WindowSize() (int, int, error)

WindowSize finds and returns the size of the console window as (rows, columns)

type Arch Uses

type Arch struct {
    OS, Arch string
}

Arch represents a combined Go-style operating system and architecture pair, as in "linux_amd64".

func HostArch Uses

func HostArch() Arch

HostArch returns the architecture for the host OS.

func NewArch Uses

func NewArch(os, arch string) Arch

NewArch constructs a new Arch instance.

func (*Arch) GoArch Uses

func (arch *Arch) GoArch() string

GoArch returns the architecture as Go would name it.

func (*Arch) HostArch Uses

func (arch *Arch) HostArch() string

HostArch returns the architecture of the host (machine doing the building).

func (*Arch) HostOS Uses

func (arch *Arch) HostOS() string

HostOS returns the OS of the host (machine doing the building). Configuring certain tools (e.g. pip) requires this information, even when cross-compiling.

func (*Arch) String Uses

func (arch *Arch) String() string

String prints this Arch to its string representation.

func (*Arch) UnmarshalFlag Uses

func (arch *Arch) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Arch) UnmarshalText Uses

func (arch *Arch) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

func (*Arch) XArch Uses

func (arch *Arch) XArch() string

XArch returns the "alternative" architecture spelling which some things prefer. In this case amd64 is instead returned as x86_64 and x86 as x86_32.

func (*Arch) XOS Uses

func (arch *Arch) XOS() string

XOS returns the "alternative" OS spelling which some things prefer. The difference here is that "darwin" is instead returned as "osx".

type ByteSize Uses

type ByteSize uint64

A ByteSize is used for flags that represent some quantity of bytes that can be passed as human-readable quantities (eg. "10G").

func (*ByteSize) UnmarshalFlag Uses

func (b *ByteSize) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*ByteSize) UnmarshalText Uses

func (b *ByteSize) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type Duration Uses

type Duration time.Duration

A 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.

func (*Duration) UnmarshalFlag Uses

func (d *Duration) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Duration) UnmarshalText Uses

func (d *Duration) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type Filepath Uses

type Filepath string

A Filepath implements completion for file paths. This is distinct from upstream's in that it knows about completing into directories.

func (*Filepath) Complete Uses

func (f *Filepath) Complete(match string) []flags.Completion

Complete implements the flags.Completer interface.

type LogBackend Uses

type LogBackend struct {
    sync.Mutex                                                  // Protects access to LogMessages
    Rows, Cols, MaxRecords, InteractiveRows, MaxInteractiveRows int
    Output                                                      []string
    LogMessages                                                 *list.List
    Formatter                                                   logging.Formatter // TODO(pebers): seems a bit weird that we have to have this here, but it doesn't
    // contains filtered or unexported fields
}   //               seem to be possible to retrieve the formatter from outside the package?

LogBackend is the backend we use for logging during the interactive console display.

func NewLogBackend Uses

func NewLogBackend(interactiveRows int) *LogBackend

NewLogBackend constructs a new logging backend.

func (*LogBackend) Deactivate Uses

func (backend *LogBackend) Deactivate()

Deactivate removes this backend as the currently active log backend.

func (*LogBackend) RecalcLines Uses

func (backend *LogBackend) RecalcLines()

RecalcLines recalculates how many lines we have available, typically in response to the window size changing

func (*LogBackend) SetActive Uses

func (backend *LogBackend) SetActive()

SetActive sets this backend as the currently active log backend.

type StdinStrings Uses

type StdinStrings []string

StdinStrings 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.

func (StdinStrings) Get Uses

func (s StdinStrings) Get() []string

Get reads stdin if needed and returns the contents of this slice.

type URL Uses

type URL string

A 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.

func (*URL) String Uses

func (u *URL) String() string

String implements the fmt.Stringer interface

func (*URL) UnmarshalFlag Uses

func (u *URL) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*URL) UnmarshalText Uses

func (u *URL) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

type Verbosity Uses

type Verbosity = cli.Verbosity

A Verbosity is used as a flag to define logging verbosity.

type Version Uses

type Version struct {
    semver.Version
    IsGTE bool
    IsSet bool
}

A Version is an extension to semver.Version extending it with the ability to recognise >= prefixes.

func MustNewVersion Uses

func MustNewVersion(in string) *Version

MustNewVersion creates a new version and dies if it is not parseable.

func NewVersion Uses

func NewVersion(in string) (*Version, error)

NewVersion creates a new version from the given string.

func (*Version) Semver Uses

func (v *Version) Semver() semver.Version

Semver converts a Version to a semver.Version

func (Version) String Uses

func (v Version) String() string

String implements the fmt.Stringer interface

func (*Version) UnmarshalFlag Uses

func (v *Version) UnmarshalFlag(in string) error

UnmarshalFlag implements the flags.Unmarshaler interface.

func (*Version) UnmarshalText Uses

func (v *Version) UnmarshalText(text []byte) error

UnmarshalText implements the encoding.TextUnmarshaler interface

func (*Version) Unset Uses

func (v *Version) Unset()

Unset resets this version to the default.

func (*Version) VersionString Uses

func (v *Version) VersionString() string

VersionString returns just the version, without any preceding >=.

Package cli imports 23 packages (graph) and is imported by 18 packages. Updated 2019-04-19. Refresh now. Tools for package owners.