-
Notifications
You must be signed in to change notification settings - Fork 350
Closed
Description
Sample code
Here is my sample code:
extension URL: ExpressibleByArgument {
public init?(argument: String) {
guard let url = URL(string: argument) else {
return nil
}
self = url
}
}struct MySample: ParsableCommand {
@Option(default: URL(string: FileManager.default.currentDirectoryPath)!, help: "Directory")
var directory: URL
}Produces output:
USAGE: sample [--directory <directory>]
OPTIONS:
-v, --version Print version
--directory <directory> Directory (default:
/Users/stewie/Library/Developer/Xcode/DerivedData/sample-blghzaivmncuwahbbafbmsweltpy/Build/Products/Debug)
-h, --help Show help information.
Expected behavior
I would expect the following
--directory <directory> Directory (default: current directory)
Actual behavior
I get:
--directory <directory> Directory (default:
/Users/stewie/Library/Developer/Xcode/DerivedData/sample-blghza
Current directory is common default value for file path like ls command. but 1294160 prints actual full path on help. Since defaultValueDescription is implemented 1294160 and it is not a protocol requirement.
Plan
Simply we can add defaultValueDescription in ExpressibleByArgument protocol
/// A type that can be expressed as a command-line argument.
public protocol ExpressibleByArgument {
/// Creates a new instance of this type from a command-line-specified
/// argument.
init?(argument: String)
/// Add this ↓
var defaultValueDescription: String { get }
}
Source Impact
Default behavior is given by default implementation declared in ExpressibleByArgument as Protocol Extensions. Only users who want to customize need to override defaultValueDescription.
Environment
ArgumentParser: 1294160
Related Forum Thread
Metadata
Metadata
Assignees
Labels
No labels