Skip to content

Need a simpler example #281

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
nddipiazza opened this issue Apr 26, 2018 · 9 comments
Closed

Need a simpler example #281

nddipiazza opened this issue Apr 26, 2018 · 9 comments

Comments

@nddipiazza
Copy link

the example demo is wayyyy too complicated. 90% of people don't need that level of command line complexity. provide several examples each of varying simplicity.

@sampomike
Copy link

I totally concur. Well, such mind-twisting example is just defeating the whole point of using this library in the first place. It is rather easier to deal with low-level parsing of command line myself.

@g2david
Copy link

g2david commented May 8, 2018

I am very confused with new version. I need to see a simple argument parsing demo

@nddipiazza
Copy link
Author

@g2david @sampomike
#274
this might help. i have not verified it because i stopped using this library due to tons of issues when using it within mono

@Rainmaker52
Copy link

I like this approach. See if you feel that this is easier to understand:

        // Commandline options
        internal class CmdOptions
        {
            [Option('f', "file", Required = true, HelpText = "Database file to open")]
            public string DBFile { get; set; }

            [Option("driveletter", Default = @"X:\", HelpText = "Driveletter to use")]
            public string DriveLetter { get; set; }
        }

        //Entrypoint
        static void Main(string[] args)
        {
            var cmdOptions = Parser.Default.ParseArguments<CmdOptions>(args);
            cmdOptions.WithParsed(
                options => {
                    Main(options);
                });

        }

        //Overloaded main, called with CmdOptions from main(string[])
        static void Main(CmdOptions options)
        {
            Console.WriteLine($"Database file used {options.DBFile}");
            string dbFile = options.DBFile;

            Console.WriteLine($"Mounting to drive {options.DriveLetter}");
            string driveLetter = options.DriveLetter;
         }

@SlowPokeInTexas
Copy link

If I wanted to write Scala (or any other functional language), I would do so.

@jmarkman
Copy link

@Rainmaker52
Pardon the month+ necro, but I actually just finished struggling through the documentation by rubber-ducking it with someone in a .NET chatroom, and I definitely like the format of your approach. I'd love to help/be kept in the loop about updating the documentation.

@dpowers86
Copy link

@Rainmaker52 I second this. The only thing is that if main returns an int this setup dosen't work. I used this for mine.

CmdOptions opts;
Parser.Default.ParseArguments<Options>(args).WithParsed(options => { opts = options; });

@nddipiazza
Copy link
Author

nddipiazza commented Dec 17, 2018

@Rainmaker52 's example is exactly what the doctor ordered. let's get it in the wiki.

@JimHume
Copy link

JimHume commented Dec 17, 2018

It would be ideal to also include the actual command line that is being sent to the application.
I've been scratching my head trying to figure out why the most basic of items won't work, and I can't find a 'super duper happy path' example that actually shows me the proper input string so that I can use it in a unit test.

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

No branches or pull requests

9 participants