app

package
v0.0.0-...-6a757b2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2023 License: MIT Imports: 7 Imported by: 36

README

app 命令行工具 APP 结构

Documentation

Index

Constants

This section is empty.

Variables

View Source
var HelpModuleCmd = "help"
View Source
var OsEnv = NewPrefixEnv("")
View Source
var RegisteredModules = NewModules()

Functions

func Register

func Register(m Module)

Types

type AppEnv

type AppEnv interface {
	Getenv(string) string
	Setenv(string, string) error
}

type Application

type Application struct {
	Config        *ApplicationConfig
	Args          []string
	Env           AppEnv
	Cwd           string
	Modules       *Modules
	Stdout        io.Writer
	Stdin         io.Reader
	FlagDefaults  string
	HelpModuleCmd string
}

func NewApplication

func NewApplication(config *ApplicationConfig) *Application

func (*Application) Getenv

func (a *Application) Getenv(key string) string

func (*Application) Print

func (a *Application) Print(args ...interface{}) (n int, err error)

func (*Application) PrintModuleHelp

func (a *Application) PrintModuleHelp(m Module)

func (*Application) Printf

func (a *Application) Printf(format string, args ...interface{}) (n int, err error)

func (*Application) Println

func (a *Application) Println(args ...interface{}) (n int, err error)

func (*Application) Run

func (a *Application) Run()

func (*Application) Setenv

func (a *Application) Setenv(key string, value string) error

func (*Application) ShowIntro

func (a *Application) ShowIntro() error

type ApplicationConfig

type ApplicationConfig struct {
	Name          string
	Cmd           string
	Version       string
	IntroTemplate string
}

func NewApplicationConfig

func NewApplicationConfig() *ApplicationConfig

type BasicModule

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

func (*BasicModule) Cmd

func (m *BasicModule) Cmd() string

func (*BasicModule) Desc

func (m *BasicModule) Desc(a *Application) string

func (*BasicModule) Exec

func (m *BasicModule) Exec(a *Application, args []string) error

func (*BasicModule) FlagSet

func (m *BasicModule) FlagSet() *flag.FlagSet

func (*BasicModule) Group

func (m *BasicModule) Group(a *Application) string

func (*BasicModule) Help

func (m *BasicModule) Help(a *Application) string

func (*BasicModule) ID

func (m *BasicModule) ID() string

func (*BasicModule) Reset

func (m *BasicModule) Reset()

type Module

type Module interface {
	ID() string
	Cmd() string
	Help(a *Application) string
	Desc(a *Application) string
	Group(a *Application) string
	FlagSet() *flag.FlagSet
	Exec(a *Application, args []string) error
}

type Modules

type Modules []Module

func NewModules

func NewModules() *Modules

func (*Modules) Add

func (modules *Modules) Add(m Module)

func (*Modules) Get

func (modules *Modules) Get(cmd string) Module

type PrefixEnv

type PrefixEnv struct {
	Prefix string
}

func NewPrefixEnv

func NewPrefixEnv(prefix string) *PrefixEnv

func (*PrefixEnv) Getenv

func (e *PrefixEnv) Getenv(key string) string

func (*PrefixEnv) Setenv

func (e *PrefixEnv) Setenv(key string, value string) error

type PresetEnv

type PresetEnv map[string]string

func (PresetEnv) Getenv

func (e PresetEnv) Getenv(key string) string

func (PresetEnv) Setenv

func (e PresetEnv) Setenv(key string, value string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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