Skip to content

Commit

Permalink
Added script to generate altsrc flag definitions, restricted list of …
Browse files Browse the repository at this point in the history
…types to the ones that provide implementation of FlagInputSourceExtension. The original program to generate altsrc flags is nowhere to be found, so replaced with fg.py. The types of altsrc flags are now limited to the subset that provide FlagInputSourceExtension implementation and have matching methods in InputSourceContext interface. Removed types where never updated from the input source.
  • Loading branch information
ipostelnik committed Feb 12, 2021
1 parent 92d7784 commit dc5f4fc
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 105 deletions.
45 changes: 45 additions & 0 deletions altsrc/fg.py
@@ -0,0 +1,45 @@
# Only types that provide implementation of FlagInputSourceExtension can be listed here
# please keep list sorted alphabetically
flag_types = [
"Bool",
"Duration",
"Float64",
"Generic",
"Int",
"IntSlice",
"Path",
"String",
"StringSlice",
]

print('''// Code generated by fg.py; DO NOT EDIT.
package altsrc
import (
"flag"
"github.com/urfave/cli/v2"
)''')

for t in flag_types:
print(f'''
// {t}Flag is the flag type that wraps cli.{t}Flag to allow
// for other values to be specified
type {t}Flag struct {{
*cli.{t}Flag
set *flag.FlagSet
}}
var _ FlagInputSourceExtension = (*{t}Flag)(nil)
// New{t}Flag creates a new {t}Flag
func New{t}Flag(fl *cli.{t}Flag) *{t}Flag {{
return &{t}Flag{{{t}Flag: fl, set: nil}}
}}
// Apply saves the flagSet for later usage calls, then calls
// the wrapped {t}Flag.Apply
func (f *{t}Flag) Apply(set *flag.FlagSet) error {{
f.set = set
return f.{t}Flag.Apply(set)
}}''')
124 changes: 19 additions & 105 deletions altsrc/flag_generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit dc5f4fc

Please sign in to comment.