commandline icon indicating copy to clipboard operation
commandline copied to clipboard

verbs with same or options

Open rychlym opened this issue 1 year ago • 0 comments

Hello, I would like to ask you, whether there can be considered having some verbs with similar or even same options? That is, when the option classes have some relations like inheritance or they are based on same type in F#. Is there possibility to have somehow Parsed<CommonType> with additional info related to verb itself - like verb string or verb attribute?

An example in F#

open CommandLine

type CommonOptions = {
    [<Option('c', "connectionString", Required = true, HelpText = "MongoDB connection string.")>]
    ConnectionString: string
    [<Option('n', "dbCollection", Required = true, HelpText = "Database and collection name in the format 'databaseName.collectionName'.")>]
    DbCollection: string
    [<Option('d', "dir", Required = true, HelpText = "Directory path for serialization or deserialization.")>]
    Directory: string
    [<Option('b', "batchSize", Default = 1000, HelpText = "Batch size for processing.")>]
    BatchSize: int
    [<Option('s', "skip", Default = 0, HelpText = "Number of chunks to skip.")>]
    Skip: int
}
[<Verb("dump", HelpText = "Serialize (dump) a MongoDB collection to a json.gz file.")>]
type SerializeOptions = CommonOptions

[<Verb("restore", HelpText = "Deserialize (restore) a json.gz file to a MongoDB collection.")>]
type DeserializeOptions = CommonOptions

Then the classic handling as described in the main page let result = Parser.Default.ParseArguments<SerializeOptions, DeserializeOptions>(argv) ... won't work (matches with NotParsed).

rychlym avatar Aug 19 '24 18:08 rychlym