Skip to content

Commit 624c05a

Browse files
authored
Merge pull request urfave#1895 from bartekpacia/update_ci
Update GitHub Actions (bump versions, improve naming a bit)
2 parents 955bc3e + 2df7fe4 commit 624c05a

16 files changed

+168
-126
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.

.github/workflows/lint.yml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
name: Run lints
2+
3+
on:
4+
push:
5+
tags:
6+
- v3.*
7+
branches:
8+
- main
9+
pull_request:
10+
branches:
11+
- main
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
staticcheck:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Set up Go
21+
uses: actions/setup-go@v5
22+
with:
23+
go-version: "1.20"
24+
25+
- name: Clone repository
26+
uses: actions/checkout@v4
27+
28+
- name: Set up staticcheck
29+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
30+
31+
- name: Run staticcheck
32+
run: staticcheck ./...
33+
34+
golangci-lint:
35+
runs-on: ubuntu-latest
36+
37+
steps:
38+
- name: Set up Go
39+
uses: actions/setup-go@v5
40+
with:
41+
go-version: "1.20"
42+
43+
- name: Clone repository
44+
uses: actions/checkout@v4
45+
46+
- name: Run golangci-lint
47+
uses: golangci/golangci-lint-action@v5
48+
with:
49+
version: latest

.github/workflows/cli.yml renamed to .github/workflows/test.yml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
name: Run Tests
1+
name: Run tests
2+
23
on:
34
push:
45
branches:
@@ -8,20 +9,26 @@ on:
89
pull_request:
910
branches:
1011
- main
12+
1113
permissions:
1214
contents: read
15+
1316
jobs:
1417
test:
1518
strategy:
1619
matrix:
1720
os: [ubuntu-latest, macos-latest, windows-latest]
1821
go: [1.19.x, 1.20.x]
22+
1923
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
2024
runs-on: ${{ matrix.os }}
25+
2126
steps:
22-
- uses: actions/setup-go@v3
27+
- name: Set up Go
28+
uses: actions/setup-go@v5
2329
with:
2430
go-version: ${{ matrix.go }}
31+
2532
- name: Set PATH
2633
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"
2734
- uses: actions/checkout@v3
@@ -48,38 +55,49 @@ jobs:
4855
name: test-docs
4956
runs-on: ubuntu-latest
5057
steps:
51-
- uses: actions/setup-go@v3
58+
- name: Set up Go
59+
uses: actions/setup-go@v5
5260
with:
5361
go-version: 1.20.x
54-
- uses: actions/setup-node@v3
62+
63+
- name: Set up Node.js
64+
uses: actions/setup-node@v4
5565
with:
56-
node-version: '16'
66+
node-version: 16
67+
5768
- name: Set PATH
5869
run: echo "${GITHUB_WORKSPACE}/.local/bin" >>"${GITHUB_PATH}"
59-
- uses: actions/checkout@v3
70+
71+
- name: Clone repository
72+
uses: actions/checkout@v4
73+
6074
- run: make ensure-gfmrun
6175
- run: make gfmrun
6276
env:
6377
FLAGS: --walk docs/v3/
6478
- run: make diffcheck
79+
6580
publish:
6681
permissions:
6782
contents: write
6883
# TODO: switch once v3 is out of alpha {{
6984
# if: startswith(github.ref, 'refs/tags/')
70-
if: 'false'
85+
if: false
7186
# }}
7287
name: publish
7388
needs: [test-docs]
7489
runs-on: ubuntu-latest
7590
steps:
76-
- uses: actions/checkout@v3
91+
- uses: actions/checkout@v4
7792
with:
7893
fetch-depth: 0
94+
7995
- run: make ensure-mkdocs
8096
env:
8197
FLAGS: --upgrade-pip
98+
8299
- run: make set-mkdocs-remote
83100
env:
84101
MKDOCS_REMOTE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
102+
85103
- run: make deploy-mkdocs

