refactor: embed *flag.FlagSet
Embed *flag.FlagSet directly into the subcommand types.
This commit is contained in:
parent
cee274318d
commit
b9dbdb2c61
2 changed files with 8 additions and 24 deletions
18
generate.go
18
generate.go
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
type GenerateCommand struct {
|
||||
fs *flag.FlagSet
|
||||
*flag.FlagSet
|
||||
input string
|
||||
output string
|
||||
employmentHistory int
|
||||
|
@ -24,24 +24,16 @@ type GenerateCommand struct {
|
|||
|
||||
func NewGenerateCommand() *GenerateCommand {
|
||||
gc := GenerateCommand{
|
||||
fs: flag.NewFlagSet("generate", flag.ExitOnError),
|
||||
FlagSet: flag.NewFlagSet("generate", flag.ExitOnError),
|
||||
}
|
||||
|
||||
gc.fs.StringVar(&gc.input, "input", "", "specify the CV JSON file that you want to input to the builder.")
|
||||
gc.fs.StringVar(&gc.output, "output", "", "specify the name of the output CV file.")
|
||||
gc.fs.IntVar(&gc.employmentHistory, "employment-history", 10, "show employment history within these number of years.")
|
||||
gc.StringVar(&gc.input, "input", "", "specify the CV JSON file that you want to input to the builder.")
|
||||
gc.StringVar(&gc.output, "output", "", "specify the name of the output CV file.")
|
||||
gc.IntVar(&gc.employmentHistory, "employment-history", 10, "show employment history within these number of years.")
|
||||
|
||||
return &gc
|
||||
}
|
||||
|
||||
func (g *GenerateCommand) Parse(args []string) error {
|
||||
return g.fs.Parse(args)
|
||||
}
|
||||
|
||||
func (g *GenerateCommand) Name() string {
|
||||
return g.fs.Name()
|
||||
}
|
||||
|
||||
func (g *GenerateCommand) Run() error {
|
||||
historyLimit := time.Now().AddDate(-1*g.employmentHistory, 0, 0)
|
||||
|
||||
|
|
14
version.go
14
version.go
|
@ -6,7 +6,7 @@ import (
|
|||
)
|
||||
|
||||
type VersionCommand struct {
|
||||
fs *flag.FlagSet
|
||||
*flag.FlagSet
|
||||
fullVersion bool
|
||||
}
|
||||
|
||||
|
@ -19,22 +19,14 @@ var (
|
|||
|
||||
func NewVersionCommand() *VersionCommand {
|
||||
vc := VersionCommand{
|
||||
fs: flag.NewFlagSet("version", flag.ExitOnError),
|
||||
FlagSet: flag.NewFlagSet("version", flag.ExitOnError),
|
||||
}
|
||||
|
||||
vc.fs.BoolVar(&vc.fullVersion, "full", false, "prints the full version")
|
||||
vc.BoolVar(&vc.fullVersion, "full", false, "prints the full version")
|
||||
|
||||
return &vc
|
||||
}
|
||||
|
||||
func (v *VersionCommand) Parse(args []string) error {
|
||||
return v.fs.Parse(args)
|
||||
}
|
||||
|
||||
func (v *VersionCommand) Name() string {
|
||||
return v.fs.Name()
|
||||
}
|
||||
|
||||
func (v *VersionCommand) Run() error {
|
||||
var version string
|
||||
if v.fullVersion {
|
||||
|
|
Loading…
Reference in a new issue