Simple switches end up on "remaining" list even if parsed properly
See original GitHub issueInformation
- OS: Windows 10
- Version: 0.36 + 0.36.1-preview0.9
- Terminal: Cmder / Powershell
Describe the bug
What I mean by simple switch:
I assume we can pass bool values in two ways:
[CommandOption("-a <BOOL>")]
public bool A { get; set; }
[CommandOption("-b")]
public bool B { get; set; }
and use them as:
app -a true -b
By simple switch I mean -b
(but NOT -a <bool>
)
So, even if parsed properly simple switches are also reported on context.Remaining.Parsed
list
To Reproduce
using System;
using System.Linq;
using Newtonsoft.Json;
using Spectre.Console.Cli;
namespace SpectreBug
{
class Program
{
static void Main(string[] args)
{
var testArgs = new[] {
"-a", "true",
"-b"
};
new CommandApp<MyCommand>().Run(testArgs);
}
}
public class MyCommand: Command<MyCommand.Settings>
{
public class Settings: CommandSettings
{
[CommandOption("-a <BOOL>")]
public bool A { get; set; }
[CommandOption("-b")]
public bool B { get; set; }
}
public override int Execute(CommandContext context, Settings settings)
{
Console.WriteLine(JsonConvert.SerializeObject(settings));
var debug = new {
Parsed = context.Remaining.Parsed.ToDictionary(g => g.Key, g => g.ToArray()),
Raw = context.Remaining.Raw.ToArray()
};
Console.WriteLine(JsonConvert.SerializeObject(debug));
return 0;
}
}
}
Expected behavior
Both A
and B
are set to true
, and context.Remaining.Parsed
is empty.
{"A":true,"B":true}
{"Parsed":{},"Raw":[]}
Actual behaviour
Both A
and B
are set to true
, but context.Remaining.Parsed
still contains -b
like it was not recognized.
{"A":true,"B":true}
{"Parsed":{"b":[null]},"Raw":[]}
Additional context
…or maybe I don’t understand how bool options should be defined?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (5 by maintainers)
Top Results From Across the Web
How do I check that a switch block is exhaustive in ...
You will get an error if your switch statement is non-exhaustive as there will be a case where nothing is returned. From your...
Read more >Handy one-liners for SED
In method 2, spaces at # the beginning of the line are discarded in centering the line, and # no trailing spaces appear...
Read more >Control flow and error handling - JavaScript - MDN Web Docs
If no default clause is found, the program resumes execution at the statement following the end of switch . (By convention, the default...
Read more >What a very bad day at work taught me about building ...
I'm the new Director of Public Q&A at Stack Overflow. ... Even kind feedback can come off as caustic and mean when there...
Read more >optparse — Parser for command line options
As it parses the command line, optparse sets attributes of the options object ... args , the list of positional arguments leftover after...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
One thing I noticed here is that if you enable strict parsing, you get the expected behavior.
I’m not sure if this makes it a bug or expected behavior. But here’s the theoretically guilty line if this isn’t what should be happening
FYI. I’ve raised PR https://github.com/spectreconsole/spectre.console/pull/1070 which fixes this issue.