Documentation
¶
Index ¶
- Variables
- func CustomIO(inputArg, outputArg string, outputName func(string) string) (input Input, output Output, err error)
- func IOFlags() []cli.Flag
- func InputFlags() []cli.Flag
- func OutputFlags() []cli.Flag
- func PassphraseFunc(prompt string) func() (string, error)
- func Read() (pack.Tag, pack.Packable, error)
- func ReadExact[T pack.Packable](in Input) (v T, err error)
- func RequestPassphrase(prompt string) (string, error)
- func Status(v ...any)
- func Statusf(format string, v ...any)
- func WithPassphrase(prompt string) error
- func Write(v pack.Packable) error
- func YesNo(prompt string) (bool, error)
- type ErrNonTerminal
- type Input
- type Output
Constants ¶
This section is empty.
Variables ¶
var FlagArmor = &cli.BoolFlag{ Name: "armor", Aliases: []string{"a"}, Usage: "use ascii-armored output", Destination: &armor, DefaultText: "enabled by default for terminal output", }
FlagArmor is an armor flag.
var FlagCompression = &cli.StringFlag{ Name: "compression", Usage: "compression `ALGORITHM:LVL`", DefaultText: "no compression", Action: func(_ *cli.Context, v string) error { i := strings.Index(v, ":") if i == 0 { return cli.Exit(fmt.Errorf("invalid compression: %s", v), 1) } var alg string var lvl int if i == -1 { alg = v } else { alg = v[:i] lvl, _ = strconv.Atoi(v[i+1:]) } c, ok := str2compression[alg] if ok { compressor = c(lvl) return nil } list := make([]string, 0, len(str2compression)) for k := range str2compression { list = append(list, k) } return cli.Exit(fmt.Errorf("available compression algorithms: %s", strings.Join(list, ", ")), 1) }, }
FlagCompression is a compression flag.
var FlagInput = &cli.StringFlag{ Name: "input", Aliases: []string{"i"}, Usage: "input `FILE` (override stdin)", TakesFile: true, Action: func(_ *cli.Context, path string) error { i, err := CustomInput(path) if err != nil { return err } os.Stdin = i.Raw() return nil }, }
FlagInput is an input flag.
var FlagOutput = &cli.PathFlag{ Name: "output", Aliases: []string{"o"}, Usage: "output `FILE` (override stdout)", TakesFile: true, Action: func(_ *cli.Context, path string) error { o, err := CustomOutput(path) if err != nil { return err } os.Stdout = o.Raw() return nil }, }
FlagOutput is an output flag.
Functions ¶
func CustomIO ¶
func CustomIO(inputArg, outputArg string, outputName func(string) string) (input Input, output Output, err error)
CustomIO accept input and output arguments and returns custom input and output.
func PassphraseFunc ¶
PassphraseFunc returns a function that prompts the user for a passphrase.
func RequestPassphrase ¶
RequestPassphrase prompts the user for a passphrase.
func WithPassphrase ¶
WithPassphrase requests the passphrase and creates packing option.
Types ¶
type ErrNonTerminal ¶ added in v0.1.3
type ErrNonTerminal struct {
// contains filtered or unexported fields
}
ErrNonTerminal is returned when the input is not a terminal.
func (ErrNonTerminal) Error ¶ added in v0.1.3
func (e ErrNonTerminal) Error() string
type Input ¶
type Input interface { Raw() *os.File Close() error // Read reads the value from input. Read() (pack.Tag, pack.Packable, error) // contains filtered or unexported methods }
Input represents a cmd input.
func CustomInput ¶
CustomInput opens the specified file and returns it as Input. If the path is empty, it returns the standard input.
type Output ¶
type Output interface { Raw() *os.File Close() error // Write writes the specified value to the output. Write(pack.Packable) error }
Output represents a cmd output.
func CustomOutput ¶
CustomOutput opens the specified file and returns it as Output. If the path is empty, it returns the standard output.