cli

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: May 21, 2016 License: MIT Imports: 26 Imported by: 0

README

Command line interface License Go Report Card GoDoc

Screenshot

screenshot2

Key features

  • Lightweight and easy to use.
  • Defines flag by tag, e.g. flag name(short or/and long), description, default value, password, prompt and so on.
  • Type safety.
  • Output looks very nice.
  • Supports custom Validator.
  • Supports slice and map as a flag.
  • Supports any type as a flag field which implements cli.Decoder interface.
  • Supports any type as a flag field which use FlagParser.
  • Suggestions for command.(e.g. hl => help, "veron" => "version").
  • Supports default value for flag, even expression about env variable(e.g. dft:"$HOME/dev").
  • Supports editor like git commit command.(See example 21 and 22)

Getting started

package main

import (
	"github.com/mkideal/cli"
)

type argT struct {
	cli.Helper
	Name string `cli:"name" usage:"your name" dft:"world"`
	Age  uint8  `cli:"a,age" usage:"your age" dft:"100"`
}

func main() {
	cli.Run(&argT{}, func(ctx *cli.Context) error {
		argv := ctx.Argv().(*argT)
		ctx.String("Hello, %s! Your age is %d?\n", argv.Name, argv.Age)
		return nil
	})
}

Type these in terminal

$> go build -o hello
$> ./hello
Hello, world! Your age is 100?
$> ./hello --name=clipher -a 9
Hello, clipher! Your age is 9?
$> ./hello -h

Try

$> ./hello -a 256

API documentation

See godoc

Examples

See _examples, example_*test.go files or site below:

Projects which use CLI

  • onepw - A lightweight tool for managing passwords
  • rqlite CLI - A command line tool for connecting to a rqlited node

Argument object of cli

Supported tags in argument object of cli:

  • cli - supports short format and long format, e,g, -p, --port
  • pw - similar to cli, but used to input password
  • usage - description of flag
  • dft - default value, supports constant value, env variable, and even expression
  • name - placeholder for flag
  • prompt - prompt string
  • parser - builtin parsers: json, jsonfile, supports custom parsers.
Supported types of flag
  • All basic types: int,uint,...,flaot32,float64,string,bool
  • Slice of basic type: []int, []uint, []string,...
  • Map of basic type: map[uint]int, map[string]string,...
  • Any type which implments cli.Decoder
  • Any type which use correct parser(json,jsonfile, or your registered parser)
AutoHelper
// AutoHelper represents interface for showing help information automaticly
AutoHelper interface {
	AutoHelp() bool
}

If your argT implments AutoHelper, it will show help if argT.AutoHelp return true.

For example:

package main

import "github.com/mkideal/cli"

type argT struct {
	Help bool `cli:"h,help" usage:"show help"`
}

func (argv *argT) AutoHelp() bool {
	return argv.Help
}

func main() {
	cli.Run(&argT{}, func(ctx *cli.Context) error {
		return nil
	})
}

Build and run:

go build -o app
./app -h

This will print help information.

For convenience, builtin type cli.Helper implements cli.AutoHelper.

So, you just need to inherit it!

type argT struct {
	cli.Helper
}
Validator - validate argument
// Validator validates flag before running command
type Validator interface {
	Validate(*Context) error
}
Context.IsSet

Determin whether the flag is set

Hooks
  • OnRootPrepareError - Function of root command which should be invoked if occur error while prepare period
  • OnBefore - Function which should be invoked before Fn
  • OnRootBefore - Function of root command which should be invoked before Fn
  • OnRootAfter - Function of root command which should be invoked after Fn
  • OnAfter - Function which should be invoked after Fn

Invoked sequence: OnRootPrepareError => OnBefore => OnRootBefore => Fn => OnRootAfter => OnAfter

Don't invoke any hook function if NoHook property of command is true, e.g.

var helpCmd = &cli.Command{
	Name: "help",
	Desc: "balabala...",
	NoHook: true,
	Fn: func(ctx *cli.Context) error { ... },
}
Command tree
// Tree creates a CommandTree
func Tree(cmd *Command, forest ...*CommandTree) *CommandTree

