Skip to content

Commit

Permalink
refine: remove assignedCount method
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian authored and yndu13 committed Nov 21, 2023
1 parent 5516f5e commit 8e5d20a
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 34 deletions.
12 changes: 0 additions & 12 deletions cli/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,15 +282,3 @@ func (f *Flag) checkFields() error {
}
return nil
}

//func (f *Flag) useDefaultValue() bool {
// if f.DefaultValue != "" {
// f.value = f.DefaultValue
// if f.p != nil {
// *f.p = f.DefaultValue
// }
// return true
// } else {
// return false
// }
//}
11 changes: 0 additions & 11 deletions cli/flag_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,17 +101,6 @@ func (fs *FlagSet) GetValue(name string) (string, bool) {
return f.GetValue()
}

// get assigned count for flags
func (fs *FlagSet) assignedCount() int {
n := 0
for _, f := range fs.flags {
if f.assigned {
n++
}
}
return n
}

// merge FlagSet with from
func (fs *FlagSet) mergeWith(from *FlagSet, applier func(f *Flag) bool) *FlagSet {
if from == nil {
Expand Down
8 changes: 0 additions & 8 deletions cli/flag_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,6 @@ func TestGetValue(t *testing.T) {
assert.Empty(t, str)
}

func TestAssignedCount(t *testing.T) {
fs := NewFlagSet()
fs.AddByName("MrX")
assert.Zero(t, fs.assignedCount())
fs.Flags()[0].assigned = true
assert.Equal(t, 1, fs.assignedCount())
}

func TestPut(t *testing.T) {
fs := NewFlagSet()
fs.put(&Flag{Name: "profile", Shorthand: 'p'})
Expand Down
5 changes: 2 additions & 3 deletions cli/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
Expand Down Expand Up @@ -101,13 +101,12 @@ var _ = ginkgo.Describe("Parser", func() {
})

ginkgo.It("2. can parse args and flags", func() {
parser, fs := newTestParser("s1", "s2", "--test", "aaa", "--test2=bbb")
parser, _ := newTestParser("s1", "s2", "--test", "aaa", "--test2=bbb")

ginkgo.By("first arg")
s, _, err := parser.ReadNextArg()
Expect(err).NotTo(HaveOccurred())
Expect(s).Should(Equal("s1"))
Expect(fs.assignedCount()).Should(Equal(0))

ginkgo.By("remain args")
s2, err := parser.ReadAll()
Expand Down

0 comments on commit 8e5d20a

Please sign in to comment.