diff --git a/api_test.go b/api_test.go index 2ec6c88084153bc9955ed4d314d277b9f78ae568..dc7adc98f438a0680c492662aea648445054ff28 100644 --- a/api_test.go +++ b/api_test.go @@ -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) diff --git a/execute_test.go b/execute_test.go index a6ecbb40462261134eda37a1805cafb486bb9c21..2625eb73697b2282eb1a074633d23f20f9423f49 100644 --- a/execute_test.go +++ b/execute_test.go @@ -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, }, } diff --git a/integration_test.go b/integration_test.go index 3021bb7177d2aa73204f3bf352d7f018de469ccd..b7ff83ef9634074ae55b16385874641e6c01e2cf 100644 --- a/integration_test.go +++ b/integration_test.go @@ -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) diff --git a/parse.go b/parse.go index bdee7a15c89e011e81fcd174feb8023f83e2fe08..24c0e26b935144aa3c2e00eb657f1248e3b16383 100644 --- a/parse.go +++ b/parse.go @@ -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 diff --git a/readme_test.go b/readme_test.go index c1554ba82185a058edbf4ca7ec7ff6360c34aba5..57e774bfce3e1970f3189f1ee299171a132e8672 100644 --- a/readme_test.go +++ b/readme_test.go @@ -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()) diff --git a/shadow_test.go b/shadow_test.go index 8418e16e91571d843ca4975ef23204f1b18e6cec..debcc1b4e679179078ea054e35034cbcfda1b600 100644 --- a/shadow_test.go +++ b/shadow_test.go @@ -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)