-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from urfave/cli-v3-integration
Integrate with urfave/cli/v3 APIs
- Loading branch information
Showing
48 changed files
with
737 additions
and
3,249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
*.coverprofile | ||
*.exe | ||
*.orig | ||
.*envrc | ||
.envrc | ||
.idea | ||
/.local/ | ||
/site/ | ||
coverage.txt | ||
vendor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"greet": { | ||
"name": "Berry", | ||
"enthusiasm": "eleven" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[greet] | ||
name = "Berry" | ||
enthusiasm = "eleven" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
greet: | ||
name: Berry | ||
enthusiasm: eleven |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"greet": { | ||
"enthusiasm": 9001 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[greet] | ||
enthusiasm = 9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
greet: | ||
enthusiasm: 9001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"water_fountain": { | ||
"water": true | ||
}, | ||
"phone_booth": { | ||
"phone": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[water_fountain] | ||
water = true | ||
|
||
[phone_booth] | ||
phone = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
water_fountain: | ||
water: true | ||
phone_booth: | ||
phone: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"water_fountain": { | ||
"water": false | ||
}, | ||
"woodstock": { | ||
"wood": false | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
[water_fountain] | ||
water = false | ||
|
||
[woodstock] | ||
wood = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
water_fountain: | ||
water: false | ||
woodstock: | ||
wood: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.PHONY: all | ||
all: vet test show-cover | ||
|
||
.PHONY: vet | ||
vet: | ||
go vet -v ./... | ||
|
||
.PHONY: test | ||
test: | ||
go test -v -cover -coverprofile=coverage.txt ./... | ||
|
||
.PHONY: show-cover | ||
show-cover: | ||
go tool cover -func=coverage.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,11 @@ | ||
# cli-altsrc | ||
# Welcome to urfave/cli-altsrc/v3 | ||
|
||
Configuration source integration library for urfave/cli | ||
[![Run Tests](https://github.com/urfave/cli-altsrc/actions/workflows/main.yml/badge.svg)](https://github.com/urfave/cli-altsrc/actions/workflows/main.yml) | ||
[![Go Reference](https://pkg.go.dev/badge/github.com/urfave/cli-altsrc/v3.svg)](https://pkg.go.dev/github.com/urfave/cli-altsrc/v3) | ||
[![Go Report Card](https://goreportcard.com/badge/github.com/urfave/cli-altsrc/v3)](https://goreportcard.com/report/github.com/urfave/cli-altsrc/v3) | ||
|
||
urfave/cli-altsrc/v3 is an extended value source integration library for [urfave/cli/v3] with support for JSON, | ||
YAML, and TOML. The primary reason for this to be a separate library is that third-party libraries are used for these | ||
features which are otherwise not used throughout [urfave/cli/v3]. | ||
|
||
[urfave/cli/v3]: github.com/urfave/cli |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package altsrc | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"runtime" | ||
"strings" | ||
) | ||
|
||
var ( | ||
Err = errors.New("urfave/cli-altsrc error") | ||
|
||
isTracingOn = os.Getenv("URFAVE_CLI_TRACING") == "on" | ||
) | ||
|
||
func tracef(format string, a ...any) { | ||
if !isTracingOn { | ||
return | ||
} | ||
|
||
if !strings.HasSuffix(format, "\n") { | ||
format = format + "\n" | ||
} | ||
|
||
pc, file, line, _ := runtime.Caller(1) | ||
cf := runtime.FuncForPC(pc) | ||
|
||
fmt.Fprintf( | ||
os.Stderr, | ||
strings.Join([]string{ | ||
"## URFAVE CLI TRACE ", | ||
file, | ||
":", | ||
fmt.Sprintf("%v", line), | ||
" ", | ||
fmt.Sprintf("(%s)", cf.Name()), | ||
" ", | ||
format, | ||
}, ""), | ||
a..., | ||
) | ||
} | ||
|
||
func readURI(uriString string) ([]byte, error) { | ||
u, err := url.Parse(uriString) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if u.Host != "" { // i have a host, now do i support the scheme? | ||
switch u.Scheme { | ||
case "http", "https": | ||
res, err := http.Get(uriString) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return io.ReadAll(res.Body) | ||
default: | ||
return nil, fmt.Errorf("%[1]w: scheme of %[2]q is unsupported", Err, uriString) | ||
} | ||
} else if u.Path != "" || | ||
(runtime.GOOS == "windows" && strings.Contains(u.String(), "\\")) { | ||
if _, notFoundFileErr := os.Stat(uriString); notFoundFileErr != nil { | ||
return nil, fmt.Errorf("%[1]w: cannot read from %[2]q because it does not exist", Err, uriString) | ||
} | ||
return os.ReadFile(uriString) | ||
} | ||
|
||
return nil, fmt.Errorf("%[1]w: unable to determine how to load from %[2]q", Err, uriString) | ||
} | ||
|
||
// nestedVal checks if the name has '.' delimiters. | ||
// If so, it tries to traverse the tree by the '.' delimited sections to find | ||
// a nested value for the key. | ||
func nestedVal(name string, tree map[any]any) (any, bool) { | ||
if sections := strings.Split(name, "."); len(sections) > 1 { | ||
node := tree | ||
for _, section := range sections[:len(sections)-1] { | ||
child, ok := node[section] | ||
if !ok { | ||
return nil, false | ||
} | ||
|
||
switch child := child.(type) { | ||
case map[string]any: | ||
node = make(map[any]any, len(child)) | ||
for k, v := range child { | ||
node[k] = v | ||
} | ||
case map[any]any: | ||
node = child | ||
default: | ||
return nil, false | ||
} | ||
} | ||
if val, ok := node[sections[len(sections)-1]]; ok { | ||
return val, true | ||
} | ||
} | ||
|
||
return nil, false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package altsrc | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/urfave/cli-altsrc/v3/internal" | ||
) | ||
|
||
var ( | ||
testdataDir = func() string { | ||
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) | ||
defer cancel() | ||
|
||
return internal.MustTestdataDir(ctx) | ||
}() | ||
) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.