Skip to content
Merged
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
27 changes: 18 additions & 9 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,36 @@ jobs:
name: Test and Build
strategy:
matrix:
go-version: [1.16.x]
go-version: [1.24.x]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v2
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run make
run: make update && make correct

- name: Test
run: go test -v ./... -race
run: go test -v . -race

coverage:
name: Code Coverage
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run make
run: make update && make correct

- name: Generage coverage
run: go test -v ./... -coverprofile=coverage.txt -covermode=atomic
run: go test -v . -coverprofile=coverage.txt -covermode=atomic

- name: Publish coverage
uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
uses: codecov/codecov-action@v5
Empty file added .gitignore
Empty file.
19 changes: 14 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ include go.mk
all: update

update:
curl -LO https://raw.githubusercontent.com/golang/go/master/src/flag/example_test.go
curl -LO https://raw.githubusercontent.com/golang/go/master/src/flag/example_value_test.go
curl -LO https://raw.githubusercontent.com/golang/go/master/src/flag/export_test.go
curl -LO https://raw.githubusercontent.com/golang/go/master/src/flag/flag.go
curl -LO https://raw.githubusercontent.com/golang/go/master/src/flag/flag_test.go
git clone --depth=1 --no-checkout https://github.com/golang/go third_party/go
git submodule add https://github.com/golang/go/ third_party/go
git submodule absorbgitdirs
git -C third_party/go config core.sparseCheckout true
cp test/sparse-checkout .git/modules/third_party/go/info/sparse-checkout
git submodule update --force --checkout third_party/go

correct:
@cp -R third_party/go/src/internal/* internal
ifeq ($(OS), Darwin)
find internal/* -type f -name "*.go" | xargs -I {} sed -i '' -e "s/\"internal\//\"github.com\/jnovack\/flag\/internal\//g" {}
else
find internal/* -type f -name "*.go" | xargs -I {} sed -i'' -e "s/\"internal\//\"github.com\/jnovack\/flag\/internal\//g" {}
endif
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ flag.String(flag.DefaultConfigFlagname, "", "path to config file")
Run the command:

```go
$ go run ./gopher.go -config ./gopher.conf
go run ./gopher.go -config ./gopher.conf
```

The default flag name for the configuration file is "config" and can be
Expand Down
6 changes: 4 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func Example() {
// to enable the flag package to see the flags defined there, one must
// execute, typically at the start of main (not init!):
// flag.Parse()
// We don't run it here because this is not a main function and
// the testing suite has already parsed the flags.
// We don't call it here because this code is a function called "Example"
// that is part of the testing suite for the package, which has already
// parsed the flags. When viewed at pkg.go.dev, however, the function is
// renamed to "main" and it could be run as a standalone example.
}
6 changes: 5 additions & 1 deletion export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package flag

import "os"
import (
"io"
"os"
)

// Additional routines compiled into the package only during testing.

Expand All @@ -15,6 +18,7 @@ var DefaultUsage = Usage
// exit the program.
func ResetForTesting(usage func()) {
CommandLine = NewFlagSet(os.Args[0], ContinueOnError)
CommandLine.SetOutput(io.Discard)
CommandLine.Usage = commandLineUsage
Usage = usage
}
2 changes: 1 addition & 1 deletion extras.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func (f *FlagSet) ParseFile(path string) error {
}
}

if hasValue == false {
if !hasValue {
name = line
}

Expand Down
Loading
Loading