From 3ae774c1fab5f9851d582df7dad09293fa8d1396 Mon Sep 17 00:00:00 2001 From: Volker Schukai <volker.schukai@schukai.com> Date: Wed, 19 Oct 2022 11:35:08 +0200 Subject: [PATCH] fix remove tag for command #4 --- command.go | 2 +- go.mod | 6 ++++-- go.sum | 2 ++ issue-4_test.go | 30 ++++++++++++++++++++++++++++++ setting_test.go | 2 +- 5 files changed, 38 insertions(+), 4 deletions(-) create mode 100644 issue-4_test.go diff --git a/command.go b/command.go index 37721f9..eccb273 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 4cc393e..c6ea543 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 f41749f..e89a2d3 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 0000000..a935041 --- /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 699ced4..3e058b9 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)) } -- GitLab