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.

Allow empty arguments when using double dashed args

See original GitHub issue

Background

A pattern that we’ve seen is to have use environment variables as values for Cake script arguments. e.g.

dotnet cake --argName=%ARG_NAME_VALUE%

If the %ARG_NAME_VALUE% environment value exists and has a value, everything works as expected.

However, if the environment variable does not exist, or its value is empty, the user receives an error from the Cake runner: Expected an option value.

The current workaround is to use (space) instead of = if the value can be empty/null. e.g.

dotnet cake --argName %ARG_NAME_VALUE%

Proposal

This issue intends to make the necessary updates to allow empty arguments when using the --argName= syntax, which translates to the argument value being null for the build script.

NB: Heads-up that we use Spectre.Console for parsing arguments, so there’s a little bit of investigation needed to see if the fix can (and should) be done directly in Cake, of if it should be fixed upstream. If you discover that the fix doesn’t belong in Cake, you’d need to send a PR to Spectre.Console and the fix in Cake would be just upgrading to a newer version of Spectre.Console.


Related:

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Nisha2015commented, Oct 20, 2021

Opened the issue in Spectre.Console repo https://github.com/spectreconsole/spectre.console/issues/594

1reaction
Nisha2015commented, Oct 19, 2021

Update:

I’ve worked on this, and debugged the issue. Issue is coming from Spectre.Console.Cli in ScanOptions method of CommandTreeTokenizer class. Below is the code throwing the exception, this is coming as the value of environment variable is empty or null, so the if condition i.e. if (!reader.TryPeek(out _)) is being satisfied and exception is thrown.

 if (reader.TryPeek(out character))
{
	// Encountered a separator?
	if (character == '=' || character == ':')
	{
		reader.Read(); // Consume
		context.AddRemaining(character);

		if (!reader.TryPeek(out _))
		{
			var token = new CommandTreeToken(CommandTreeToken.Kind.String, reader.Position, "=", "=");
			throw CommandParseException.OptionValueWasExpected(reader.Original, token);
		}

		result.Add(ScanString(context, reader));
	}
}

I will be working on this further and raising a PR against Spectre.Console repository.

Read more comments on GitHub >

github_iconTop Results From Across the Web

'argparse' with optional positional arguments that start with ...
This is a known issue (https://bugs.python.org/issue15112, argparse: nargs='*' positional argument doesn't accept any items if preceded by ...
Read more >
Signal the end of option arguments: double dashes `--` vs ...
The double dash is the POSIX definition for the end of the options. After that, only file type arguments are allowed.
Read more >
Double Dash (--) parameters in Bash Script
I have a project I am working on that requires a parameter with a double dash. For example, running the command should look...
Read more >
What's the difference betwen the single dash and double ...
The double hyphen disambiguates the command-line argument, ensuring that tar interprets it as exclude rather than a combination of e , x ,...
Read more >
What's the difference between one-dash and two- ...
It has nothing to do with parameters at all. Many options have a short form and a long form, and many have one...
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