Skip to content
Snippets Groups Projects
Verified Commit 3b941206 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

fix parse only the arguments and not the programm

parent 549bb819
No related branches found
No related tags found
No related merge requests found
......@@ -43,7 +43,7 @@ type CmdTest1 struct {
func TestCommand2(t *testing.T) {
commands := New("root", CmdTest1{})
args := []string{"root", "-a", "sub1", "-b", "sub2", "-c", "sub3", "-d"}
args := []string{"-a", "sub1", "-b", "sub2", "-c", "sub3", "-d"}
commands.Parse(args)
......
......@@ -48,16 +48,16 @@ func TestExec(t *testing.T) {
tests := []testExecutionTestCases[testExecutionStruct]{
{
name: "test",
args: []string{"test", "command1", "-c"},
args: []string{"command1", "-c"},
targetValue: 1,
},
{
name: "test",
args: []string{"test", "command1", "command2", "-e"},
args: []string{"command1", "command2", "-e"},
targetValue: 2,
}, {
name: "test",
args: []string{"test", "-a", "command3"},
args: []string{"-a", "command3"},
targetValue: 1,
},
}
......
......@@ -24,7 +24,7 @@ func TestIntegrationError(t *testing.T) {
tests := []testIntegrationTestCases[testIntegrationStruct]{
{
name: "test",
args: []string{"test2", "-a"},
args: []string{"-a"},
errors: []string{
"flag provided but not defined: -a",
},
......@@ -60,8 +60,8 @@ func TestIntegration(t *testing.T) {
tests := []testIntegrationTestCases[testIntegrationStruct]{
{
name: "test",
args: []string{"test"},
test: func(s *setting[testIntegrationStruct]) {
args: []string{},
test: func(s *Settings[testIntegrationStruct]) {
v := s.GetValues()
assert.NotNil(t, v)
assert.IsType(t, testIntegrationStruct{}, v)
......@@ -71,8 +71,8 @@ func TestIntegration(t *testing.T) {
},
{
name: "test",
args: []string{"test", "-v"},
test: func(s *setting[testIntegrationStruct]) {
args: []string{"-v"},
test: func(s *Settings[testIntegrationStruct]) {
v := s.GetValues()
assert.NotNil(t, v)
assert.IsType(t, testIntegrationStruct{}, v)
......@@ -82,29 +82,29 @@ func TestIntegration(t *testing.T) {
},
{
name: "test",
args: []string{"test", "--verbose"},
test: func(s *setting[testIntegrationStruct]) {
args: []string{"--verbose"},
test: func(s *Settings[testIntegrationStruct]) {
assert.True(t, s.GetValues().Verbose)
},
},
{
name: "test",
args: []string{"test", "-verbose"},
test: func(s *setting[testIntegrationStruct]) {
args: []string{"-verbose"},
test: func(s *Settings[testIntegrationStruct]) {
assert.True(t, s.GetValues().Verbose)
},
},
{
name: "test",
args: []string{"test", "sub1"},
test: func(s *setting[testIntegrationStruct]) {
args: []string{"sub1"},
test: func(s *Settings[testIntegrationStruct]) {
assert.False(t, s.GetValues().Verbose)
},
},
}
for _, tt := range tests {
t.Run(tt.args[0], func(t *testing.T) {
t.Run(tt.name, func(t *testing.T) {
settings := New(tt.name, testIntegrationStruct{})
assert.NotNil(t, settings)
......
......@@ -18,7 +18,7 @@ func (s *setting[C]) Parse(args []string) *setting[C] {
return s
}
err := s.command.flagSet.Parse(args[1:])
err := s.command.flagSet.Parse(args)
if err != nil {
s.errors = append(s.errors, err)
return s
......
......@@ -13,13 +13,13 @@ type Definition struct {
} `command:"serve" description:"Run the HTTP server" call:"DoServe"`
}
func (d *Definition) DoServe(_ *setting[Definition]) {
func (d *Definition) DoServe(_ *Settings[Definition]) {
// do something
}
func TestReadMeInit(t *testing.T) {
setting := New("test", Definition{})
setting.Parse([]string{"test", "-v", "serve", "-h", "localhost", "-p", "8080"})
setting.Parse([]string{"-v", "serve", "-h", "localhost", "-p", "8080"})
setting.Execute()
assert.True(t, setting.definitions.Verbose)
assert.False(t, setting.HasErrors())
......
......@@ -35,7 +35,7 @@ func TestFlagCopyToShadow(t *testing.T) {
settings.SetShadow(&c)
assert.False(t, settings.HasErrors())
settings.Parse([]string{"test", "-a", "command1", "-d"})
settings.Parse([]string{"-a", "command1", "-d"})
assert.True(t, c.ValGlobal1)
assert.True(t, c.ValCommand1Flag2)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment