api-base/pkg/args/args.go

37 lines
625 B
Go
Raw Normal View History

2020-08-03 12:19:47 +00:00
package args
import (
2020-08-15 17:21:27 +00:00
"errors"
2020-08-03 12:19:47 +00:00
"os"
"git.trj.tw/golang/argparse"
)
type Args struct {
ConfigPath string
DBTool bool
Run string
}
var a *Args
func Parse() error {
a = &Args{}
parser := argparse.New()
parser.StringVar(&a.ConfigPath, "", "c", "config", "config file path", nil)
parser.StringVar(&a.Run, "server", "r", "run", "run mode [server, dbtool], default server", nil)
parser.BoolVar(&a.DBTool, false, "d", "dbtool", "run db migration", nil)
parser.Help("h", "help")
return parser.Parse(os.Args)
}
2020-08-15 17:21:27 +00:00
func Get() *Args {
if a == nil {
panic(errors.New("arguments not init"))
}
return a
}