Skip to content

Add unparse extension with args (string[]) as return value #628

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

Closed
kapsiR opened this issue May 13, 2020 · 3 comments
Closed

Add unparse extension with args (string[]) as return value #628

kapsiR opened this issue May 13, 2020 · 3 comments
Milestone

Comments

@kapsiR
Copy link
Contributor

kapsiR commented May 13, 2020

It would be cool if I can use the unparsed string with the parser again.

e.g.

public static string[] FormatCommandLineArgs<T>(this Parser parser, T options, Action<UnParserSettings> configuration)

If the options instance is manually created, it would be possible to let commandline handle some default stuff:

        public async Task RunAsync(string[] args)
        {
            var parserResult = _parser.ParseArguments<MyOptions1, MyOptions2, MyOptions3>(args);

            await parserResult.MapResult(
                  async (MyOptions1 opts) => await Run1Async(opts),
                  async (MyOptions2 opts) => await Run2Async(opts),
                  async (MyOptions3 opts) => await Run3Async(opts),
                  async (IEnumerable<Error> errors) => await HandleParseErrorAsync(errors));
        }

        public async Task RunWithOptionsAsync<T>(T options)
        {
            string[] unparsedArgs = _parser.FormatCommandLineArgs(options);

            await RunAsync(unparsedArgs);
        }
@moh-hassan
Copy link
Collaborator

You can split the string generated from FormatCommandLineArgs to string[].
It is planned to provide this Extension method.

@moh-hassan moh-hassan added this to the 2.9 milestone May 23, 2020
@kapsiR
Copy link
Contributor Author

kapsiR commented May 25, 2020

@moh-hassan Thanks for adding this to the 2.9 milestone.
Splitting the string manually is painful, as you have to honor all different kinds of possibilities (especially with paths)

As alternative, this also would be a lot easier if I could provide the separator for FormatCommandLineArgs.

@moh-hassan
Copy link
Collaborator

@kapsiR
Yes, you are correct.
It's planned to provide a specialized splitter for FormatCommandLineArgs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants