This commit is contained in:
Andrey Parhomenko 2023-03-24 19:35:14 +03:00
parent c382bc403f
commit 3199e25c38

View file

@ -10,6 +10,8 @@ import(
type Flags struct { type Flags struct {
*flag.FlagSet *flag.FlagSet
progName string
utilName string
args []string args []string
parsedArgs []string parsedArgs []string
} }
@ -32,6 +34,14 @@ func (flags *Flags) Args() []string {
return flags.parsedArgs return flags.parsedArgs
} }
func (flags *Flags) ProgName() string {
return flags.progName
}
func (flags *Flags) UtilName() string {
return flags.utilName
}
func Main(name string, m Tools) { func Main(name string, m Tools) {
var( var(
utilName string utilName string
@ -75,9 +85,7 @@ func Main(name string, m Tools) {
arg1 := os.Args[1] arg1 := os.Args[1]
flagSet := flag.NewFlagSet(arg1, flag.ExitOnError) flagSet := flag.NewFlagSet(arg1, flag.ExitOnError)
flags := &Flags{ flags := &Flags{
flagSet, FlagSet : flagSet,
[]string{},
[]string{},
} }
flags.Usage = func() { flags.Usage = func() {
out := flags.Output() out := flags.Output()
@ -115,6 +123,8 @@ func Main(name string, m Tools) {
os.Exit(1) os.Exit(1)
} }
flags.progName = name
flags.utilName = args[0]
flags.args = args[1:] flags.args = args[1:]
util.Handler(flags) util.Handler(flags)