Documentation ¶
Index ¶
- Constants
- func Do(ctx context.Context, args []string) error
- func DoWithOS()
- func ExitCode(from error) int
- func ExtractFormat(arg string) (path, format string)
- func Help() string
- func RegisterWorker(inputFormat, outputFormat string, worker Worker) error
- type Context
- type ExitCodeBearer
- type ExitError
- type Work
- type Worker
Constants ¶
const ( ExitCodeUnknownError = 1 ExitCodeInvalidArgs = 2 ExitCodeInvalidFormats = 3 )
Variables ¶
This section is empty.
Functions ¶
func DoWithOS ¶
func DoWithOS()
DoWithOS is wrapper for Do with NewContext(context.Background()) and os.Args. It also handles returned error and exit code.
func ExitCode ¶
ExitCode returns exit code from passed error. If passed error or its wrapped error doesn't implement ExitCode, it returns ExitCodeUnknownError. See also ExitError.
func ExtractFormat ¶
ExtractFormat returns path from passed arg and derived format. Default format is derived from file extension. It can be overridden if arg contains # with following format.
func RegisterWorker ¶
Types ¶
type Context ¶
type Context struct {
// contains filtered or unexported fields
}
Context represents cancelable context which also reacts to os.Interrupt signal.
func NewContext ¶
NewContext returns new Context based on parent.
type ExitCodeBearer ¶
type ExitCodeBearer interface {
ExitCode() int
}
ExitCodeBearer represents value with specified exit code. See also ExitCode or ExitError.
type ExitError ¶
ExitError represents error with specified exit code.
func NewExitError ¶
NewExitError creates new ExitError.
func (*ExitError) ErrString ¶
ErrString returns string representation of Err. If e or Err is nil, it returns value "unknown error".
type Work ¶
type Work interface { Context() context.Context Formats() (input, output string) Input() []byte Output(data []byte) error }
Work represents one specific run with arguments.
func NewWorkFromOS ¶
NewWorkFromOS returns new Work based on passed parameters. Values input and output can be path to file or - (representing stdin and stdout). Format is derived from file extension or overridden if # is present. See also ExtractFormat.