This commit is contained in:
Mario Hros 2017-03-30 20:47:59 +02:00
parent 58e62faa3d
commit 992acaf408
2 changed files with 50 additions and 0 deletions

View File

@ -250,6 +250,15 @@ func TestRequiredPositional(t *testing.T) {
assert.Error(t, err)
}
func TestRequiredPositionalMultiple(t *testing.T) {
var args struct {
Input string `arg:"positional"`
Multiple []string `arg:"positional,required"`
}
err := parse("foo", &args)
assert.Error(t, err)
}
func TestTooManyPositional(t *testing.T) {
var args struct {
Input string `arg:"positional"`
@ -270,6 +279,17 @@ func TestMultiple(t *testing.T) {
assert.Equal(t, []string{"x", "y", "z"}, args.Bar)
}
func TestMultiplePositionals(t *testing.T) {
var args struct {
Input string `arg:"positional"`
Multiple []string `arg:"positional,required"`
}
err := parse("foo a b c", &args)
assert.NoError(t, err)
assert.Equal(t, "foo", args.Input)
assert.Equal(t, []string{"a", "b", "c"}, args.Multiple)
}
func TestMultipleWithEq(t *testing.T) {
var args struct {
Foo []int
@ -321,6 +341,14 @@ func TestMissingRequired(t *testing.T) {
assert.Error(t, err)
}
func TestMissingRequiredMultiplePositional(t *testing.T) {
var args struct {
X []string `arg:"positional, required"`
}
err := parse("x", &args)
assert.Error(t, err)
}
func TestMissingValue(t *testing.T) {
var args struct {
Foo string

View File

@ -157,3 +157,25 @@ Options:
t.Fail()
}
}
func TestRequiredMultiplePositionals(t *testing.T) {
expectedHelp := `Usage: example REQUIREDMULTIPLE [REQUIREDMULTIPLE ...]
Positional arguments:
REQUIREDMULTIPLE required multiple positional
Options:
--help, -h display this help and exit
`
var args struct {
RequiredMultiple []string `arg:"positional,required,help:required multiple positional"`
}
p, err := NewParser(Config{}, &args)
require.NoError(t, err)
os.Args[0] = "example"
var help bytes.Buffer
p.WriteHelp(&help)
assert.Equal(t, expectedHelp, help.String())
}