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

IsNullOrEmpty on a command throws System.NullReferenceException #40

Open
craiginscotland opened this issue Aug 8, 2019 · 0 comments
Open

Comments

@craiginscotland
Copy link

When a command is not present, I should be able to reference it in the dictionary and use .IsNullOrEmpty to check for it's present. But it throws System.NullReferenceException instead.

In my case, I did not mark as optional. I used the version where I gave 2 example command lines, each with a different COMMAND perhaps that's the issue?

There is a workaround below, but I would have thought you were populate a default Object in the dictionary so that the IsNullOrEmpty could be used.

Snippet of syntax below.

[TestMethod]
public void Test_CommandLine()
{
const string USAGE = @"prog.

        Usage: prog PREPARE (--folderpath <path> | --azure --jobid <jobid> --simrun <simrun> --token <token> --host <host>)
               prog SIMIULATE --scenario <scenario_name> (--folderpath <path> | --azure --simrun <simrun> --token <token> --host <host>)";

        var opt = new Docopt();

        var arguments = opt.Apply(USAGE, "simulate --scenario senario1 --azure --simrun simrun --token token --host host");
        
        //This would crash
        if(arguments["PREPARE"].IsNullOrEmpty)
        {

        }

        //So would have to do this instead.
        if (arguments["PREPARE"] != null)
        {

        }
    }
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

1 participant