Pointers and nils again

urfave-cli-integration
Dan Buch 2 years ago
parent d0c96803c8
commit 30449ba506
Signed by: meatballhat
GPG Key ID: A12F782281063434

@ -16,7 +16,7 @@ func main() {
log.SetFlags(0)
pCfg := argh.NewParserConfig()
pCfg.Prog = argh.CommandConfig{
pCfg.Prog = &argh.CommandConfig{
NValue: argh.OneOrMoreValue,
ValueNames: []string{"topping"},
Flags: &argh.Flags{

@ -61,7 +61,7 @@ func (p *parser) parseArgs() (*ParseTree, error) {
}
tracef("parseArgs() parsing %q as program command; cfg=%+#v", p.lit, p.cfg.Prog)
prog := p.parseCommand(&p.cfg.Prog)
prog := p.parseCommand(p.cfg.Prog)
tracef("parseArgs() top level node is %T", prog)

@ -27,7 +27,7 @@ func (nv NValue) Contains(i int) bool {
}
type ParserConfig struct {
Prog CommandConfig
Prog *CommandConfig
ScannerConfig *ScannerConfig
}
@ -43,8 +43,8 @@ func NewParserConfig(opts ...ParserOption) *ParserConfig {
}
}
if pCfg.Prog.IsZero() {
pCfg.Prog = CommandConfig{}
if pCfg.Prog == nil {
pCfg.Prog = &CommandConfig{}
pCfg.Prog.init()
}
@ -62,13 +62,6 @@ type CommandConfig struct {
Commands *Commands
}
func (cCfg *CommandConfig) IsZero() bool {
return cCfg.NValue == NValue(0) &&
cCfg.ValueNames == nil &&
cCfg.Flags == nil &&
cCfg.Commands == nil
}
func (cCfg *CommandConfig) init() {
if cCfg.ValueNames == nil {
cCfg.ValueNames = []string{}

@ -24,7 +24,7 @@ func TestParser(t *testing.T) {
"pies", "-eat", "--wat", "hello", "mario",
},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"e": {},
@ -98,8 +98,8 @@ func TestParser(t *testing.T) {
"pies", "--wat", "hello", "mario", "-eat",
},
cfg: &argh.ParserConfig{
Prog: func() argh.CommandConfig {
cmdCfg := argh.CommandConfig{
Prog: func() *argh.CommandConfig {
cmdCfg := &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"e": {Persist: true},
@ -193,7 +193,7 @@ func TestParser(t *testing.T) {
name: "one positional arg",
args: []string{"pizzas", "excel"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{NValue: 1},
Prog: &argh.CommandConfig{NValue: 1},
},
expPT: []argh.Node{
&argh.Command{
@ -219,7 +219,7 @@ func TestParser(t *testing.T) {
name: "many positional args",
args: []string{"pizzas", "excel", "wildly", "when", "feral"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
NValue: argh.OneOrMoreValue,
ValueNames: []string{"word"},
},
@ -267,7 +267,7 @@ func TestParser(t *testing.T) {
name: "long value-less flags",
args: []string{"pizzas", "--tasty", "--fresh", "--super-hot-right-now"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"tasty": {},
@ -312,7 +312,7 @@ func TestParser(t *testing.T) {
"--please",
},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{Map: map[string]argh.CommandConfig{}},
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
@ -391,7 +391,7 @@ func TestParser(t *testing.T) {
name: "short value-less flags",
args: []string{"pizzas", "-t", "-f", "-s"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"t": {},
@ -429,7 +429,7 @@ func TestParser(t *testing.T) {
name: "compound short flags",
args: []string{"pizzas", "-aca", "-blol"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"a": {},
@ -484,7 +484,7 @@ func TestParser(t *testing.T) {
name: "mixed long short value flags",
args: []string{"pizzas", "-a", "--ca", "-b", "1312", "-lol"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{Map: map[string]argh.CommandConfig{}},
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
@ -549,7 +549,7 @@ func TestParser(t *testing.T) {
name: "nested commands with positional args",
args: []string{"pizzas", "fly", "freely", "sometimes", "and", "other", "times", "fry", "deeply", "--forever"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{
Map: map[string]argh.CommandConfig{
"fly": argh.CommandConfig{
@ -632,7 +632,7 @@ func TestParser(t *testing.T) {
name: "compound flags with values",
args: []string{"pizzas", "-need", "sauce", "heat", "love", "-also", "over9000"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"a": {NValue: argh.ZeroOrMoreValue},
@ -735,7 +735,7 @@ func TestParser(t *testing.T) {
name: "command specific flags",
args: []string{"pizzas", "fly", "--freely", "fry", "--deeply", "-wAt", "hugs"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{
Map: map[string]argh.CommandConfig{
"fly": argh.CommandConfig{
@ -835,7 +835,7 @@ func TestParser(t *testing.T) {
name: "total weirdo",
args: []string{"PIZZAs", "^wAT@golf", "^^hecKing", "goose", "bonk", "^^FIERCENESS@-2"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{
Map: map[string]argh.CommandConfig{
"goose": argh.CommandConfig{
@ -910,7 +910,7 @@ func TestParser(t *testing.T) {
name: "windows like",
args: []string{"hotdog", "/f", "/L", "/o:ppy", "hats"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"f": {},
@ -957,7 +957,7 @@ func TestParser(t *testing.T) {
name: "invalid bare assignment",
args: []string{"pizzas", "=", "--wat"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Flags: &argh.Flags{
Map: map[string]argh.FlagConfig{
"wat": {},

@ -19,7 +19,7 @@ func TestQuerier_Program(t *testing.T) {
name: "typical",
args: []string{"pizzas", "ahoy", "--treatsa", "fun"},
cfg: &argh.ParserConfig{
Prog: argh.CommandConfig{
Prog: &argh.CommandConfig{
Commands: &argh.Commands{
Map: map[string]argh.CommandConfig{
"ahoy": argh.CommandConfig{

Loading…
Cancel
Save