Skip to content

Commit

Permalink
panic on addArg failure, and tests to check it (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
goofinator authored and akamensky committed Jan 21, 2020
1 parent 112b813 commit 48862cb
Show file tree
Hide file tree
Showing 3 changed files with 410 additions and 29 deletions.
44 changes: 33 additions & 11 deletions argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ func (o *Command) Flag(short string, long string, opts *Options) *bool {
unique: true,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add Flag: %s", err.Error()))
}

return &result
}
Expand All @@ -183,7 +185,9 @@ func (o *Command) FlagCounter(short string, long string, opts *Options) *int {
unique: false,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add FlagCounter: %s", err.Error()))
}

return &result
}
Expand All @@ -203,7 +207,9 @@ func (o *Command) String(short string, long string, opts *Options) *string {
unique: true,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add String: %s", err.Error()))
}

return &result
}
Expand All @@ -224,7 +230,9 @@ func (o *Command) Int(short string, long string, opts *Options) *int {
unique: true,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add Int: %s", err.Error()))
}

return &result
}
Expand All @@ -245,7 +253,9 @@ func (o *Command) Float(short string, long string, opts *Options) *float64 {
unique: true,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add Float: %s", err.Error()))
}

return &result
}
Expand All @@ -271,7 +281,9 @@ func (o *Command) File(short string, long string, flag int, perm os.FileMode, op
filePerm: perm,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add File: %s", err.Error()))
}

return &result
}
Expand Down Expand Up @@ -300,7 +312,9 @@ func (o *Command) StringList(short string, long string, opts *Options) *[]string
unique: false,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add StringList: %s", err.Error()))
}

return &result
}
Expand All @@ -321,7 +335,9 @@ func (o *Command) IntList(short string, long string, opts *Options) *[]int {
unique: false,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add IntList: %s", err.Error()))
}

return &result
}
Expand All @@ -342,7 +358,9 @@ func (o *Command) FloatList(short string, long string, opts *Options) *[]float64
unique: false,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add FloatList: %s", err.Error()))
}

return &result
}
Expand All @@ -365,7 +383,9 @@ func (o *Command) FileList(short string, long string, flag int, perm os.FileMode
filePerm: perm,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add FileList: %s", err.Error()))
}

return &result
}
Expand All @@ -389,7 +409,9 @@ func (o *Command) Selector(short string, long string, options []string, opts *Op
selector: &options,
}

o.addArg(a)
if err := o.addArg(a); err != nil {
panic(fmt.Errorf("unable to add Selector: %s", err.Error()))
}

return &result
}
Expand Down
Loading

0 comments on commit 48862cb

Please sign in to comment.