-
Notifications
You must be signed in to change notification settings - Fork 336
Print supported values in synopses, when practical #620
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
781b82b
0ba70c4
76d5bae
129a63a
74b0152
dcc35d2
c9d8a87
286c606
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//===----------------------------------------------------------*- swift -*-===// | ||
// | ||
// This source file is part of the Swift Argument Parser open source project | ||
// | ||
// Copyright (c) 2024 Apple Inc. and the Swift project authors | ||
// Licensed under Apache License v2.0 with Runtime Library Exception | ||
// | ||
// See https://swift.org/LICENSE.txt for license information | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import XCTest | ||
import ArgumentParserTestHelpers | ||
@testable import ArgumentParser | ||
|
||
extension HelpGenerationTests { | ||
enum Fruit: String, ExpressibleByArgument, CaseIterable { | ||
case apple, banana, coconut, dragonFruit = "dragon-fruit", elderberry, fig, grape, honeydew | ||
} | ||
|
||
enum Action: String, ExpressibleByArgument, CaseIterable { | ||
case purchase, sample, refund = "return" | ||
} | ||
|
||
enum Count: Int, ExpressibleByArgument, CaseIterable { | ||
case zero, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eighteen, nineteen, twenty | ||
} | ||
|
||
enum Ripeness: String, ExpressibleByArgument, CaseIterable { | ||
case under, perfect, over | ||
} | ||
|
||
struct FruitStore: ParsableArguments { | ||
@Argument(help: "The transaction type") | ||
var action: Action = .purchase | ||
|
||
@Argument(help: "The fruit to purchase") | ||
var fruit: Fruit | ||
|
||
@Option(help: "The number of fruit to purchase") | ||
var quantity: Count = .one | ||
|
||
@Option(help: "The desired ripeness of fruit") | ||
var ripeness: Ripeness = .perfect | ||
} | ||
|
||
func testFruitStoreHelp() { | ||
AssertHelp(.default, for: FruitStore.self, equals: """ | ||
USAGE: fruit_store [<purchase|sample|return>] <fruit> [--quantity <quantity>] [--ripeness <under|perfect|over>] | ||
|
||
ARGUMENTS: | ||
<action> The transaction type (values: purchase, sample, | ||
return; default: purchase) | ||
<fruit> The fruit to purchase (values: apple, banana, | ||
coconut, dragon-fruit, elderberry, fig, grape, | ||
honeydew) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like replacing
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm certain that I've used a cli before that had this feature, but over the past two weeks I could not remember what it was. It did have the issue you describe though, and I like your solution! Another possibility is that ArgumentParser only expand values when showing a short help (such as gets printed after a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ohh the tool I'm thinking of is something I use frequently at work. Instead of an expanded
I was thinking |
||
|
||
OPTIONS: | ||
--quantity <quantity> The number of fruit to purchase (values: 0, 1, 2, 3, | ||
4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, | ||
19, 20; default: 1) | ||
--ripeness <ripeness> The desired ripeness of fruit (values: under, | ||
perfect, over; default: perfect) | ||
-h, --help Show help information. | ||
|
||
""") | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Likewise, it seems like this loses the context that add/multiply/stats are subcommands.