Skip to content

Commit ce21143

Browse files
Merge pull request #9 from andreimerlescu/feature/usage
Activated the Usage func in the flag package on the tree
2 parents 8fb63d9 + f242dca commit ce21143

File tree

5 files changed

+6
-9
lines changed

5 files changed

+6
-9
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.0.9
1+
v2.0.10

alias_test.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func TestWithAlias(t *testing.T) {
1515
figs.NewString(cmdLong, valueLong, usage)
1616
figs.WithAlias(cmdLong, cmdAliasLong)
1717
assert.NoError(t, figs.Parse())
18-
t.Log(figs.Usage())
1918

2019
assert.Equal(t, valueLong, *figs.String(cmdLong))
2120
assert.Equal(t, valueLong, *figs.String(cmdAliasLong))
@@ -33,7 +32,6 @@ func TestWithAlias(t *testing.T) {
3332
figs.WithAlias(k, ka2)
3433
figs.WithAlias(k, ka3)
3534
assert.NoError(t, figs.Parse())
36-
t.Log(figs.Usage())
3735

3836
assert.Equal(t, v, *figs.String(k))
3937
assert.Equal(t, v, *figs.String(ka1))
@@ -56,7 +54,7 @@ func TestWithAlias(t *testing.T) {
5654
figs.WithValidator(cmdShort, AssureStringNotEmpty)
5755

5856
assert.NoError(t, figs.Parse())
59-
t.Log(figs.Usage())
57+
6058
// long
6159
assert.Equal(t, valueLong, *figs.String(cmdLong))
6260
assert.Equal(t, valueLong, *figs.String(cmdAliasLong))
@@ -73,7 +71,6 @@ func TestWithAlias(t *testing.T) {
7371
figs.NewInt("count", 42, "usage")
7472
figs.WithAlias("count", "c")
7573
assert.NoError(t, figs.Parse())
76-
t.Log(figs.Usage())
7774
assert.Equal(t, 42, *figs.Int("count"))
7875
assert.Equal(t, 42, *figs.Int("c"))
7976
})
@@ -86,6 +83,5 @@ func TestWithAlias(t *testing.T) {
8683
figs.WithAlias("two", "x") // Should this overwrite or be ignored?
8784
assert.NoError(t, figs.Parse())
8885
assert.Equal(t, "value1", *figs.String("x")) // Clarify expected behavior
89-
t.Log(figs.Usage())
9086
})
9187
}

figtree.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func With(opts Options) Plant {
7979
mutationsCh: make(chan Mutation),
8080
flagSet: flag.NewFlagSet(os.Args[0], flag.ContinueOnError),
8181
}
82+
fig.flagSet.Usage = fig.Usage
8283
angel.Store(false)
8384
if opts.IgnoreEnvironment {
8485
os.Clearenv()

types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ type Core interface {
173173
ErrorFor(name string) error
174174

175175
// Usage displays the helpful menu of figs registered using -h or -help
176-
Usage() string
176+
Usage()
177177
}
178178

179179
// Plant defines the interface for configuration management.

usage.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
)
1212

1313
// Usage prints a helpful table of figs in a human-readable format
14-
func (tree *figTree) Usage() string {
14+
func (tree *figTree) Usage() {
1515
termWidth := 80
1616
if term.IsTerminal(int(os.Stdout.Fd())) {
1717
if width, _, err := term.GetSize(int(os.Stdout.Fd())); err == nil {
@@ -79,7 +79,7 @@ func (tree *figTree) Usage() string {
7979
}
8080
})
8181

82-
return sb.String()
82+
fmt.Println(sb.String())
8383
}
8484

8585
// wrapText wraps a line of text to fit within the terminal width, indenting wrapped lines

0 commit comments

Comments
 (0)