Skip to content

.MapResultAsync not working #809

Closed
Closed
@asterictnl-lvdw

Description

@asterictnl-lvdw

Using the Pull from #390 I get an error when trying to use .MapResultAsync it does not exist in version 2.9.0preview1???

Changing it to MapResult makes the code work. But is Async not implemented correctly?

using CommandLine;
using CommandLine.Text;
using System;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    [Verb("add", HelpText = "Add file contents to the index.")]
    class AddOptions
    {
        //normal options here
    }

    [Verb("commit", HelpText = "Record changes to the repository.")]
    class CommitOptions
    {
        //normal options here
    }

    [Verb("clone", HelpText = "Clone a repository into a new directory.")]
    class CloneOptions
    {
        //normal options here
    }

    class Program
    {
        static async Task<int> Main(string[] args)
        {
            var parserResult = new Parser(c => c.HelpWriter = null);
            return await parserResult.ParseArguments<AddOptions, CommitOptions, CloneOptions>(args)
              .MapResult(
                (AddOptions opts) => RunAddAndReturnExitCodeAsync(opts),
                (CommitOptions opts) => RunCommitAndReturnExitCodeAsync(opts),
                (CloneOptions opts) => RunCloneAndReturnExitCodeAsync(opts),
                errs => Console.WriteLine(DisplayHelp()));
        }

        static Task<int> RunAddAndReturnExitCodeAsync(AddOptions opts)
        {
            throw new NotImplementedException();
        }

        private static Task<int> RunCommitAndReturnExitCodeAsync(CommitOptions opts)
        {
            throw new NotImplementedException();
        }

        private static Task<int> RunCloneAndReturnExitCodeAsync(CloneOptions opts)
        {
            throw new NotImplementedException();
        }

        private static async Task<int> DisplayHelp<T>(ParserResult<T> result)
        {
            var helpText = HelpText.AutoBuild(result, h =>
            {
                h.AdditionalNewLineAfterOption = false;
                h.Heading = "Myapp 2.0.0-beta"; //change header
                h.Copyright = "Copyright (c) 2019 Global.com"; //change copyright text
                return h;
            },
            e => e,
            verbsIndex: true);  //set verbsIndex to display verb help summary.
            Console.WriteLine(helpText);
            return -1;
        }
    }
}

Furthermore, I want to implement the custom help screen into the mapped results. I do need to change the Parser.Default for this. I have looked at the examples, but I couldn't get it to work.

Question: What do I need to change at errs => Console.WriteLine(DisplayHelp())); in order to make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions