utils for command line app
Go to file
程广 74e7586c36 reorg code and add Readme 2024-11-16 15:19:59 +08:00
.vscode commplete Command style 2024-11-16 15:15:27 +08:00
example reorg code and add Readme 2024-11-16 15:19:59 +08:00
.gitignore Initial commit 2024-10-21 23:21:46 +08:00
LICENSE Initial commit 2024-10-21 23:21:46 +08:00
README.md reorg code and add Readme 2024-11-16 15:19:59 +08:00
command.go commplete Command style 2024-11-16 15:15:27 +08:00
flag.go remove --help 2024-11-15 15:10:05 +08:00
flag_test.go add case 2024-10-24 07:15:25 +08:00
go.mod add help to flag set 2024-11-15 13:17:19 +08:00
usage.go add case 2024-10-24 07:15:25 +08:00

README.md

command

utils for command line app

Provide two style for command line args parse:

  • use struct field tag
  • use command

Usage

use struct field tag

type targs struct {
	Test     string `flag_default:"test" flag_usage:"this is test"`
	TestBool bool   `flag_short:"b"`
	TestInt  int
}
	sargs := &targs{}
	v, _ := NewFVSet(sargs)
	v.Usage()
	err := Parse([]string{"--test", "test", "--test-bool", "--test-int", "1"}, v)

use command style

package main

import (
	"fmt"
	"os"

	"git.pyer.club/kingecg/command"
)

func main() {
	var cmd = command.NewCommand("test", "test command")
	cmd.AddArg("arg1", "a", "arg1 description", "default value")
	cmd.AddArg("arg2", "b", "arg2 description", "default value")
	cmd.AddSubCommand("sub1", "sub1 description")
	cmd.Parse(os.Args[1:])
	fmt.Println(cmd.GetGlobalOptions())
}