// Root registers forest for root and return root
func Root(root *Command, forest ...*CommandTree) *Command
func log(ctx *cli.Context) error {
	ctx.String("path: `%s`\n", ctx.Path())
	return nil
}
var (
	cmd1  = &cli.Command{Name: "cmd1", Fn: log}
	cmd11 = &cli.Command{Name: "cmd11", Fn: log}
	cmd12 = &cli.Command{Name: "cmd12", Fn: log}

	cmd2   = &cli.Command{Name: "cmd2", Fn: log}
	cmd21  = &cli.Command{Name: "cmd21", Fn: log}
	cmd22  = &cli.Command{Name: "cmd22", Fn: log}
	cmd221 = &cli.Command{Name: "cmd221", Fn: log}
	cmd222 = &cli.Command{Name: "cmd222", Fn: log}
	cmd223 = &cli.Command{Name: "cmd223", Fn: log}
)

root := cli.Root(
	&cli.Command{Name: "tree"},
	cli.Tree(cmd1,
		cli.Tree(cmd11),
		cli.Tree(cmd12),
	),
	cli.Tree(cmd2,
		cli.Tree(cmd21),
		cli.Tree(cmd22,
			cli.Tree(cmd221),
			cli.Tree(cmd222),
			cli.Tree(cmd223),
		),
	),
)

HTTP router

Context implements ServeHTTP method.

func (ctx *Context) ServeHTTP(w http.ResponseWriter, r *http.Request)

Command has two http properties: HTTPMethods and HTTPRouters.

HTTPRouters []string
HTTPMethods []string

Each command have one default router: slashes-separated router path of command. e.g. $app sub1 sub11 has default router /sub1/sub11. The HTTPRouters property will add some new extra routers, it would'nt replace the default router. The HTTPMethods is a string array. It will handle any method if HTTPMethods is empty.

var help = &cli.Command{
	Name:        "help",
	Desc:        "display help",
	CanSubRoute: true,
	HTTPRouters: []string{"/v1/help", "/v2/help"},
	HTTPMethods: []string{"GET", "POST"},

	Fn: cli.HelpCommandFn,
}

NOTE: Must call root command's RegisterHTTP method if you want to use custom HTTPRouters

...
if err := ctx.Command().Root().RegisterHTTP(ctx); err != nil {
	return err
}
return http.ListenAndServe(addr, ctx.Command().Root())
...

Documentation

Overview

Example (Hello)

This is a HelloWorld example

package main

import (
	"github.com/mkideal/cli"
)

type helloT struct {
	cli.Helper
	Name string `cli:"name" usage:"tell me your name" dft:"world"`
	Age  uint8  `cli:"a,age" usage:"tell me your age" dft:"100"`
}

// This is a HelloWorld example
func main() {
	args := []string{"app", "--name=Cliper"}
	cli.RunWithArgs(new(helloT), args, func(ctx *cli.Context) error {
		argv := ctx.Argv().(*helloT)
		ctx.String("Hello, %s! Your age is %d?\n", argv.Name, argv.Age)
		return nil
	})
}
Output:

Hello, Cliper! Your age is 100?

Index

Examples

Constants

View Source
const DefaultEditor = "vim"

Variables

View Source
var ExitError = exitError{}

ExitError is a special error, should be ignored but return

View Source
var GetEditor func() (string, error)

GetEditor sets callback to get editor program

Functions

func Daemon

func Daemon(ctx *Context, successPrefix string) error

Daemon startup app as a daemon process, success if result from stderr has prefix successPrefix

func DaemonResponse

func DaemonResponse(resp string)

func HelpCommandFn

func HelpCommandFn(ctx *Context) error

HelpCommandFn implements buildin help command function

func IsValidCommandName

func IsValidCommandName(commandName string) bool

IsValidCommandName validates name of command

func LaunchEditor

func LaunchEditor(editor string) (content []byte, err error)

func Parse

func Parse(args []string, argv interface{}) error

Parse parses args to object argv

Example (DefaultValue)

This example demonstrates how to use default value

package main

import (
	"os"

	"github.com/mkideal/cli"
)

