commandlinetool

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

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 9 Imported by: 0

README

集成pfalg、viper、cobra的命令行构建工具

注意:本app命令行构建器是github.com/marmotedu/iam项目的/pkg/app包的缩水版本

之所以是缩水版本,是因为我做了一些功能的删减,

这个命令行构建工具是我学习go的尝试,建议去观看github.com/marmotedu/iam项目的/pkg/app包。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetConfigIn

func SetConfigIn(configFile string)

Types

type AppCli

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

func NewAppCli

func NewAppCli(basename, name string, opts ...Option) *AppCli

func (*AppCli) Run

func (ac *AppCli) Run()

Run 开启运行命令行程序

type AppFlagSets

type AppFlagSets struct {
	FlagSets map[string]*pflag.FlagSet
}

AppFlagSets 存放app各子命令行的FlagSet

func (*AppFlagSets) FlagSet

func (fs *AppFlagSets) FlagSet(name string) *pflag.FlagSet

FlagSet 返回指定名称的FlagSet

type CliOptions

type CliOptions interface {
	// Flags() add pflag
	Flags() (fss AppFlagSets)
	// 验证
	Validate() []error
}

CliOptions 抽象用于从命令行读取参数的配置选项。

type Command

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

func (*Command) AddCommand

func (c *Command) AddCommand(cmd *Command)

AddCommand 添加子命令行

func (*Command) AddCommands

func (c *Command) AddCommands(cmds ...*Command)

func (*Command) BuildCobraCommand

func (c *Command) BuildCobraCommand() *cobra.Command

BuildCobraCommand 构建命令行及其子命令行

type CommandOption

type CommandOption func(*Command)

type CompleteableOptions

type CompleteableOptions interface {
	Complete() error
}

CompleteableOptions 抽象可以完成/编译的options

type ConfigurableOptions

type ConfigurableOptions interface {
	ApplyFlags() []error
}

ConfigurableOptions 抽象用于从配置文件读取参数的配置选项。

type Option

type Option func(*AppCli)

func WithConfig

func WithConfig(noConfig bool) Option

func WithDescription

func WithDescription(desc string) Option

func WithOptions

func WithOptions(opt CliOptions) Option

func WithRunFunc

func WithRunFunc(run RunFunc) Option

type PrintableOptions

type PrintableOptions interface {
	String() string
}

PrintableOptions 抽象可以打印的options

type RunCommandFunc

type RunCommandFunc func(args []string) error

RunCommandFunc 相关的 action

type RunFunc

type RunFunc func(basename string) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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