Parsing the arguments of a console application
A request to a CLI application usually contains the name of the command (and an optional subcommand) along with arguments that provide values to the parameters needed by the command.
The first command we will be adding is the ability to add a new bookmark to the list of bookmarks.
The syntax of the expected command is the following:
$ bookmarkr link add <name> <url>
So, let’s modify the code to handle such a command!
We will start with the Main
method of the Program
class (located in the Program.cs
file). Why? Because this is the method that receives the input parameters from the user.
Since we may have multiple commands in the future, we will add a switch
statement to handle each one of these. Hence, the code will look like this:
namespace bookmarkr; class Program { static void Main(string[] args) { if...