Skip to content

IsNullOrEmpty on a command throws System.NullReferenceException #40

@craiginscotland

Description

@craiginscotland

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)
        {

        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions