arghing #1
@ -209,6 +209,29 @@ func (p *parser2) parseLongFlag(flCfgMap map[string]FlagConfig) Node {
|
|||||||
return p.parseConfiguredFlag(node, flCfg)
|
return p.parseConfiguredFlag(node, flCfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *parser2) parseCompoundShortFlag(flCfgMap map[string]FlagConfig) Node {
|
||||||
|
flagNodes := []Node{}
|
||||||
|
|
||||||
|
withoutFlagPrefix := p.lit[1:]
|
||||||
|
|
||||||
|
for i, r := range withoutFlagPrefix {
|
||||||
|
node := &Flag{Name: string(r)}
|
||||||
|
|
||||||
|
if i == len(withoutFlagPrefix)-1 {
|
||||||
|
flCfg, ok := flCfgMap[node.Name]
|
||||||
|
if ok {
|
||||||
|
flagNodes = append(flagNodes, p.parseConfiguredFlag(node, flCfg))
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
flagNodes = append(flagNodes, node)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &CompoundShortFlag{Nodes: flagNodes}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *parser2) parseConfiguredFlag(node *Flag, flCfg FlagConfig) Node {
|
func (p *parser2) parseConfiguredFlag(node *Flag, flCfg FlagConfig) Node {
|
||||||
values := map[string]string{}
|
values := map[string]string{}
|
||||||
nodes := []Node{}
|
nodes := []Node{}
|
||||||
@ -271,21 +294,6 @@ func (p *parser2) parseConfiguredFlag(node *Flag, flCfg FlagConfig) Node {
|
|||||||
return node
|
return node
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *parser2) parseCompoundShortFlag(flCfgMap map[string]FlagConfig) Node {
|
|
||||||
flagNodes := []Node{}
|
|
||||||
|
|
||||||
withoutFlagPrefix := p.lit[1:]
|
|
||||||
|
|
||||||
for i, r := range withoutFlagPrefix {
|
|
||||||
if i == len(withoutFlagPrefix)-1 {
|
|
||||||
tracef("parseCompoundShortFlag(...) TODO capture flag value(s)")
|
|
||||||
}
|
|
||||||
flagNodes = append(flagNodes, &Flag{Name: string(r)})
|
|
||||||
}
|
|
||||||
|
|
||||||
return &CompoundShortFlag{Nodes: flagNodes}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *parser2) parsePassthrough() Node {
|
func (p *parser2) parsePassthrough() Node {
|
||||||
nodes := []Node{}
|
nodes := []Node{}
|
||||||
|
|
||||||
|
@ -413,10 +413,8 @@ func TestParser2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
skip: true,
|
|
||||||
|
|
||||||
name: "command specific flags",
|
name: "command specific flags",
|
||||||
args: []string{"pizzas", "fly", "--freely", "fry", "--deeply", "-wAt"},
|
args: []string{"pizzas", "fly", "--freely", "fry", "--deeply", "-wAt", "hugs"},
|
||||||
cfg: &argh.ParserConfig{
|
cfg: &argh.ParserConfig{
|
||||||
Prog: argh.CommandConfig{
|
Prog: argh.CommandConfig{
|
||||||
Commands: map[string]argh.CommandConfig{
|
Commands: map[string]argh.CommandConfig{
|
||||||
@ -424,13 +422,15 @@ func TestParser2(t *testing.T) {
|
|||||||
Flags: map[string]argh.FlagConfig{
|
Flags: map[string]argh.FlagConfig{
|
||||||
"freely": {},
|
"freely": {},
|
||||||
},
|
},
|
||||||
},
|
Commands: map[string]argh.CommandConfig{
|
||||||
"fry": argh.CommandConfig{
|
"fry": argh.CommandConfig{
|
||||||
Flags: map[string]argh.FlagConfig{
|
Flags: map[string]argh.FlagConfig{
|
||||||
"deeply": {},
|
"deeply": {},
|
||||||
"w": {},
|
"w": {},
|
||||||
"A": {},
|
"A": {},
|
||||||
"t": {},
|
"t": argh.FlagConfig{NValue: 1},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -438,21 +438,39 @@ func TestParser2(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
expPT: []argh.Node{
|
expPT: []argh.Node{
|
||||||
argh.Command{Name: "pizzas"},
|
&argh.Command{
|
||||||
argh.ArgDelimiter{},
|
Name: "pizzas",
|
||||||
argh.Command{Name: "fly"},
|
|
||||||
argh.ArgDelimiter{},
|
|
||||||
argh.Flag{Name: "freely"},
|
|
||||||
argh.ArgDelimiter{},
|
|
||||||
argh.Command{Name: "fry"},
|
|
||||||
argh.ArgDelimiter{},
|
|
||||||
argh.Flag{Name: "deeply"},
|
|
||||||
argh.ArgDelimiter{},
|
|
||||||
argh.CompoundShortFlag{
|
|
||||||
Nodes: []argh.Node{
|
Nodes: []argh.Node{
|
||||||
argh.Flag{Name: "w"},
|
&argh.ArgDelimiter{},
|
||||||
argh.Flag{Name: "A"},
|
&argh.Command{
|
||||||
argh.Flag{Name: "t"},
|
Name: "fly",
|
||||||
|
Nodes: []argh.Node{
|
||||||
|
&argh.ArgDelimiter{},
|
||||||
|
&argh.Flag{Name: "freely"},
|
||||||
|
&argh.ArgDelimiter{},
|
||||||
|
&argh.Command{
|
||||||
|
Name: "fry",
|
||||||
|
Nodes: []argh.Node{
|
||||||
|
&argh.ArgDelimiter{},
|
||||||
|
&argh.Flag{Name: "deeply"},
|
||||||
|
&argh.ArgDelimiter{},
|
||||||
|
&argh.CompoundShortFlag{
|
||||||
|
Nodes: []argh.Node{
|
||||||
|
&argh.Flag{Name: "w"},
|
||||||
|
&argh.Flag{Name: "A"},
|
||||||
|
&argh.Flag{
|
||||||
|
Name: "t",
|
||||||
|
Values: map[string]string{"0": "hugs"},
|
||||||
|
Nodes: []argh.Node{
|
||||||
|
&argh.ArgDelimiter{},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user