func main() {
	type argT1 struct {
		Port int `cli:"p,port" usage:"listening port" dft:"8080"`
	}
	type argT2 struct {
		Port int `cli:"p,port" usage:"listening port" dft:"$CLI_TEST_HTTP_PORT"`
	}
	type argT3 struct {
		Port int `cli:"p,port" usage:"listening port" dft:"$CLI_TEST_HTTP_PORT+800"`
	}
	type argT4 struct {
		DevDir string `cli:"dir" usage:"develope directory" dft:"$CLI_TEST_DEV_PARENT_DIR/dev"`
	}

	os.Setenv("CLI_TEST_DEV_PARENT_DIR", "/home")
	os.Setenv("CLI_TEST_HTTP_PORT", "8000")

	for _, tt := range []struct {
		argv interface{}
		args []string
	}{
		{new(argT1), []string{"app"}},
		{new(argT2), []string{"app"}},
		{new(argT3), []string{"app"}},
		{new(argT4), []string{"app"}},
		{new(argT4), []string{"app", "--dir=/dev"}},
	} {
		cli.RunWithArgs(tt.argv, tt.args, func(ctx *cli.Context) error {
			ctx.String("argv=%v\n", ctx.Argv())
			return nil
		})
	}
}
Output:

argv=&{8080}
argv=&{8000}
argv=&{8800}
argv=&{/home/dev}
argv=&{/dev}
Example (ShortAndLongFlagName)

This example demonstrates how to use short and long format flag

package main

import (
	"github.com/mkideal/cli"
)

func main() {
	// argument object
	type argT struct {
		Port int `cli:"p,port" usage:"listening port"`
	}

	for _, args := range [][]string{
		[]string{"app", "-p", "8080"},
		[]string{"app", "-p8081"},
		[]string{"app", "-p=8082"},
		[]string{"app", "--port", "8083"},
		[]string{"app", "--port=8084"},
	} {
		cli.RunWithArgs(&argT{}, args, func(ctx *cli.Context) error {
			argv := ctx.Argv().(*argT)
			ctx.String("port=%d\n", argv.Port)
			return nil
		})
	}
}
Output:

port=8080
port=8081
port=8082
port=8083
port=8084
Example (SliceAndMap)

This example demonstrates to use Slice and Map

package main

import (
	"github.com/mkideal/cli"
)

func main() {
	type argT1 struct {
		Slice []uint32 `cli:"U,u32-slice" usage:"uint32 slice"`
	}
	type argT2 struct {
		Slice []string `cli:"S,str-slice" usage:"string slice"`
	}
	type argT3 struct {
		Slice []bool `cli:"B,bool-slice" usage:"boolean slice"`
	}
	type argT4 struct {
		MapA map[string]int  `cli:"A" usage:"string => int"`
		MapB map[int]int     `cli:"B" usage:"int => int"`
		MapC map[int]string  `cli:"C" usage:"int => string"`
		MapD map[string]bool `cli:"D" usage:"string => bool"`
	}

	for _, tt := range []struct {
		argv interface{}
		args []string
	}{
		{new(argT1), []string{"app", "-U1", "-U2"}},
		{new(argT1), []string{"app", "-U", "1", "-U", "2"}},
		{new(argT1), []string{"app", "--u32-slice", "1", "--u32-slice", "2"}},
		{new(argT2), []string{"app", "-Shello", "-Sworld"}},
		{new(argT2), []string{"app", "-S", "hello", "-S", "world"}},
		{new(argT2), []string{"app", "--str-slice", "hello", "--str-slice", "world"}},
		{new(argT3), []string{"app", "-Btrue", "-Bfalse"}},
		{new(argT3), []string{"app", "-B", "true", "-B", "false"}},
		{new(argT3), []string{"app", "--bool-slice", "true", "--bool-slice", "false"}},

		{new(argT4), []string{"app",
			"-Ax=1",
			"-B", "1=2",
			"-C1=a",
			"-Dx",
		}},
	} {
		cli.RunWithArgs(tt.argv, tt.args, func(ctx *cli.Context) error {
			ctx.String("argv=%v\n", ctx.Argv())
			return nil
		})
	}
}
Output:

argv=&{[1 2]}
argv=&{[1 2]}
argv=&{[1 2]}
argv=&{[hello world]}
argv=&{[hello world]}
argv=&{[hello world]}
argv=&{[true false]}
argv=&{[true false]}
argv=&{[true false]}
argv=&{map[x:1] map[1:2] map[1:a] map[x:true]}

func RegisterFlagParser

func RegisterFlagParser(name string, creator FlagParserCreator)

RegisterFlagParser registers FlagParserCreator by name

Example

This example demonstrates how to use custom parser

package main

import (
	"reflect"

	"github.com/mkideal/cli"
)

type myParser struct {
	ptr interface{}
}

func newMyParser(ptr interface{}) cli.FlagParser {
	return &myParser{ptr}
}

