Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create main.yml #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
name: Run Tests

on:
push:
branches:
- master
- v1
pull_request:
branches:
- master
- v1

jobs:

test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.13, 1.14, 1.15]
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go ${{ matrix.go }}
uses: actions/setup-go@v1
with:
go-version: ${{ matrix.go }}

- name: Set GOPATH, PATH and ENV
run: |
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
uses: actions/checkout@v1
with:
ref: ${{ github.ref }}

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

- name: vet
run: go run internal/build/build.go vet

- name: test
run: go run internal/build/build.go test

- name: check-binary-size
run: go run internal/build/build.go check-binary-size

test-docs:
name: test-docs
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.15
uses: actions/setup-go@v1
with:
go-version: 1.15

- name: Use Node.js 12.x
uses: actions/setup-node@v1
with:
node-version: 12.x

- name: Set GOPATH, PATH and ENV
run: |
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
uses: actions/checkout@v1
with:
ref: ${{ github.ref }}

- name: Install Dependencies
run: |
mkdir -p $GOPATH/bin
curl -L -o $GOPATH/bin/gfmrun "https://github.com/urfave/gfmrun/releases/download/v1.2.14/gfmrun-$(go env GOOS)-amd64-v1.2.14"
chmod +x $GOPATH/bin/gfmrun
npm install -g [email protected]

- name: Run Tests (v1)
if: contains(github.base_ref, 'v1')
run: |
go run internal/build/build.go gfmrun docs/v1/manual.md
go run internal/build/build.go toc docs/v1/manual.md

- name: Run Tests (v2)
if: contains(github.base_ref, 'master')
run: |
go run internal/build/build.go gfmrun docs/v2/manual.md
go run internal/build/build.go toc docs/v2/manual.md
5 changes: 4 additions & 1 deletion context.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,10 @@ func (c *Context) Lineage() []*Context {

// Value returns the value of the flag corresponding to `name`
func (c *Context) Value(name string) interface{} {
return c.flagSet.Lookup(name).Value.(flag.Getter).Get()
if fs := lookupFlagSet(name, c); fs != nil {
return fs.Lookup(name).Value.(flag.Getter).Get()
}
return nil
}

// Args returns the command line arguments associated with the context.
Expand Down
11 changes: 11 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,17 @@ func TestContext_Bool(t *testing.T) {
expect(t, c.Bool("top-flag"), true)
}

func TestContext_Value(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Int("myflag", 12, "doc")
parentSet := flag.NewFlagSet("test", 0)
parentSet.Int("top-flag", 13, "doc")
parentCtx := NewContext(nil, parentSet, nil)
c := NewContext(nil, set, parentCtx)
expect(t, c.Value("myflag"), 12)
expect(t, c.Value("top-flag"), 13)
}

func TestContext_Args(t *testing.T) {
set := flag.NewFlagSet("test", 0)
set.Bool("myflag", false, "doc")
Expand Down