Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose terminal subcommand #75

Merged
merged 2 commits into from
Apr 23, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flaggy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@ func TestComplexNesting(t *testing.T) {
t.Log("testE", testE)
t.FailNow()
}
if subcommandName := flaggy.DefaultParser.TerminalSubcommand().Name; subcommandName != "scD" {
mattwiller marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal("Used subcommand was incorrect:", subcommandName)
}

}

Expand Down Expand Up @@ -177,5 +180,8 @@ func TestParsePositionalsA(t *testing.T) {
if parser.TrailingArguments[1] != "trailingB" {
t.Fatal("Trailing argumentB was incorrect:", parser.TrailingArguments[1])
}
if subcommandName := parser.TerminalSubcommand().Name; subcommandName != "subcommand" {
mattwiller marked this conversation as resolved.
Show resolved Hide resolved
t.Fatal("Used subcommand was incorrect:", subcommandName)
}

}
4 changes: 4 additions & 0 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ type Parser struct {
subcommandContext *Subcommand // points to the most specific subcommand being used
}

mattwiller marked this conversation as resolved.
Show resolved Hide resolved
func (p *Parser) TerminalSubcommand() *Subcommand {
mattwiller marked this conversation as resolved.
Show resolved Hide resolved
return p.subcommandContext
}

// NewParser creates a new ArgumentParser ready to parse inputs
func NewParser(name string) *Parser {
// this can not be done inline because of struct embedding
Expand Down