cli

package
v2.5.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Jun 21, 2018 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package cli provides helpers for common NCA command-line tools' needs

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Wrap

func Wrap(msg string)

Wrap is a helper to wrap a usage message at 80 characters and print a newline afterward

Types

type BaseOptions

type BaseOptions struct {
	ConfigFile string `short:"c" long:"config" description:"path to NCA config file" required:"true"`
}

BaseOptions represents the simplest possible list of CLI options an NCA command can have: a config file. Commands should extend this rather than having their own custom type in order to ensure consistency.

type CLI

type CLI struct {
	// contains filtered or unexported fields
}

CLI centralizes the CLI parser as well as functionality around it

func New

func New(opts interface{}) *CLI

New returns a CLI instance for parsing flags into the given structure

func Simple

func Simple() *CLI

Simple returns a CLI instance for parsing just a --config flag, simplifying the tools which don't need special-case handling

func (*CLI) AppendUsage

func (c *CLI) AppendUsage(msg string)

AppendUsage adds a string which will be printed when usage is displayed

func (*CLI) GetConf

func (c *CLI) GetConf() *config.Config

GetConf parses the command-line flags and returns the config file - it is assumed that the options structure includes a ConfigFile string (which is free if BaseOptions is an embedded type)

func (*CLI) HelpExit

func (c *CLI) HelpExit(code int)

HelpExit exits the application after printing out the parser's help

func (*CLI) Parse

func (c *CLI) Parse()

Parse just runs the flags parser with some of our custom logic for handling errors and the help flag

func (*CLI) UsageFail

func (c *CLI) UsageFail(format string, args ...interface{})

UsageFail exits the application after printing out a message and the parser's help

Jump to

Keyboard shortcuts

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