// Parse implements FlagParser.Parse interface
func (parser *myParser) Parse(s string) error {
	typ := reflect.TypeOf(parser.ptr)
	val := reflect.ValueOf(parser.ptr)
	if typ.Kind() == reflect.Ptr {
		kind := reflect.Indirect(val).Type().Kind()
		if kind == reflect.Struct {
			typElem, valElem := typ.Elem(), val.Elem()
			numField := valElem.NumField()
			for i := 0; i < numField; i++ {
				_, valField := typElem.Field(i), valElem.Field(i)
				if valField.Kind() == reflect.Int && valField.CanSet() {
					valField.SetInt(2)
				}
				if valField.Kind() == reflect.String && valField.CanSet() {
					valField.SetString("B")
				}
			}
		}
	}
	return nil
}

type config3 struct {
	A int
	B string
}

// This example demonstrates how to use custom parser
func main() {
	// register parser factory function
	cli.RegisterFlagParser("myparser", newMyParser)

	type argT struct {
		Cfg3 config3 `cli:"cfg3" parser:"myparser"`
	}

	args := []string{"app",
		`--cfg3`, `hello`,
	}

	cli.RunWithArgs(new(argT), args, func(ctx *cli.Context) error {
		ctx.JSON(ctx.Argv())
		return nil
	})
}
Output:

{"Cfg3":{"A":2,"B":"B"}}

func Run

func Run(argv interface{}, fn CommandFunc, descs ...string)

Run runs a single command app

func RunWithArgs

func RunWithArgs(argv interface{}, args []string, fn CommandFunc, descs ...string)

RunWithArgs is similar to Run, but with args instead of os.Args

func SetUsageStyle

func SetUsageStyle(style UsageStyle)

SetUsageStyle sets default style

Types

type Addr deprecated

type Addr struct {
	Host string `cli:"host" usage:"specify host" dft:"0.0.0.0"`
	Port uint16 `cli:"port" usage:"specify port" dft:"8080"`
}

Deprecated: Addr is builtin host,port flag

func (Addr) ToString deprecated

func (addr Addr) ToString() string

Deprecated: ToString ...

type AddrWithShort deprecated

type AddrWithShort struct {
	Host string `cli:"H,host" usage:"specify host" dft:"0.0.0.0"`
	Port uint16 `cli:"p,port" usage:"specify port" dft:"8080"`
}

Deprecated: AddrWithShort is builtin host,port flag contains short flag

func (AddrWithShort) ToString deprecated

func (addr AddrWithShort) ToString() string

Deprecated: ToString ...

type ArgvFunc

type ArgvFunc func() interface{}

ArgvFunc ...

type AutoHelper

type AutoHelper interface {
	AutoHelp() bool
}

AutoHelper represents interface for showing help information automatically

type Command

type Command struct {
	Name    string      // Command name
	Aliases []string    // Command aliases name
	Desc    string      // Command abstract
	Text    string      // Command detail description
	Fn      CommandFunc // Command handler
	Argv    ArgvFunc    // Command argument factory function

	CanSubRoute bool
	NeedArgs    bool
	NoHook      bool
	NoHTTP      bool

	HTTPRouters []string
	HTTPMethods []string

	// hooks for current command
	OnBefore func(*Context) error
	OnAfter  func(*Context) error

	// hooks for all commands if current command is root command
	OnRootPrepareError func(error) error
	OnRootBefore       func(*Context) error
	OnRootAfter        func(*Context) error
	// contains filtered or unexported fields
}

Command is the top-level instance in command-line app

Example
package main

import (
	"github.com/mkideal/cli"
)

func main() {
	root := &cli.Command{
		Name: "app",
	}

	type childT struct {
		S string `cli:"s" usage:"string flag"`
		B bool   `cli:"b" usage:"boolean flag"`
	}
	root.Register(&cli.Command{
		Name:        "child",
		Aliases:     []string{"sub"},
		Desc:        "child command",
		Text:        "detailed description for command",
		Argv:        func() interface{} { return new(childT) },
		CanSubRoute: true,
		NoHook:      true,
		NoHTTP:      true,
		NeedArgs:    true,
		HTTPRouters: []string{"/v1/child", "/v2/child"},
		HTTPMethods: []string{"GET", "POST"},

		OnRootPrepareError: func(err error) error {
			return err
		},
		OnBefore: func(ctx *cli.Context) error {
			ctx.String("OnBefore\n")
			return nil
		},
		OnAfter: func(ctx *cli.Context) error {
			ctx.String("OnAfter\n")
			return nil
		},
		OnRootBefore: func(ctx *cli.Context) error {
			ctx.String("OnRootBefore\n")
			return nil
		},
		OnRootAfter: func(ctx *cli.Context) error {
			ctx.String("OnRootAfter\n")
			return nil
		},

		Fn: func(ctx *cli.Context) error {
			return nil
		},
	})
}
Output:

