Skip to content

Commit

Permalink
Merge pull request #1569 from urfave/v3-porting
Browse files Browse the repository at this point in the history
Porting `main` to `v3-dev-main` circa 2022-11-06
  • Loading branch information
meatballhat authored Nov 8, 2022
2 parents 46043dd + a5ec63b commit c296830
Show file tree
Hide file tree
Showing 52 changed files with 643 additions and 568 deletions.
18 changes: 14 additions & 4 deletions .github/workflows/cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,22 @@ on:
push:
branches:
- main
- v3-dev-main
tags:
- v2.*
- v3.*
pull_request:
branches:
- main
- v3-dev-main
permissions:
contents: read
jobs:
test:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
go: [1.17.x, 1.18.x, 1.19.x]
go: [1.18.x, 1.19.x]
name: ${{ matrix.os }} @ Go ${{ matrix.go }}
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -43,13 +46,17 @@ jobs:
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
run: make generate
- run: make diffcheck
- if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
# TODO: switch once v3 is released {{
# - if: matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
- if: 'false'
run: make v2diff
# }}
- if: success() && matrix.go == '1.19.x' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

test-docs:
name: test-docs
runs-on: ubuntu-latest
Expand All @@ -66,12 +73,15 @@ jobs:
- run: make ensure-gfmrun
- run: make gfmrun
env:
FLAGS: --walk docs/v2/
FLAGS: --walk docs/v3/
- run: make diffcheck
publish:
permissions:
contents: write
if: startswith(github.ref, 'refs/tags/')
# TODO: switch once v3 is released {{
# if: startswith(github.ref, 'refs/tags/')
if: 'false'
# }}
name: publish
needs: [test-docs]
runs-on: ubuntu-latest
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
.envrc
.idea
/.local/
/cmd/urfave-cli-genflags/urfave-cli-genflags
/site/
coverage.txt
internal/*/built-example
vendor
/cmd/urfave-cli-genflags/urfave-cli-genflags
*.exe
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
GO_RUN_BUILD := go run internal/build/build.go

.PHONY: all
all: generate vet test check-binary-size gfmrun yamlfmt v2diff
all: generate vet test check-binary-size gfmrun yamlfmt

# NOTE: this is a special catch-all rule to run any of the commands
# defined in internal/build/build.go with optional arguments passed
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# cli

[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v2)
[![GoDoc](https://godoc.org/github.com/urfave/cli?status.svg)](https://pkg.go.dev/github.com/urfave/cli/v3)
[![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/main/graph/badge.svg)](https://codecov.io/gh/urfave/cli)
Expand Down
2 changes: 1 addition & 1 deletion altsrc/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strconv"
"syscall"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// FlagInputSourceExtension is an extension interface of cli.Flag that
Expand Down
2 changes: 1 addition & 1 deletion altsrc/flag_generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package altsrc
import (
"flag"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// BoolFlag is the flag type that wraps cli.BoolFlag to allow
Expand Down
2 changes: 1 addition & 1 deletion altsrc/flag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type testApplyInputSource struct {
Expand Down
2 changes: 1 addition & 1 deletion altsrc/input_source_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package altsrc
import (
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// InputSourceContext is an interface used to allow
Expand Down
2 changes: 1 addition & 1 deletion altsrc/json_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion altsrc/json_source_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// NewJSONSourceFromFlagFunc returns a func that takes a cli.Context
Expand Down
2 changes: 1 addition & 1 deletion altsrc/map_input_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

// MapInputSource implements InputSourceContext to return
Expand Down
2 changes: 1 addition & 1 deletion altsrc/toml_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

func TestCommandTomFileTest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion altsrc/toml_file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"reflect"

"github.com/BurntSushi/toml"
"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

type tomlMap struct {
Expand Down
2 changes: 1 addition & 1 deletion altsrc/yaml_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"os"
"testing"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"
)

func TestCommandYamlFileTest(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion altsrc/yaml_file_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"runtime"
"strings"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v3"

"gopkg.in/yaml.v3"
)
Expand Down
4 changes: 2 additions & 2 deletions altsrc/yaml_file_loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"os"
"time"

"github.com/urfave/cli/v2"
"github.com/urfave/cli/v2/altsrc"
"github.com/urfave/cli/v3"
"github.com/urfave/cli/v3/altsrc"
)

func ExampleApp_Run_yamlFileLoaderDuration() {
Expand Down
20 changes: 20 additions & 0 deletions app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,26 @@ func (c *customBoolFlag) IsSet() bool {
return false
}

func (c *customBoolFlag) IsRequired() bool {
return false
}

func (c *customBoolFlag) IsVisible() bool {
return false
}

func (c *customBoolFlag) GetCategory() string {
return ""
}

func (c *customBoolFlag) GetEnvVars() []string {
return nil
}

func (c *customBoolFlag) GetDefaultText() string {
return ""
}

func TestCustomFlagsUnused(t *testing.T) {
app := &App{
Flags: []Flag{&customBoolFlag{"custom"}},
Expand Down
29 changes: 23 additions & 6 deletions cmd/urfave-cli-genflags/generated.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,21 +47,38 @@ func (f *{{.TypeName}}) Names() []string {
return {{$.UrfaveCLINamespace}}FlagNames(f.Name, f.Aliases)
}

{{end}}{{/* /if .GenerateFlagInterface */}}

