Skip to content
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

Task< SomeReturnInfoClass > state = _app.RunAsyncWithState(args) #1501

Open
carsten-riedel opened this issue Mar 28, 2024 · 0 comments
Open

Comments

@carsten-riedel
Copy link

carsten-riedel commented Mar 28, 2024

Is your feature request related to a problem? Please describe.
Well the RunAsync command does not properly describe what happened inside the CommandApp it just gives a exitcode.
-1 on Command not found
0 on Help displayed
0 on Version Displayed
0 on Command successful (somehow standard)
all othere states.....
(Duplicates here)

Describe the solution you'd like
I want to determinate in some way if help was displayed or command was successful.
Task< SomeReturnInfoClass > state = _app.RunAsyncWithState(args); // just a simple state like -> exitcode, helpdisplayed, customcommandexectuted,VersionDisplayed, commandnotfound whatever.
Maybe returning -2 if just help is displayed and -3 on Version displayed is suitable. (depends on what's the real meaning of -1)

Describe alternatives you've considered
My command basicly returns 1 as successful execution.

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            await WaitForApplicationStartAsync(appLifetime.ApplicationStarted);
            var args = Environment.GetCommandLineArgs()[1..];

            //Exitcode 0 will be returned if just help is displayed, Exitcode -1 will be returned if command is not found.
            CommandAppExitCode = await _app.RunAsync(args);

            if (CommandAppExitCode == 0 || CommandAppExitCode == -1)
            {
                appLifetime.StopApplication();
                Environment.ExitCode = CommandAppExitCode;
            }

            if (CommandAppExitCode == 1)
            {
                Environment.ExitCode = 0;
            }
            try
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                        await Task.Delay(500, stoppingToken);
                }
            }
            catch (Exception ex)
            {
            }
        }

Additional context
As you can see in my example i am running the command as a background service, service should continue under some circumstances. Main problem is here if the help is displayed it should stop execution.


Please upvote 👍 this issue if you are interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant