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 all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions flaggy_test.go
Expand Up @@ -108,6 +108,9 @@ func TestComplexNesting(t *testing.T) {
t.Log("testE", testE)
t.FailNow()
}
if subcommandName := flaggy.DefaultParser.TrailingSubcommand().Name; subcommandName != "scD" {
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.TrailingSubcommand().Name; subcommandName != "subcommand" {
t.Fatal("Used subcommand was incorrect:", subcommandName)
}

}
5 changes: 5 additions & 0 deletions parser.go
Expand Up @@ -26,6 +26,11 @@ type Parser struct {
subcommandContext *Subcommand // points to the most specific subcommand being used
}

mattwiller marked this conversation as resolved.
Show resolved Hide resolved
TrailingSubcommand returns the last and most specific subcommand invoked.
func (p *Parser) TrailingSubcommand() *Subcommand {
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