command.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,11 @@ func (cmd *Command) ensureHelp() {
359359
func (cmd *Command) parseArgsFromStdin() ([]string, error) {
360360
type state int
361361
const (
362-
STATE_SEARCH_FOR_TOKEN state = -1
363-
STATE_IN_STRING state = 0
362+
stateSearchForToken state = -1
363+
stateSearchForString state = 0
364364
)
365365

366-
st := STATE_SEARCH_FOR_TOKEN
366+
st := stateSearchForToken
367367
linenum := 1
368368
token := ""
369369
args := []string{}
@@ -375,11 +375,11 @@ outer:
375375
ch, _, err := breader.ReadRune()
376376
if err == io.EOF {
377377
switch st {
378-
case STATE_SEARCH_FOR_TOKEN:
378+
case stateSearchForToken:
379379
if token != "--" {
380380
args = append(args, token)
381381
}
382-
case STATE_IN_STRING:
382+
case stateSearchForString:
383383
// make sure string is not empty
384384
for _, t := range token {
385385
if !unicode.IsSpace(t) {
@@ -393,7 +393,7 @@ outer:
393393
return nil, err
394394
}
395395
switch st {
396-
case STATE_SEARCH_FOR_TOKEN:
396+
case stateSearchForToken:
397397
if unicode.IsSpace(ch) || ch == '"' {
398398
if ch == '\n' {
399399
linenum++
@@ -407,12 +407,12 @@ outer:
407407
token = ""
408408
}
409409
if ch == '"' {
410-
st = STATE_IN_STRING
410+
st = stateSearchForString
411411
}
412412
continue
413413
}
414414
token += string(ch)
415-
case STATE_IN_STRING:
415+
case stateSearchForString:
416416
if ch != '"' {
417417
token += string(ch)
418418
} else {
@@ -423,7 +423,7 @@ outer:
423423
/*else {
424424
//TODO. Should we pass in empty strings ?
425425
}*/
426-
st = STATE_SEARCH_FOR_TOKEN
426+
st = stateSearchForToken
427427
}
428428
}
429429
}
@@ -1181,7 +1181,6 @@ func hasCommand(commands []*Command, command *Command) bool {
11811181
}
11821182

11831183
func (cmd *Command) runFlagActions(ctx context.Context) error {
1184-
11851184
for _, fl := range cmd.appliedFlags {
11861185
isSet := false
11871186

flag_bool.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func (cmd *Command) Bool(name string) bool {
3737
// Below functions are to satisfy the ValueCreator interface
3838

3939
// Create creates the bool value
40-
func (i boolValue) Create(val bool, p *bool, c BoolConfig) Value {
40+
func (b boolValue) Create(val bool, p *bool, c BoolConfig) Value {
4141
*p = val
4242
if c.Count == nil {
4343
c.Count = new(int)
@@ -49,8 +49,8 @@ func (i boolValue) Create(val bool, p *bool, c BoolConfig) Value {
4949
}
5050

5151
// ToString formats the bool value
52-
func (i boolValue) ToString(b bool) string {
53-
return strconv.FormatBool(b)
52+
func (b boolValue) ToString(value bool) string {
53+
return strconv.FormatBool(value)
5454
}
5555

5656
// Below functions are to satisfy the flag.Value interface

flag_bool_with_inverse.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import (
77
"strings"
88
)
99

10-
var (
11-
DefaultInverseBoolPrefix = "no-"
12-
)
10+
var DefaultInverseBoolPrefix = "no-"
1311

1412
type BoolWithInverseFlag struct {
1513
// The BoolFlag which the positive and negative flags are generated from
@@ -29,44 +27,42 @@ type BoolWithInverseFlag struct {
2927
negDest *bool
3028
}
3129

32-
func (s *BoolWithInverseFlag) Flags() []Flag {
33-
return []Flag{s.positiveFlag, s.negativeFlag}
30+
func (parent *BoolWithInverseFlag) Flags() []Flag {
31+
return []Flag{parent.positiveFlag, parent.negativeFlag}
3432
}
3533

36-
func (s *BoolWithInverseFlag) IsSet() bool {
37-
return (*s.posCount > 0) || (s.positiveFlag.IsSet() || s.negativeFlag.IsSet())
34+
func (parent *BoolWithInverseFlag) IsSet() bool {
35+
return (*parent.posCount > 0) || (parent.positiveFlag.IsSet() || parent.negativeFlag.IsSet())
3836
}
3937

40-
func (s *BoolWithInverseFlag) Value() bool {
41-
return *s.posDest
38+
func (parent *BoolWithInverseFlag) Value() bool {
39+
return *parent.posDest
4240
}
4341

44-
func (s *BoolWithInverseFlag) RunAction(ctx context.Context, cmd *Command) error {
45-
if *s.negDest && *s.posDest {
46-
return fmt.Errorf("cannot set both flags `--%s` and `--%s`", s.positiveFlag.Name, s.negativeFlag.Name)
42+
func (parent *BoolWithInverseFlag) RunAction(ctx context.Context, cmd *Command) error {
43+
if *parent.negDest && *parent.posDest {
44+
return fmt.Errorf("cannot set both flags `--%s` and `--%s`", parent.positiveFlag.Name, parent.negativeFlag.Name)
4745
}
4846

49-
if *s.negDest {
50-
err := cmd.Set(s.positiveFlag.Name, "false")
47+
if *parent.negDest {
48+
err := cmd.Set(parent.positiveFlag.Name, "false")
5149
if err != nil {
5250
return err
5351
}
5452
}
5553

56-
if s.BoolFlag.Action != nil {
57-
return s.BoolFlag.Action(ctx, cmd, s.Value())
54+
if parent.BoolFlag.Action != nil {
55+
return parent.BoolFlag.Action(ctx, cmd, parent.Value())
5856
}
5957

6058
return nil
6159
}
6260

63-
/*
64-
initialize creates a new BoolFlag that has an inverse flag
65-
66-
consider a bool flag `--env`, there is no way to set it to false
67-
this function allows you to set `--env` or `--no-env` and in the command action
68-
it can be determined that BoolWithInverseFlag.IsSet()
69-
*/
61+
// Initialize creates a new BoolFlag that has an inverse flag
62+
//
63+
// consider a bool flag `--env`, there is no way to set it to false
64+
// this function allows you to set `--env` or `--no-env` and in the command action
65+
// it can be determined that BoolWithInverseFlag.IsSet().
7066
func (parent *BoolWithInverseFlag) initialize() {
7167
child := parent.BoolFlag
7268

@@ -138,45 +134,47 @@ func (parent *BoolWithInverseFlag) inverseAliases() (aliases []string) {
138134
return
139135
}
140136

141-
func (s *BoolWithInverseFlag) Apply(set *flag.FlagSet) error {
142-
if s.positiveFlag == nil {
143-
s.initialize()
137+
func (parent *BoolWithInverseFlag) Apply(set *flag.FlagSet) error {
138+
if parent.positiveFlag == nil {
139+
parent.initialize()
144140
}
145141

146-
if err := s.positiveFlag.Apply(set); err != nil {
142+
if err := parent.positiveFlag.Apply(set); err != nil {
147143
return err
148144
}
149145

150-
if err := s.negativeFlag.Apply(set); err != nil {
146+
if err := parent.negativeFlag.Apply(set); err != nil {
151147
return err
152148
}
153149

154150
return nil
155151
}
156152

157-
func (s *BoolWithInverseFlag) Names() []string {
153+
func (parent *BoolWithInverseFlag) Names() []string {
158154
// Get Names when flag has not been initialized
159-
if s.positiveFlag == nil {
160-
return append(s.BoolFlag.Names(), FlagNames(s.inverseName(), s.inverseAliases())...)
155+
if parent.positiveFlag == nil {
156+
return append(parent.BoolFlag.Names(), FlagNames(parent.inverseName(), parent.inverseAliases())...)
161157
}
162158

163-
if *s.negDest {
164-
return s.negativeFlag.Names()
159+
if *parent.negDest {
160+
return parent.negativeFlag.Names()
165161
}
166162

167-
if *s.posDest {
168-
return s.positiveFlag.Names()
163+
if *parent.posDest {
164+
return parent.positiveFlag.Names()
169165
}
170166

171-
return append(s.negativeFlag.Names(), s.positiveFlag.Names()...)
167+
return append(parent.negativeFlag.Names(), parent.positiveFlag.Names()...)
172168
}
173169

170+
// String implements the standard Stringer interface.
171+
//
174172
// Example for BoolFlag{Name: "env"}
175173
// --env (default: false) || --no-env (default: false)
176-
func (s *BoolWithInverseFlag) String() string {
177-
if s.positiveFlag == nil {
178-
return fmt.Sprintf("%s || --%s", s.BoolFlag.String(), s.inverseName())
174+
func (parent *BoolWithInverseFlag) String() string {
175+
if parent.positiveFlag == nil {
176+
return fmt.Sprintf("%s || --%s", parent.BoolFlag.String(), parent.inverseName())
179177
}
180178

181-
return fmt.Sprintf("%s || %s", s.positiveFlag.String(), s.negativeFlag.String())
179+
return fmt.Sprintf("%s || %s", parent.positiveFlag.String(), parent.negativeFlag.String())
182180
}

0 commit comments

Comments
 (0)