Skip to content

Commit

Permalink
Merge pull request #1374 from 53jk1/main
Browse files Browse the repository at this point in the history
Remove some unused code
  • Loading branch information
meatballhat authored Apr 26, 2022
2 parents 59ec2a1 + 4c7b46c commit dbeef68
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
22 changes: 1 addition & 21 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"flag"
"fmt"
"io/ioutil"
"reflect"
"regexp"
"runtime"
"strconv"
Expand Down Expand Up @@ -244,7 +243,7 @@ func prefixedNames(names []string, placeholder string) string {

func withEnvHint(envVars []string, str string) string {
envText := ""
if envVars != nil && len(envVars) > 0 {
if len(envVars) > 0 {
prefix := "$"
suffix := ""
sep := ", $"
Expand Down Expand Up @@ -273,17 +272,6 @@ func flagNames(name string, aliases []string) []string {
return ret
}

func flagStringSliceField(f Flag, name string) []string {
fv := flagValue(f)
field := fv.FieldByName(name)

if field.IsValid() {
return field.Interface().([]string)
}

return []string{}
}

func withFileHint(filePath, str string) string {
fileText := ""
if filePath != "" {
Expand All @@ -292,14 +280,6 @@ func withFileHint(filePath, str string) string {
return str + fileText
}

func flagValue(f Flag) reflect.Value {
fv := reflect.ValueOf(f)
for fv.Kind() == reflect.Ptr {
fv = reflect.Indirect(fv)
}
return fv
}

func formatDefault(format string) string {
return " (default: " + format + ")"
}
Expand Down
18 changes: 9 additions & 9 deletions flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
}
}

var prefixStringFlagTests = []struct {
var _ = []struct {
name string
aliases []string
usage string
Expand Down Expand Up @@ -490,7 +490,7 @@ func TestPathFlagApply_SetsAllNames(t *testing.T) {
expect(t, v, "/path/to/file/PATH")
}

var envHintFlagTests = []struct {
var _ = []struct {
name string
env string
hinter FlagEnvHintFunc
Expand Down Expand Up @@ -2174,43 +2174,43 @@ type flagDefaultTestCase struct {

func TestFlagDefaultValue(t *testing.T) {
cases := []*flagDefaultTestCase{
&flagDefaultTestCase{
{
name: "stringSclice",
flag: &StringSliceFlag{Name: "flag", Value: NewStringSlice("default1", "default2")},
toParse: []string{"--flag", "parsed"},
expect: `--flag value (default: "default1", "default2") (accepts multiple inputs)`,
},
&flagDefaultTestCase{
{
name: "float64Sclice",
flag: &Float64SliceFlag{Name: "flag", Value: NewFloat64Slice(1.1, 2.2)},
toParse: []string{"--flag", "13.3"},
expect: `--flag value (default: 1.1, 2.2) (accepts multiple inputs)`,
},
&flagDefaultTestCase{
{
name: "int64Sclice",
flag: &Int64SliceFlag{Name: "flag", Value: NewInt64Slice(1, 2)},
toParse: []string{"--flag", "13"},
expect: `--flag value (default: 1, 2) (accepts multiple inputs)`,
},
&flagDefaultTestCase{
{
name: "intSclice",
flag: &IntSliceFlag{Name: "flag", Value: NewIntSlice(1, 2)},
toParse: []string{"--flag", "13"},
expect: `--flag value (default: 1, 2) (accepts multiple inputs)`,
},
&flagDefaultTestCase{
{
name: "string",
flag: &StringFlag{Name: "flag", Value: "default"},
toParse: []string{"--flag", "parsed"},
expect: `--flag value (default: "default")`,
},
&flagDefaultTestCase{
{
name: "bool",
flag: &BoolFlag{Name: "flag", Value: true},
toParse: []string{"--flag", "false"},
expect: `--flag (default: true)`,
},
&flagDefaultTestCase{
{
name: "uint64",
flag: &Uint64Flag{Name: "flag", Value: 1},
toParse: []string{"--flag", "13"},
Expand Down

0 comments on commit dbeef68

Please sign in to comment.