flag

package
v0.0.38 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2022 License: LGPL-3.0 Imports: 20 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const EncodingDefault = "CP437"

Variables

View Source
var Build create.Args
View Source
var ErrFilenames = errors.New("ignoring [filenames]")
View Source
var ErrHide = errors.New("could not hide the flag")
View Source
var Info struct {
	Format string
}
View Source
var View = views()

Functions

func Args

func Args(cmd *cobra.Command, args ...string) ([]string, *convert.Convert, sample.Flags, error)

Args initializes the command arguments and flags.

func Controls

func Controls(p *[]string, cc *cobra.Command)

Controls handles the --controls flag.

func Default

func Default() encoding.Encoding

Default returns the default encoding when the --encoding flag is unused.

func Encode

func Encode(p *string, cc *cobra.Command)

Encode handles the --encode flag.

func EncodeAndHide

func EncodeAndHide(cmd *cobra.Command, dfault string) (sample.Flags, error)

EncodeAndHide applies the public --encode and the hidden --to encoding values to embed sample data.

func EndOfFile

func EndOfFile(flags convert.Flag) bool

EndOfFile returns true if the end-of-file control flag was requested.

Example
package main

import (
	"fmt"

	"github.com/bengarrett/retrotxtgo/cmd/internal/flag"
	"github.com/bengarrett/retrotxtgo/lib/convert"
)

func main() {
	var f convert.Flag
	f.Controls = []string{"eof"}
	fmt.Print(flag.EndOfFile(f))
}
Output:

true

func Help

func Help(cmd *cobra.Command, args ...string) error

Help will print the help and exit when no arguments are supplied.

func HiddenTo

func HiddenTo(p *string, cc *cobra.Command) error

HiddenTo handles the hidden --to flag.

func Init

func Init() map[int]Meta

Init initializes the create command flags and their help.

func OpenSample

func OpenSample(cmd *cobra.Command, arg string, c *convert.Convert, f sample.Flags) ([]byte, error)

OpenSample returns the content of the named embed sample file given via an argument.

func ReadArgument

func ReadArgument(arg string, cmd *cobra.Command, c *convert.Convert, f sample.Flags) ([]byte, error)

ReadArgument returns the content of argument supplied filepath, embed sample file or piped data.

func SAUCE

func SAUCE(src *[]byte) create.SAUCE

SAUCE returns any SAUCE metadata that is attached to src.

func Sort

func Sort(flags map[int]Meta) []int

Sort creates an ordered index of the meta flags.

func SwapChars

func SwapChars(p *[]string, cc *cobra.Command)

SwapChars handles the --swap-chars flag.

func Width

func Width(p *int, cc *cobra.Command)

Width handles the --width flag.

Types

type Commands

type Commands struct {
	Config string
	Tester bool
}
var Command Commands

type Creates

type Creates struct {
	Controls []string // character encoding used by the filename
	Encode   string   // use these control codes
	Swap     []string // swap out these characters with UTF8 alternatives
}

func Create

func Create() Creates

type Meta

type Meta struct {
	Key   string   // configuration name
	Strg  *string  // StringVarP(p) argument value
	Boo   *bool    // BoolVarP(p) argument value
	I     *uint    // UintVar(p) argument value
	Name  string   // flag long name
	Short string   // flag short name
	Opts  []string // flag choices for display in the usage string
}

func (*Meta) Body

func (c *Meta) Body(buf bytes.Buffer) bytes.Buffer

Body initializes the hidden body flag.

func (*Meta) Init

func (c *Meta) Init(cmd *cobra.Command, buf bytes.Buffer) bytes.Buffer

Init initializes the public facing flags.

type Views

type Views struct {
	Controls []string
	Encode   string
	Swap     []string
	To       string
	Width    int
}

Jump to

Keyboard shortcuts

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