Argu icon indicating copy to clipboard operation
Argu copied to clipboard

Dictionary / arbitrary key-value input

Open jcmrva opened this issue 5 years ago • 2 comments

Is there an ideal way of including a key/value input that would allow the user to provide the keys? Basically Dictionary<string,string> / (string * string) list but that's unsupported in the DU.

Argu ignores app.config entries it doesn't recognize. Can an option be added to the ArgumentParser to add unrecognized entries to the results list as one of the types above, and/or add support as a DU case but make it require NoCommandLine?

I realize those can be handled "on the side" but, as with post processing, there may be value in having Argu manage all the inputs. Having help text would be great.

jcmrva avatar Jul 21 '20 01:07 jcmrva

Is there an ideal way of including a key/value input that would allow the user to provide the keys? Basically Dictionary<string,string> / (string * string) list but that's unsupported in the DU.

You can defined key/value sources by implementing IConfigurationReader.

Argu ignores app.config entries it doesn't recognize. Can an option be added to the ArgumentParser to add unrecognized entries to the results list as one of the types above, and/or add support as a DU case but make it require NoCommandLine?

I'm not sure I understand the question, can you provide an example?

eiriktsarpalis avatar Jul 21 '20 12:07 eiriktsarpalis

I started going down the path of implementing IConfigurationReader but I don't see how to get the results into ParseResults<'T> if 'T doesn't support the type.

I'd like to have the user generate an app.config file of their CLI inputs (supported), then modify it with additional options for the next run.

<add key="directory" value="something" />
<add key="quiet" value="true" />
<add key="UserExample1" value="something" />
<add key="UserExample2" value="something else" />

Roughly...

// too many possible user inputs for this to contain them
type CliArguments = 
    | Directory of path:string
    | Quiet of bool
    | [<NoCommandLine>] UserExamples of (string * string) list 
    // ^ throws System.TypeInitializationException
    interface IArgParserTemplate with
        member s.Usage =
            match s with
            | Directory _ -> "input directory."
            | Quiet -> "suppress console output"
            | UserExamples _ -> "key/value user examples"

let parser = ArgumentParser.Create<CliArguments>()

[<EntryPoint>]
let main argv =

    let args = parser.Parse(argv, ConfigurationReader.FromAppSettings())

    // get UserExamples [("UserExample1","something");("UserExample1","something else")] from args

jcmrva avatar Jul 21 '20 15:07 jcmrva