I'm creating a console app in .NET Core 5 which knows a set of commands.
The name of the application is Strict.exe
. These are the commands I need to parse.
strict.exe load mytext
strict.exe read
strict.exe explode
strict.exe stich 3 4 5 6
strict.exe case -pascal
strict.exe join -l "pqr"
strict.exe echo "Making C# array"
strict.exe implode -d ","
strict.exe join -r "abc"
To parse the commands I'm using CommandLineParser library - https://github.com/commandlineparser/commandline.
Now the issue is some of my commands are context aware. Like the first command load mytext
So if the text file is in same directory, It can be
load mytext
In case it is in a different directory, command can be
load "c:\Sample Data\mytext.txt"
Another issue is with Stich command. It can accept any number of arbitary values after 'stich'. Like
stich 1
stich 1 2
stich 1 2 3
Another case is command validation. If user is using a join
command. It should be followed by a flag like '-l
' or '-r
' then a string
. How can I enforce it.
I was able to parse normal commands using the library but I was not able to use it for my use case. How to create the Options class to cope up with the above requirements.
My current implementation can only parse 1st command
public class Options
{
[Option("load", Required = false, HelpText = "Loads a text file")]
public bool load { get; set; }
}