Skip to content

Commit

Permalink
增加注释
Browse files Browse the repository at this point in the history
  • Loading branch information
ShizheChang committed Mar 14, 2024
1 parent 5a26a42 commit 2d898c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
21 changes: 17 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,35 @@ type cmd struct {
version string
}

/*
*
args:参数列表
*/
func (c *cmd) Execute(args []string) {
//app.run:启动实例
if err := c.app.Run(args); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func newCmd() *cmd {
//vfox的运行版本
version := internal.RuntimeVersion
cli.VersionFlag = &cli.BoolFlag{
Name: "version",
//当前cli程序的“名字”
Name: "version",
//别名,可以接受多个对象
Aliases: []string{"v", "V"},
Usage: "print version",
//此程序的简介
Usage: "print version",
//当未使用子命令时,此程序要进行的动作。其值应当为一个 cli.ActionFunc 函数
Action: func(ctx *cli.Context, b bool) error {
println(version)
return nil
},
}

//声明app的各种参数及行为
app := &cli.App{}
app.EnableBashCompletion = true
app.Name = "vfox"
Expand All @@ -62,7 +72,9 @@ func newCmd() *cmd {
app.Copyright = "Copyright 2024 Han Li. All rights reserved."
app.Version = version
app.Description = "vfox is a cross-platform version manager, extendable via plugins. It allows you to quickly install and switch between different environment you need via the command line."
//启用命令和标志的建议
app.Suggest = true
//设置 shell 完成标志时要执行的操作
app.BashComplete = func(ctx *cli.Context) {
for _, command := range ctx.App.Commands {
_, _ = fmt.Fprintln(ctx.App.Writer, command.Name)
Expand All @@ -77,10 +89,11 @@ func newCmd() *cmd {
return nil
},
}

//标志列表
app.Flags = []cli.Flag{
debugFlags,
}
//可执行的命令/动作/行为列表
app.Commands = []*cli.Command{
commands.Info,
commands.Install,
Expand Down
2 changes: 1 addition & 1 deletion godemo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ func TestOsArgs(t *testing.T) {
args := os.Args
for i := 0; i < len(args); i++ {
arg := args[i]
println("the args on the No." + string(i))
println("//")
println(arg)
}
}

0 comments on commit 2d898c8

Please sign in to comment.