question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting started, getting stuck

See original GitHub issue

Trying out this library with a toy example:

using CommandLine;
using System;

namespace Test_CommandArgs
{
    class Options
    {
        [Option('a', "optiona", Required = true, HelpText = "Option A")]
        string a {get; set;}
    }

    class Program
    {
        static void Main(string[] args)
        {
            var results = CommandLine.Parser.Default.ParseArguments<Options>(new string[] {});
            Console.WriteLine(results.Tag);
            Console.WriteLine(results.);
        }
    }
}

For the last line, I was hoping that VS would show me an attribute that I’d expect to hold a reference to the options object, but I can’t see it:

2018-03-03_8-44-23

What am I doing wrong? How do I get that reference?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
gbritton1commented, Mar 4, 2018

Hmmm. Pity it doesn’t expose the parsed value directly, say in a ParserResult.Value property. This means an awkward (to me) workaround like:

  class Program
   {
       static void Main(string[] args)
       {
           var results = CommandLine.Parser.Default.ParseArguments<Options>(args);
           results.WithParsed(o => RealMain(o));
           results.WithNotParsed(e =>  
               {
                   foreach(var i in e) Console.WriteLine("Error: " + i); 
                   throw new ArgumentException("Invalid Argument(s).");
               });
       }
       static void RealMain(Options o)
       {
           // Now we really start.
       }
   }
}

Also, both approaches are at odds with the example code which looks very nice https://archive.codeplex.com/?p=commandline

0reactions
ericnewton76commented, Mar 21, 2018

If the quickstart example could be improved for a user that isnt familiar with the library, a pull request would be welcome and thanks in order.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Helpful Tips When You're Stuck on Getting Started
Helpful Ideas When You're Stuck on Getting Started · 1. Think outside the rut. · 2. Ask yourself questions. · 3. Why power...
Read more >
Feeling Stuck? 7 Ways to Climb Out of a Slump
So the feeling of being stuck can be frustrating. Rather than beat yourself up over feeling stuck, treat yourself with self-compassion.
Read more >
How to Get Started When You're Stuck
Think about the project overall. Describe the goal to yourself in a few sentences. Write down all the major things that need to...
Read more >
Joe McCall - Getting Started, Getting Stuck and ... - YouTube
I recently interviewed Joe McCall to ask him about life before REI, the roadblocks most new investors face, what powers his most successful ......
Read more >
A Guide to Getting Unstuck - Forcing Function
Getting stuck is often caused by points of indecision. A lack of conviction is paralyzing and leads to an over-reliance on willpower. Motivation...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found