Merge commit '46043dd' into v3-porting
This commit is contained in:
commit
75f2d1a83a
18
altsrc/flag-spec.yaml
Normal file
18
altsrc/flag-spec.yaml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
# NOTE: this file is used by the tool defined in
|
||||||
|
# ./cmd/urfave-cli-genflags/main.go which uses the
|
||||||
|
# `Spec` type that maps to this file structure.
|
||||||
|
flag_types:
|
||||||
|
Bool:
|
||||||
|
Duration:
|
||||||
|
Float64:
|
||||||
|
Generic:
|
||||||
|
Int64:
|
||||||
|
Int:
|
||||||
|
IntSlice:
|
||||||
|
Int64Slice:
|
||||||
|
Float64Slice:
|
||||||
|
String:
|
||||||
|
Path:
|
||||||
|
StringSlice:
|
||||||
|
Uint64:
|
||||||
|
Uint:
|
@ -1,4 +1,4 @@
|
|||||||
// Code generated by fg; DO NOT EDIT.
|
// WARNING: this file is generated. DO NOT EDIT
|
||||||
|
|
||||||
package altsrc
|
package altsrc
|
||||||
|
|
||||||
@ -65,6 +65,25 @@ func (f *Float64Flag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.Float64Flag.Apply(set)
|
return f.Float64Flag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Float64SliceFlag is the flag type that wraps cli.Float64SliceFlag to allow
|
||||||
|
// for other values to be specified
|
||||||
|
type Float64SliceFlag struct {
|
||||||
|
*cli.Float64SliceFlag
|
||||||
|
set *flag.FlagSet
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewFloat64SliceFlag creates a new Float64SliceFlag
|
||||||
|
func NewFloat64SliceFlag(fl *cli.Float64SliceFlag) *Float64SliceFlag {
|
||||||
|
return &Float64SliceFlag{Float64SliceFlag: fl, set: nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
|
// the wrapped Float64SliceFlag.Apply
|
||||||
|
func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
|
||||||
|
f.set = set
|
||||||
|
return f.Float64SliceFlag.Apply(set)
|
||||||
|
}
|
||||||
|
|
||||||
// GenericFlag is the flag type that wraps cli.GenericFlag to allow
|
// GenericFlag is the flag type that wraps cli.GenericFlag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type GenericFlag struct {
|
type GenericFlag struct {
|
||||||
@ -84,25 +103,6 @@ func (f *GenericFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.GenericFlag.Apply(set)
|
return f.GenericFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int64Flag is the flag type that wraps cli.Int64Flag to allow
|
|
||||||
// for other values to be specified
|
|
||||||
type Int64Flag struct {
|
|
||||||
*cli.Int64Flag
|
|
||||||
set *flag.FlagSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewInt64Flag creates a new Int64Flag
|
|
||||||
func NewInt64Flag(fl *cli.Int64Flag) *Int64Flag {
|
|
||||||
return &Int64Flag{Int64Flag: fl, set: nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply saves the flagSet for later usage calls, then calls
|
|
||||||
// the wrapped Int64Flag.Apply
|
|
||||||
func (f *Int64Flag) Apply(set *flag.FlagSet) error {
|
|
||||||
f.set = set
|
|
||||||
return f.Int64Flag.Apply(set)
|
|
||||||
}
|
|
||||||
|
|
||||||
// IntFlag is the flag type that wraps cli.IntFlag to allow
|
// IntFlag is the flag type that wraps cli.IntFlag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type IntFlag struct {
|
type IntFlag struct {
|
||||||
@ -122,23 +122,23 @@ func (f *IntFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.IntFlag.Apply(set)
|
return f.IntFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow
|
// Int64Flag is the flag type that wraps cli.Int64Flag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type IntSliceFlag struct {
|
type Int64Flag struct {
|
||||||
*cli.IntSliceFlag
|
*cli.Int64Flag
|
||||||
set *flag.FlagSet
|
set *flag.FlagSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewIntSliceFlag creates a new IntSliceFlag
|
// NewInt64Flag creates a new Int64Flag
|
||||||
func NewIntSliceFlag(fl *cli.IntSliceFlag) *IntSliceFlag {
|
func NewInt64Flag(fl *cli.Int64Flag) *Int64Flag {
|
||||||
return &IntSliceFlag{IntSliceFlag: fl, set: nil}
|
return &Int64Flag{Int64Flag: fl, set: nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply saves the flagSet for later usage calls, then calls
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
// the wrapped IntSliceFlag.Apply
|
// the wrapped Int64Flag.Apply
|
||||||
func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
|
func (f *Int64Flag) Apply(set *flag.FlagSet) error {
|
||||||
f.set = set
|
f.set = set
|
||||||
return f.IntSliceFlag.Apply(set)
|
return f.Int64Flag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow
|
// Int64SliceFlag is the flag type that wraps cli.Int64SliceFlag to allow
|
||||||
@ -160,23 +160,42 @@ func (f *Int64SliceFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.Int64SliceFlag.Apply(set)
|
return f.Int64SliceFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Float64SliceFlag is the flag type that wraps cli.Float64SliceFlag to allow
|
// IntSliceFlag is the flag type that wraps cli.IntSliceFlag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type Float64SliceFlag struct {
|
type IntSliceFlag struct {
|
||||||
*cli.Float64SliceFlag
|
*cli.IntSliceFlag
|
||||||
set *flag.FlagSet
|
set *flag.FlagSet
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewFloat64SliceFlag creates a new Float64SliceFlag
|
// NewIntSliceFlag creates a new IntSliceFlag
|
||||||
func NewFloat64SliceFlag(fl *cli.Float64SliceFlag) *Float64SliceFlag {
|
func NewIntSliceFlag(fl *cli.IntSliceFlag) *IntSliceFlag {
|
||||||
return &Float64SliceFlag{Float64SliceFlag: fl, set: nil}
|
return &IntSliceFlag{IntSliceFlag: fl, set: nil}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Apply saves the flagSet for later usage calls, then calls the
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
// wrapped Float64SliceFlag.Apply
|
// the wrapped IntSliceFlag.Apply
|
||||||
func (f *Float64SliceFlag) Apply(set *flag.FlagSet) error {
|
func (f *IntSliceFlag) Apply(set *flag.FlagSet) error {
|
||||||
f.set = set
|
f.set = set
|
||||||
return f.Float64SliceFlag.Apply(set)
|
return f.IntSliceFlag.Apply(set)
|
||||||
|
}
|
||||||
|
|
||||||
|
// PathFlag is the flag type that wraps cli.PathFlag to allow
|
||||||
|
// for other values to be specified
|
||||||
|
type PathFlag struct {
|
||||||
|
*cli.PathFlag
|
||||||
|
set *flag.FlagSet
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPathFlag creates a new PathFlag
|
||||||
|
func NewPathFlag(fl *cli.PathFlag) *PathFlag {
|
||||||
|
return &PathFlag{PathFlag: fl, set: nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
|
// the wrapped PathFlag.Apply
|
||||||
|
func (f *PathFlag) Apply(set *flag.FlagSet) error {
|
||||||
|
f.set = set
|
||||||
|
return f.PathFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// StringFlag is the flag type that wraps cli.StringFlag to allow
|
// StringFlag is the flag type that wraps cli.StringFlag to allow
|
||||||
@ -198,25 +217,6 @@ func (f *StringFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.StringFlag.Apply(set)
|
return f.StringFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// PathFlag is the flag type that wraps cli.PathFlag to allow
|
|
||||||
// for other values to be specified
|
|
||||||
type PathFlag struct {
|
|
||||||
*cli.PathFlag
|
|
||||||
set *flag.FlagSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPathFlag creates a new PathFlag
|
|
||||||
func NewPathFlag(fl *cli.PathFlag) *PathFlag {
|
|
||||||
return &PathFlag{PathFlag: fl, set: nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply saves the flagSet for later usage calls, then calls the
|
|
||||||
// wrapped PathFlag.Apply
|
|
||||||
func (f *PathFlag) Apply(set *flag.FlagSet) error {
|
|
||||||
f.set = set
|
|
||||||
return f.PathFlag.Apply(set)
|
|
||||||
}
|
|
||||||
|
|
||||||
// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow
|
// StringSliceFlag is the flag type that wraps cli.StringSliceFlag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type StringSliceFlag struct {
|
type StringSliceFlag struct {
|
||||||
@ -236,6 +236,25 @@ func (f *StringSliceFlag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.StringSliceFlag.Apply(set)
|
return f.StringSliceFlag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UintFlag is the flag type that wraps cli.UintFlag to allow
|
||||||
|
// for other values to be specified
|
||||||
|
type UintFlag struct {
|
||||||
|
*cli.UintFlag
|
||||||
|
set *flag.FlagSet
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewUintFlag creates a new UintFlag
|
||||||
|
func NewUintFlag(fl *cli.UintFlag) *UintFlag {
|
||||||
|
return &UintFlag{UintFlag: fl, set: nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
|
// the wrapped UintFlag.Apply
|
||||||
|
func (f *UintFlag) Apply(set *flag.FlagSet) error {
|
||||||
|
f.set = set
|
||||||
|
return f.UintFlag.Apply(set)
|
||||||
|
}
|
||||||
|
|
||||||
// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow
|
// Uint64Flag is the flag type that wraps cli.Uint64Flag to allow
|
||||||
// for other values to be specified
|
// for other values to be specified
|
||||||
type Uint64Flag struct {
|
type Uint64Flag struct {
|
||||||
@ -255,21 +274,4 @@ func (f *Uint64Flag) Apply(set *flag.FlagSet) error {
|
|||||||
return f.Uint64Flag.Apply(set)
|
return f.Uint64Flag.Apply(set)
|
||||||
}
|
}
|
||||||
|
|
||||||
// UintFlag is the flag type that wraps cli.UintFlag to allow
|
// vim:ro
|
||||||
// for other values to be specified
|
|
||||||
type UintFlag struct {
|
|
||||||
*cli.UintFlag
|
|
||||||
set *flag.FlagSet
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUintFlag creates a new UintFlag
|
|
||||||
func NewUintFlag(fl *cli.UintFlag) *UintFlag {
|
|
||||||
return &UintFlag{UintFlag: fl, set: nil}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply saves the flagSet for later usage calls, then calls
|
|
||||||
// the wrapped UintFlag.Apply
|
|
||||||
func (f *UintFlag) Apply(set *flag.FlagSet) error {
|
|
||||||
f.set = set
|
|
||||||
return f.UintFlag.Apply(set)
|
|
||||||
}
|
|
||||||
|
@ -25,4 +25,5 @@ show-cover:
|
|||||||
|
|
||||||
.PHONY: run
|
.PHONY: run
|
||||||
run: build
|
run: build
|
||||||
./urfave-cli-genflags
|
./urfave-cli-genflags
|
||||||
|
./urfave-cli-genflags -f altsrc/flag-spec.yaml -o altsrc/flag_generated.go -p altsrc -a
|
||||||
|
34
cmd/urfave-cli-genflags/generated_altsrc.gotmpl
Normal file
34
cmd/urfave-cli-genflags/generated_altsrc.gotmpl
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
// WARNING: this file is generated. DO NOT EDIT
|
||||||
|
|
||||||
|
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
|
||||||
|
type {{.TypeName}} struct {
|
||||||
|
*cli.{{.TypeName}}
|
||||||
|
set *flag.FlagSet
|
||||||
|
}
|
||||||
|
|
||||||
|
// New{{.TypeName}} creates a new {{.TypeName}}
|
||||||
|
func New{{.TypeName}}(fl *cli.{{.TypeName}}) *{{.TypeName}} {
|
||||||
|
return &{{.TypeName}}{{"{"}}{{.TypeName}}: fl, set: nil}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply saves the flagSet for later usage calls, then calls
|
||||||
|
// the wrapped {{.TypeName}}.Apply
|
||||||
|
func (f *{{.TypeName}}) Apply(set *flag.FlagSet) error {
|
||||||
|
f.set = set
|
||||||
|
return f.{{.TypeName}}.Apply(set)
|
||||||
|
}
|
||||||
|
{{end}}{{/* /range .SortedFlagTypes */}}
|
||||||
|
|
||||||
|
// vim{{/* 👻 */}}:ro
|
||||||
|
{{/*
|
||||||
|
vim:filetype=gotexttmpl
|
||||||
|
*/}}
|
@ -32,6 +32,9 @@ var (
|
|||||||
//go:embed generated_test.gotmpl
|
//go:embed generated_test.gotmpl
|
||||||
TestTemplateString string
|
TestTemplateString string
|
||||||
|
|
||||||
|
//go:embed generated_altsrc.gotmpl
|
||||||
|
AltsrcTemplateString string
|
||||||
|
|
||||||
titler = cases.Title(language.Und, cases.NoLower)
|
titler = cases.Title(language.Und, cases.NoLower)
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,6 +61,10 @@ func main() {
|
|||||||
Name: "genflags",
|
Name: "genflags",
|
||||||
Usage: "Generate flag types for urfave/cli",
|
Usage: "Generate flag types for urfave/cli",
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: "altsrc",
|
||||||
|
Aliases: []string{"a"},
|
||||||
|
},
|
||||||
&cli.PathFlag{
|
&cli.PathFlag{
|
||||||
Name: "flag-spec-yaml",
|
Name: "flag-spec-yaml",
|
||||||
Aliases: []string{"f"},
|
Aliases: []string{"f"},
|
||||||
@ -148,12 +155,11 @@ func runGenFlags(cCtx *cli.Context) error {
|
|||||||
spec.UrfaveCLITestNamespace = "cli."
|
spec.UrfaveCLITestNamespace = "cli."
|
||||||
}
|
}
|
||||||
|
|
||||||
genTmpl, err := template.New("gen").Parse(TemplateString)
|
templateString := TemplateString
|
||||||
if err != nil {
|
if cCtx.IsSet("altsrc") {
|
||||||
return err
|
templateString = AltsrcTemplateString
|
||||||
}
|
}
|
||||||
|
genTmpl, err := template.New("gen").Parse(templateString)
|
||||||
genTestTmpl, err := template.New("gen_test").Parse(TestTemplateString)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -163,23 +169,32 @@ func runGenFlags(cCtx *cli.Context) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := os.WriteFile(cCtx.Path("generated-output"), genBuf.Bytes(), 0644); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-output")); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if cCtx.IsSet("altsrc") {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
genTestTmpl, err := template.New("gen_test").Parse(TestTemplateString)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
genTestBuf := &bytes.Buffer{}
|
genTestBuf := &bytes.Buffer{}
|
||||||
if err := genTestTmpl.Execute(genTestBuf, spec); err != nil {
|
if err := genTestTmpl.Execute(genTestBuf, spec); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(cCtx.Path("generated-output"), genBuf.Bytes(), 0644); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := os.WriteFile(cCtx.Path("generated-test-output"), genTestBuf.Bytes(), 0644); err != nil {
|
if err := os.WriteFile(cCtx.Path("generated-test-output"), genTestBuf.Bytes(), 0644); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-output")); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-test-output")); err != nil {
|
if _, err := sh(cCtx.Context, cCtx.Path("goimports"), "-w", cCtx.Path("generated-test-output")); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user