diff --git a/command.go b/command.go index 37721f9362a0c346ceb33a486143366d4f986d52..eccb273808a880859a35c9d138e63dd8f0197504 100644 --- a/command.go +++ b/command.go @@ -163,7 +163,7 @@ func (c *cmd[C]) parseStruct(dta any) { } c.initFlags(x, m) } else if m[tagCommand] != "" { - c.tagMapping[m[tagCommand]] = v.Type().Field(i).Name + //c.tagMapping["cmd"+m[tagCommand]] = v.Type().Field(i).Name c.initCommands(x, m, v.Type().Field(i).Name) } else if m[tagIgnore] != "" { diff --git a/go.mod b/go.mod index 4cc393e3a414d80083df9df70e2b8f007ed19194..c6ea543eaa48e87d57f5f28a082a285b55f290d2 100644 --- a/go.mod +++ b/go.mod @@ -2,12 +2,14 @@ module gitlab.schukai.com/oss/libraries/go/application/xflags go 1.19 -require github.com/stretchr/testify v1.8.0 +require ( + github.com/stretchr/testify v1.8.0 + gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.1 +) require ( github.com/agnivade/levenshtein v1.1.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index f41749f6d814c2f5ecabba782362c1b9309d1734..e89a2d3c0884e5eb4d5eeaffd96e604a8c92f1f3 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,8 @@ github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PK github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.0 h1:mSxk2q/npskmHMmw1oF4moccjGav5dL6qmff2njUV7A= gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.0/go.mod h1:UvdD4NAf3gLKYafabJD7e9ZCOetzM9JZ9y4GkZukPVU= +gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.1 h1:oyElaqEiyr2XgaE1CYwD8LoeHsuR/vQD/p6k3jYbJFs= +gitlab.schukai.com/oss/libraries/go/utilities/pathfinder v0.3.1/go.mod h1:UvdD4NAf3gLKYafabJD7e9ZCOetzM9JZ9y4GkZukPVU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/issue-4_test.go b/issue-4_test.go new file mode 100644 index 0000000000000000000000000000000000000000..a9350419982ac34569a70df4a1286361b9166a12 --- /dev/null +++ b/issue-4_test.go @@ -0,0 +1,30 @@ +// Copyright 2022 schukai GmbH +// SPDX-License-Identifier: AGPL-3.0 + +package xflags + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +type testConfigCommandIssue4 struct { +} + +type testCmdStructIssue4 struct { + ConfigPath string `long:"config" short:"c" description:"Path to configuration file"` + Config testConfigCommandIssue4 `command:"config" description:"Config commands"` +} + +// TestIssue4 tests the issue #4. +func TestIssue4B(t *testing.T) { + + s := New("test", testCmdStructIssue4{}) + s.Parse([]string{"--config", "config"}) + + assert.Equal(t, s.HasErrors(), false) + if s.HasErrors() { + t.Log(s.Errors()) + } + +} diff --git a/setting_test.go b/setting_test.go index 699ced4b29712879c9b1405e3a86984900e7190f..3e058b98df53ed19355da3a98ea7255bc7dd017c 100644 --- a/setting_test.go +++ b/setting_test.go @@ -24,5 +24,5 @@ func TestInitCommands(t *testing.T) { assert.Equal(t, 0, len(s.errors)) assert.Equal(t, "test", s.command.name) assert.Equal(t, 1, len(s.command.commands)) - assert.Equal(t, 3, len(s.command.tagMapping)) + assert.Equal(t, 2, len(s.command.tagMapping)) }