func HelpCommand

func HelpCommand(desc string) *Command

HelpCommand returns a buildin help command

func Root

func Root(root *Command, forest ...*CommandTree) *Command

Root registers forest for root and return root

func (*Command) ChildrenDescriptions

func (cmd *Command) ChildrenDescriptions(prefix, indent string) string

ChildrenDescriptions returns all children's brief infos by one string

func (*Command) IsClient

func (cmd *Command) IsClient() bool

IsClient returns command whether if run as client

func (*Command) IsServer

func (cmd *Command) IsServer() bool

IsServer returns command whether if run as server

func (*Command) ListChildren

func (cmd *Command) ListChildren() []string

ListChildren returns all names of command children

func (*Command) ListenAndServeHTTP

func (cmd *Command) ListenAndServeHTTP(addr string) error

ListenAndServeHTTP set IsServer flag with true and startup http service

func (*Command) Parent

func (cmd *Command) Parent() *Command

Parent returns command's parent

func (*Command) Path

func (cmd *Command) Path() string

Path returns space-separated command full name

func (*Command) RPC

func (cmd *Command) RPC(httpc *http.Client, ctx *Context) error

RPC runs the command from remote

func (*Command) Register

func (cmd *Command) Register(child *Command) *Command

Register registers a child command

func (*Command) RegisterFunc

func (cmd *Command) RegisterFunc(name string, fn CommandFunc, argvFn ArgvFunc) *Command

RegisterFunc registers handler as child command

func (*Command) RegisterHTTP

func (cmd *Command) RegisterHTTP(ctxs ...*Context) error

RegisterHTTP init HTTPRouters for command

func (*Command) RegisterTree

func (cmd *Command) RegisterTree(forest ...*CommandTree)

RegisterTree registers a command tree

func (*Command) Root

func (cmd *Command) Root() *Command

Root returns command's ancestor

func (*Command) Route

func (cmd *Command) Route(router []string) *Command

Route finds command full matching router

func (*Command) Run

func (cmd *Command) Run(args []string) error

Run runs the command with args

func (*Command) RunWith

func (cmd *Command) RunWith(args []string, writer io.Writer, resp http.ResponseWriter, httpMethods ...string) error

RunWith runs the command with args and writer,httpMethods

func (*Command) Serve

func (cmd *Command) Serve(listeners ...net.Listener) (err error)

Serve set IsServer with true and serve http with listeners

func (*Command) ServeHTTP

func (cmd *Command) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements HTTP handler

func (*Command) SetIsServer

func (cmd *Command) SetIsServer(yes bool)

SetIsServer sets command running mode(server or not)

func (*Command) SubRoute

func (cmd *Command) SubRoute(router []string) (*Command, int)

SubRoute finds command partial matching router

func (*Command) Suggestions

func (cmd *Command) Suggestions(path string) []string

Suggestions returns all similar commands

func (*Command) Usage

func (cmd *Command) Usage(ctx *Context) string

Usage returns the usage string of command

type CommandFunc

type CommandFunc func(*Context) error

CommandFunc ...

type CommandTree

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

CommandTree represents a tree of commands

func Tree

func Tree(cmd *Command, forest ...*CommandTree) *CommandTree

Tree creates a CommandTree

type Context

type Context struct {
	HTTPRequest  *http.Request
	HTTPResponse http.ResponseWriter
	// contains filtered or unexported fields
}

Context provides running context

func (*Context) Args

func (ctx *Context) Args() []string

Args returns free args `./app hello world -a=1 abc xyz` will return ["abc" "xyz"]

func (*Context) Argv

func (ctx *Context) Argv() interface{}

Argv returns parsed args object

func (*Context) Color

func (ctx *Context) Color() *color.Color

Color returns color instance

func (*Context) Command

func (ctx *Context) Command() *Command

Command returns current command instance

func (*Context) FormValues