{{if .GenerateRequiredFlagInterface}}
// IsRequired returns whether or not the flag is required
func (f *{{.TypeName}}) IsRequired() bool {
return f.Required
}
{{end}}{{/* /if .GenerateRequiredFlagInterface */}}

{{if .GenerateVisibleFlagInterface}}
// IsVisible returns true if the flag is not hidden, otherwise false
func (f *{{.TypeName}}) IsVisible() bool {
return !f.Hidden
}
{{end}}{{/* /if .GenerateVisibleFlagInterface */}}

// GetCategory returns the category of the flag
func (f *{{.TypeName}}) GetCategory() string {
return f.Category
}

// GetUsage returns the usage string for the flag
func (f *{{.TypeName}}) GetUsage() string {
return f.Usage
}

// GetEnvVars returns the env vars for this flag
func (f *{{.TypeName}}) GetEnvVars() []string {
return f.EnvVars
}

// TakesValue returns true if the flag takes a value, otherwise false
func (f *{{.TypeName}}) TakesValue() bool {
return "{{.TypeName }}" != "BoolFlag"
}

{{end}}{{/* /if .GenerateFlagInterface */}}

{{end}}{{/* /range .SortedFlagTypes */}}

// vim{{/* 👻 */}}:ro
Expand Down
5 changes: 0 additions & 5 deletions cmd/urfave-cli-genflags/generated_altsrc.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@

package {{.PackageName}}

import (
"flag"
"github.com/urfave/cli/v2"
)

{{range .SortedFlagTypes}}
// {{.TypeName}} is the flag type that wraps cli.{{.TypeName}} to allow
// for other values to be specified
Expand Down
23 changes: 11 additions & 12 deletions cmd/urfave-cli-genflags/generated_test.gotmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,30 @@ func Test{{.TypeName}}_SatisfiesFlagInterface(t *testing.T) {
_ = f.IsSet()
_ = f.Names()
}
{{end}}

{{if .GenerateFmtStringerInterface}}
func Test{{.TypeName}}_SatisfiesFmtStringerInterface(t *testing.T) {
var f fmt.Stringer = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.String()
}
{{end}}

{{if .GenerateRequiredFlagInterface}}
func Test{{.TypeName}}_SatisfiesRequiredFlagInterface(t *testing.T) {
var f {{$.UrfaveCLITestNamespace}}RequiredFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.IsRequired()
}
{{end}}

{{if .GenerateVisibleFlagInterface}}
func Test{{.TypeName}}_SatisfiesVisibleFlagInterface(t *testing.T) {
var f {{$.UrfaveCLITestNamespace}}VisibleFlag = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.IsVisible()
}

{{end}}

{{if .GenerateFmtStringerInterface}}
func Test{{.TypeName}}_SatisfiesFmtStringerInterface(t *testing.T) {
var f fmt.Stringer = &{{$.UrfaveCLITestNamespace}}{{.TypeName}}{}

_ = f.String()
}
{{end}}


{{end}}

// vim{{/* 👻 */}}:ro
Expand Down
2 changes: 1 addition & 1 deletion docs/v2/examples/flags.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ For example this:

<!-- {
"args": ["&#45;&#45;help"],
"output": ".*Load configuration from FILE\n.*Language for the greeting.*"
"output": ".*Load configuration from FILE\n.*\n.*Language for the greeting.*"
} -->
```go
package main
Expand Down
1 change: 1 addition & 0 deletions docs/v3/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# v3 guide
1 change: 1 addition & 0 deletions flag-spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# `Spec` type that maps to this file structure.
flag_types:
bool:
no_default_text: true
struct_fields:
- name: Count
type: int
Expand Down
19 changes: 13 additions & 6 deletions flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,14 @@ type ActionableFlag interface {
// this interface be implemented.
type Flag interface {
fmt.Stringer

// Apply Flag settings to the given flag set
Apply(*flag.FlagSet) error

// All possible names for this flag
Names() []string

// Whether the flag has been set or not
IsSet() bool
}

Expand All @@ -108,6 +113,7 @@ type Flag interface {
type RequiredFlag interface {
Flag

// whether the flag is a required flag or not
IsRequired() bool
}

Expand Down Expand Up @@ -140,6 +146,12 @@ type DocGenerationSliceFlag interface {
IsSliceFlag() bool
}

// Countable is an interface to enable detection of flag values which support
// repetitive flags
type Countable interface {
Count() int
}

// VisibleFlag is an interface that allows to check if a flag is visible
type VisibleFlag interface {
Flag
Expand All @@ -153,15 +165,10 @@ type VisibleFlag interface {
type CategorizableFlag interface {
VisibleFlag

// Returns the category of the flag
GetCategory() string
}

// Countable is an interface to enable detection of flag values which support
// repetitive flags
type Countable interface {
Count() int
}

func flagSet(name string, flags []Flag) (*flag.FlagSet, error) {
set := flag.NewFlagSet(name, flag.ContinueOnError)

Expand Down
Loading

0 comments on commit c296830

Please sign in to comment.