Skip to content

Commit

Permalink
Merge branch 'main' into flags-after-args
Browse files Browse the repository at this point in the history
  • Loading branch information
dearchap authored Jul 9, 2024
2 parents ad0e192 + 6d6416e commit e6aa7ca
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ command line tools in Go featuring:
- environment variables
- plain text files
- structured file formats (supported via the
[`urfave/cli-altsrc`][urfave/cli-docs] module)
[`urfave/cli-altsrc`][urfave/cli-altsrc] module)

## Documentation

Expand Down
2 changes: 2 additions & 0 deletions godoc-current.txt
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ type ValueSource interface {

func EnvVar(key string) ValueSource

func File(path string) ValueSource

type ValueSourceChain struct {
Chain []ValueSource
}
Expand Down
2 changes: 2 additions & 0 deletions testdata/godoc-v3.x.txt
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,8 @@ type ValueSource interface {

func EnvVar(key string) ValueSource

func File(path string) ValueSource

type ValueSourceChain struct {
Chain []ValueSource
}
Expand Down
4 changes: 4 additions & 0 deletions value_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ func (f *fileValueSource) GoString() string {
return fmt.Sprintf("&fileValueSource{Path:%[1]q}", f.Path)
}

func File(path string) ValueSource {
return &fileValueSource{Path: path}
}

// Files is a helper function to encapsulate a number of
// fileValueSource together as a ValueSourceChain
func Files(paths ...string) ValueSourceChain {
Expand Down
8 changes: 4 additions & 4 deletions value_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func TestFileValueSource(t *testing.T) {
r.Implements((*ValueSource)(nil), &fileValueSource{})

t.Run("not found", func(t *testing.T) {
src := &fileValueSource{Path: fmt.Sprintf("junk_file_name-%[1]v", rand.Int())}
src := File(fmt.Sprintf("junk_file_name-%[1]v", rand.Int()))
_, ok := src.Lookup()
r.False(ok)
})
Expand All @@ -82,23 +82,23 @@ func TestFileValueSource(t *testing.T) {
r.Nil(os.WriteFile(fileName, []byte("pita"), 0o644))

t.Run("found", func(t *testing.T) {
src := &fileValueSource{Path: fileName}
src := File(fileName)
str, ok := src.Lookup()
r.True(ok)
r.Equal("pita", str)
})
})

t.Run("implements fmt.Stringer", func(t *testing.T) {
src := &fileValueSource{Path: "/dev/null"}
src := File("/dev/null")
r := require.New(t)

r.Implements((*ValueSource)(nil), src)
r.Equal("file \"/dev/null\"", src.String())
})

t.Run("implements fmt.GoStringer", func(t *testing.T) {
src := &fileValueSource{Path: "/dev/null"}
src := File("/dev/null")
r := require.New(t)

r.Implements((*ValueSource)(nil), src)
Expand Down

0 comments on commit e6aa7ca

Please sign in to comment.