Skip to content

Commit

Permalink
Merge branch 'master' into suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
meatballhat committed Apr 19, 2022
2 parents 002bde2 + 7b2e609 commit 4b238b8
Show file tree
Hide file tree
Showing 62 changed files with 2,097 additions and 439 deletions.
11 changes: 6 additions & 5 deletions .github/pull_request_template.md
Expand Up @@ -29,10 +29,11 @@ _(REQUIRED)_

_(REQUIRED)_
<!--
If this PR fixes one of more issues, list them here.
One line each, like so:
Fixes #123
Fixes #39
If this PR fixes one of more issues, list them here.
One line each, like so:
Fixes #123
Fixes #39
-->

## Special notes for your reviewer:
Expand Down Expand Up @@ -66,4 +67,4 @@ _(REQUIRED)_

```release-note
```
```
63 changes: 0 additions & 63 deletions .github/stale.yml

This file was deleted.

29 changes: 14 additions & 15 deletions .github/workflows/cli.yml
Expand Up @@ -11,12 +11,11 @@ on:
- v1

jobs:

test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.11, 1.12, 1.13]
go: [1.15, 1.16, 1.17]
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -27,10 +26,10 @@ jobs:

- name: Set GOPATH, PATH and ENV
run: |
echo "::set-env name=GOPATH::$(dirname $GITHUB_WORKSPACE)"
echo "::set-env name=GO111MODULE::on"
echo "::set-env name=GOPROXY::https://proxy.golang.org"
echo "::add-path::$(dirname $GITHUB_WORKSPACE)/bin"
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
echo "GO111MODULE=on" >> $GITHUB_ENV
echo "GOPROXY=https://proxy.golang.org" >> $GITHUB_ENV
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
shell: bash

- name: Checkout Code
Expand All @@ -39,7 +38,7 @@ jobs:
ref: ${{ github.ref }}

- name: GOFMT Check
if: matrix.go == 1.13 && matrix.os == 'ubuntu-latest'
if: matrix.go == 1.17 && matrix.os == 'ubuntu-latest'
run: test -z $(gofmt -l .)

- name: vet
Expand All @@ -52,20 +51,20 @@ jobs:
run: go run internal/build/build.go check-binary-size

- name: Upload coverage to Codecov
if: success() && matrix.go == 1.13 && matrix.os == 'ubuntu-latest'
if: success() && matrix.go == 1.17 && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v1
with:
token: 0a8cc73b-bb7c-480b-8626-38a461643761
fail_ci_if_error: true

test-docs:
name: test-docs
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
- name: Set up Go
uses: actions/setup-go@v1
with:
go-version: 1.13
# Currently fails on 1.16+
go-version: 1.15

- name: Use Node.js 12.x
uses: actions/setup-node@v1
Expand All @@ -74,10 +73,10 @@ jobs:

- name: Set GOPATH, PATH and ENV
run: |
echo "::set-env name=GOPATH::$(dirname $GITHUB_WORKSPACE)"
echo "::set-env name=GO111MODULE::on"
echo "::set-env name=GOPROXY::https://proxy.golang.org"
echo "::add-path::$(dirname $GITHUB_WORKSPACE)/bin"
echo "GOPATH=$(dirname $GITHUB_WORKSPACE)" >> $GITHUB_ENV
echo "GO111MODULE=on" >> $GITHUB_ENV
echo "GOPROXY=https://proxy.golang.org" >> $GITHUB_ENV
echo "$(dirname $GITHUB_WORKSPACE)/bin" >> $GITHUB_PATH
shell: bash

- name: Checkout Code
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -5,3 +5,5 @@ vendor
.idea
internal/*/built-example
coverage.txt

*.exe
12 changes: 8 additions & 4 deletions README.md
@@ -1,7 +1,7 @@
cli
===

[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://godoc.org/github.com/urfave/cli)
[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v2)
[![codebeat](https://codebeat.co/badges/0a8f30aa-f975-404b-b878-5fab3ae1cc5f)](https://codebeat.co/projects/github-com-urfave-cli)
[![Go Report Card](https://goreportcard.com/badge/urfave/cli)](https://goreportcard.com/report/urfave/cli)
[![codecov](https://codecov.io/gh/urfave/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/urfave/cli)
Expand All @@ -17,11 +17,15 @@ Usage documentation exists for each major version. Don't know what version you'r
- `v2` - [./docs/v2/manual.md](./docs/v2/manual.md)
- `v1` - [./docs/v1/manual.md](./docs/v1/manual.md)

Guides for migrating to newer versions:

- `v1-to-v2` - [./docs/migrate-v1-to-v2.md](./docs/migrate-v1-to-v2.md)

## Installation

Make sure you have a working Go environment. Go version 1.11+ is supported. [See the install instructions for Go](http://golang.org/doc/install.html).
Using this package requires a working Go environment. [See the install instructions for Go](http://golang.org/doc/install.html).

Go Modules are strongly recommended when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).
Go Modules are required when using this package. [See the go blog guide on using Go Modules](https://blog.golang.org/using-go-modules).

### Using `v2` releases

Expand Down Expand Up @@ -63,4 +67,4 @@ export PATH=$PATH:$GOPATH/bin

cli is tested against multiple versions of Go on Linux, and against the latest
released version of Go on OS X and Windows. This project uses Github Actions for
builds. For more build info, please look at the [./.github/workflows/cli.yml](https://github.com/urfave/cli/blob/master/.github/workflows/cli.yml).
builds. To see our currently supported go versions and platforms, look at the [./.github/workflows/cli.yml](https://github.com/urfave/cli/blob/master/.github/workflows/cli.yml).
6 changes: 6 additions & 0 deletions altsrc/default_input_source.go
@@ -0,0 +1,6 @@
package altsrc

// defaultInputSource creates a default InputSourceContext.
func defaultInputSource() (InputSourceContext, error) {
return &MapInputSource{file: "", valueMap: map[interface{}]interface{}{}}, nil
}
9 changes: 8 additions & 1 deletion altsrc/flag_test.go
Expand Up @@ -4,6 +4,7 @@ import (
"flag"
"fmt"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
Expand Down Expand Up @@ -190,7 +191,13 @@ func TestPathApplyInputSourceMethodSet(t *testing.T) {

expected := "/path/to/source/hello"
if runtime.GOOS == "windows" {
expected = `D:\path\to\source\hello`
var err error
// Prepend the corresponding drive letter (or UNC path?), and change
// to windows-style path:
expected, err = filepath.Abs(expected)
if err != nil {
t.Fatal(err)
}
}
expect(t, expected, c.String("test"))
}
Expand Down
6 changes: 5 additions & 1 deletion altsrc/json_source_context.go
Expand Up @@ -17,7 +17,11 @@ import (
// by the given flag.
func NewJSONSourceFromFlagFunc(flag string) func(c *cli.Context) (InputSourceContext, error) {
return func(context *cli.Context) (InputSourceContext, error) {
return NewJSONSourceFromFile(context.String(flag))
if context.IsSet(flag) {
return NewJSONSourceFromFile(context.String(flag))
}

return defaultInputSource()
}
}

Expand Down
5 changes: 5 additions & 0 deletions altsrc/map_input_source.go
Expand Up @@ -16,6 +16,11 @@ type MapInputSource struct {
valueMap map[interface{}]interface{}
}

// NewMapInputSource creates a new MapInputSource for implementing custom input sources.
func NewMapInputSource(file string, valueMap map[interface{}]interface{}) *MapInputSource {
return &MapInputSource{file: file, valueMap: valueMap}
}

// 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.
Expand Down
9 changes: 4 additions & 5 deletions altsrc/map_input_source_test.go
Expand Up @@ -6,14 +6,13 @@ import (
)

func TestMapDuration(t *testing.T) {
inputSource := &MapInputSource{
file: "test",
valueMap: map[interface{}]interface{}{
inputSource := NewMapInputSource(
"test",
map[interface{}]interface{}{
"duration_of_duration_type": time.Minute,
"duration_of_string_type": "1m",
"duration_of_int_type": 1000,
},
}
})
d, err := inputSource.Duration("duration_of_duration_type")
expect(t, time.Minute, d)
expect(t, nil, err)
Expand Down
8 changes: 6 additions & 2 deletions altsrc/toml_file_loader.go
Expand Up @@ -87,8 +87,12 @@ func NewTomlSourceFromFile(file string) (InputSourceContext, error) {
// NewTomlSourceFromFlagFunc creates a new TOML InputSourceContext from a provided flag name and source context.
func NewTomlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
return func(context *cli.Context) (InputSourceContext, error) {
filePath := context.String(flagFileName)
return NewTomlSourceFromFile(filePath)
if context.IsSet(flagFileName) {
filePath := context.String(flagFileName)
return NewTomlSourceFromFile(filePath)
}

return defaultInputSource()
}
}

Expand Down
8 changes: 6 additions & 2 deletions altsrc/yaml_file_loader.go
Expand Up @@ -33,8 +33,12 @@ func NewYamlSourceFromFile(file string) (InputSourceContext, error) {
// NewYamlSourceFromFlagFunc creates a new Yaml InputSourceContext from a provided flag name and source context.
func NewYamlSourceFromFlagFunc(flagFileName string) func(context *cli.Context) (InputSourceContext, error) {
return func(context *cli.Context) (InputSourceContext, error) {
filePath := context.String(flagFileName)
return NewYamlSourceFromFile(filePath)
if context.IsSet(flagFileName) {
filePath := context.String(flagFileName)
return NewYamlSourceFromFile(filePath)
}

return defaultInputSource()
}
}

Expand Down

0 comments on commit 4b238b8

Please sign in to comment.