0

NDesk doesn't throw exceptions while parsing args. When I do debug without any arguments, the next step after try is the if and not the catch section. Any suggestions?

My code is:

using System;
using System.Collections.Generic;
using NDesk.Options;
namespace test
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string emailFrom = "";
            string emailTo = "";
            string emailSubject = "";
            string emailBody = "";
            bool showHelp = false;
            var p = new OptionSet()
            {
                { "f|from", "email to send from", v => emailFrom = v },
                { "t|to", "email to send to", v => emailTo = v },
                { "s|subject", "subject of email", v => emailSubject = v },
                { "b|body", "body of email", v => emailBody= v },
                { "h|help", "show this help and exit", v => showHelp = v != null }
            };
            List<string> extra;
            try
            {
                extra = p.Parse(args);
            }
            catch (OptionException e)
            {
                Console.WriteLine(e.Message);
                Console.WriteLine("Try `{0} --help` for more information.", projectName);
                return;
            }
            if (showHelp)
            {
                ShowHelp(p);
                return;
            }
            Console.WriteLine("Done");
        }

        private static void ShowHelp(OptionSet p)
        {
            // show help
        }
    }
}

I am following the documentation here:
http://ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html.

Connor Low
  • 5,900
  • 3
  • 31
  • 52

0 Answers0