flag

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2024 License: LGPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Package flag provides the command flags handlers.

Package flag provides the command flags handlers.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrHide = errors.New("could not hide the flag")
View Source
var ErrNames = errors.New("ignoring [filenames]")
View Source
var Hex struct {
	Raw bool // raw output
}

Hex handles the dec and hex "raw" flag.

View Source
var Info struct {
	Checksum bool   // show legacy checksums
	Format   string // output format
}

Info handles the info "format" flag.

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 a default encoding when the "input" flag is unused. If the input is a pipe, then the default encoding is UTF-16. Otherwise, the default encoding is CodePage437.

func Encode

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

Encode handles the "input" flag.

func EndOfFile

func EndOfFile(flags convert.Flag) bool

EndOfFile reports whether end-of-file control flag was requested.

Example
package main

import (
	"fmt"
	"os"

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

func main() {
	var f convert.Flag
	f.Controls = []string{"eof"}
	fmt.Fprint(os.Stdout, 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 InputOriginal added in v0.7.0

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

InputOriginal applies the "input" and the (hidden) "original" encoding flag values to the sample data.

func OG added in v0.7.5

func OG(p *bool, cc *cobra.Command) error

OG handles the original flag that can be used for multiple commands.

func OpenSample

func OpenSample(name 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, c *convert.Convert, f sample.Flags) ([]byte, error)

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

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 Command

type Command struct {
	Tester bool // internal automated tester
}

Command flags for the main cmd.

var Cmd Command

Cmd returns the flags for the main cmd.

type Views

type Views struct {
	Input    string   // input character encoding used by the files
	Controls []string // control codes to implement
	Swap     []string // swap out these characters with Unicode control pictures
	Width    int      // maximum document character/column width
	Original bool     // output the sample's original character encoding to stdout
}

Views handles the view command flags.

func View

func View() Views

View returns the Views struct with default values.

Jump to

Keyboard shortcuts

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