bilal-fazlani / commanddotnet

A modern framework for building modern CLI apps
https://commanddotnet.bilal-fazlani.com
MIT License
569 stars 30 forks source link

AppRunner<object>.Run(args) returning error (1) in dotnet6 and shutting down #401

Closed asheesh1996 closed 2 years ago

asheesh1996 commented 2 years ago
 static void  Main(string[] args)
        {
            Console.WriteLine("Starting Application :)");
            var op = new AppRunner<Calculator>().Run(args);
            Console.WriteLine(op);

        }

following code snippet in dotnet 6 is giving error and closing the console app

drewburlingame commented 2 years ago

Hi @asheesh1996 the documentation has fallen behind a bit and I've been working to update it. I just merged a branch to master with updated Getting Started docs that should work for you. Let me know if there are still problems.

drewburlingame commented 2 years ago

@asheesh1996 has the updated documentation been helpful? Are you still having problems?

asheesh1996 commented 2 years ago

Hi @drewburlingame , I tried the updated documentation, following is the code snippet


using CommandDotNet;

namespace CommandLineTest
{

    public class Program
    {
        // this is the entry point of your application
        static int Main(string[] args)
        {
            // AppRunner<T> where T is the class defining your commands
            var OP = new AppRunner<Program>().Run(args);
            Console.WriteLine(OP.ToString());
            return OP;
        }

        // Add command with two positional arguments
        public void Add(int x, int y) => Console.WriteLine(x + y);

        // Subtract command with two positional arguments
        public void Subtract(int x, int y) => Console.WriteLine(x - y);
    }

}

And application is closing with following output


Usage: CommandLineTest.exe [command]

Commands:

  Add
  Subtract

Use "CommandLineTest.exe [command] --help" for more information about a command.
1

D:\Development\CommandLineTest\CommandLineTest\bin\Debug\net6.0\CommandLineTest.exe (process 19532) exited with code 1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .
drewburlingame commented 2 years ago

How are you executing the app? If you're not passing in a command to run or a help option, this is the expected behavior because CommandDotNet is not able to execute a command since there's no default command and no subcommand was specified. It prints the help as a courtesy. If you typed in CommandLineTest.exe -h or CommandLineTest.exe --help then you'd get the same output but OP would be 0. If you typed CommandLineTest.exe Add 1 1 then it should print 2 and OP would be 0.

drewburlingame commented 2 years ago

What I'll do is follow the convention used by the dotnet tool and print Required command was not provided. when this happens, and then the help text.

drewburlingame commented 2 years ago

This will go out with our next release.

drewburlingame commented 2 years ago

I've pushed 6.0.1. I'll close this for now. Reopen if the cause is different than what I've stated above.

asheesh1996 commented 2 years ago

Thanks for the response, I was using it in the wrong way. I got it working .

drewburlingame commented 2 years ago

Good to hear you got it working. Feel free to start up a discussion of you have questions or challenges.