func (ctx *Context) FormValues() url.Values

FormValues returns parsed args as url.Values

func (*Context) IsSet

func (ctx *Context) IsSet(flag string, aliasFlags ...string) bool

IsSet determins whether `flag` is set

func (*Context) JSON

func (ctx *Context) JSON(obj interface{}) *Context

JSON writes json string of obj to writer

func (*Context) JSONIndent

func (ctx *Context) JSONIndent(obj interface{}, prefix, indent string) *Context

JSONIndent writes pretty json string of obj to writer

func (*Context) JSONIndentln

func (ctx *Context) JSONIndentln(obj interface{}, prefix, indent string) *Context

JSONIndentln writes pretty json string of obj end with "\n" to writer

func (*Context) JSONln

func (ctx *Context) JSONln(obj interface{}) *Context

JSONln writes json string of obj end with "\n" to writer

func (*Context) NArg

func (ctx *Context) NArg() int

NArg returns length of Args

func (*Context) NativeArgs

func (ctx *Context) NativeArgs() []string

NativeArgs returns native args `./app hello world -a --xyz=1` will return ["-a" "--xyz=1"]

func (*Context) Path

func (ctx *Context) Path() string

Path returns full command name `./app hello world -a --xyz=1` will returns "hello world"

func (*Context) Router

func (ctx *Context) Router() []string

Router returns full command name with string array `./app hello world -a --xyz=1` will returns ["hello" "world"]

func (*Context) String

func (ctx *Context) String(format string, args ...interface{}) *Context

String writes formatted string to writer

func (*Context) Usage

func (ctx *Context) Usage() string

Usage returns current command's usage with current context

func (*Context) Write

func (ctx *Context) Write(data []byte) (n int, err error)

Write implements io.Writer

func (*Context) WriteUsage

func (ctx *Context) WriteUsage()

WriteUsage writes usage to writer

func (*Context) Writer

func (ctx *Context) Writer() io.Writer

Writer returns writer

type Decoder

type Decoder interface {
	Decode(s string) error
}

type Encoder

type Encoder interface {
	Encode() string
}

type FlagParser

type FlagParser interface {
	Parse(s string) error
}

FlagParser represents a parser for parsing flag

Example

This example demonstrates how to use builtin praser(json,jsonfile)

package main

import (
	"io/ioutil"
	"os"

	"github.com/mkideal/cli"
)

type config1 struct {
	A string
	B int
}

type config2 struct {
	C string
	D bool
}

// This example demonstrates how to use builtin praser(json,jsonfile)
func main() {
	type argT struct {
		Cfg1 config1 `cli:"cfg1" parser:"json"`
		Cfg2 config2 `cli:"cfg2" parser:"jsonfile"`
	}
	jsonfile := "1.json"
	args := []string{"app",
		`--cfg1`, `{"A": "hello", "B": 2}`,
		`--cfg2`, jsonfile,
	}
	ioutil.WriteFile(jsonfile, []byte(`{"C": "world", "D": true}`), 0644)
	defer os.Remove(jsonfile)

	cli.RunWithArgs(new(argT), args, func(ctx *cli.Context) error {
		ctx.JSON(ctx.Argv())
		return nil
	})
}
Output:

{"Cfg1":{"A":"hello","B":2},"Cfg2":{"C":"world","D":true}}

type FlagParserCreator

type FlagParserCreator func(ptr interface{}) FlagParser

FlagParserCreator represents factory function of FlagParser

type Helper

type Helper struct {
	Help bool `cli:"!h,help" usage:"display help information"`
}

Helper is builtin Help flag

func (Helper) AutoHelp

func (h Helper) AutoHelp() bool

AutoHelp implements AutoHelper interface

type JSONFileParser

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

JSON file parser

func (JSONFileParser) Parse

func (p JSONFileParser) Parse(s string) error

type JSONParser

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

JSON parser

func (JSONParser) Parse

func (p JSONParser) Parse(s string) error

type UsageStyle

type UsageStyle int32

UsageStyle is style of usage

const (
	// NormalStyle : left-right
	NormalStyle UsageStyle = iota
	// ManualStyle : up-down
	ManualStyle
)

func GetUsageStyle

func GetUsageStyle() UsageStyle

GetUsageStyle gets default style

type Validator

type Validator interface {
	Validate(*Context) error
}

Validator validates flag before running command

Jump to

Keyboard shortcuts

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