Quest: Reading Command-Line Arguments

Robson William
2 min readJul 19, 2020

This post is the first of a series that will be a journal of learnings as the Quest app is developed.

Quest is a CLI app for developers to quickly create to-dos through the command-line. This is the GitHub repo:
https://github.com/RWillup/quest

Reading Command-Line Arguments in C#

Initially Quest will have to be able to receive the following arguments:
- a command: new, complete, delete, etc.
- a text: this is the to-do text, e.g.: “refactor class x”
- a date-time: this will be the time of the reminder.

Creating the “command” argument

This is the very first draft of how the “new” command is being read:

On line 5, the program first checks if a string “new” exists in the args[] array. If it exists the program will then check if the “--todo” string was provided as well as a following string containing the text of the new todo.

To allow the non-positional arguments, the program is using the “Contains()” method on the args[] array. However, the argument of the “--todo” flag must immediately follow it, and to check this the program gets the index of the “--todo” flag and then increments it by 1 to get the content of the following argument.

This is it for the first post of Quest journal. If you are interested in the Quest project, your contribution on GitHub is very much welcome!

--

--

Robson William

Software developer. C# and Go. Enthusiast for gRPC and IoT. Also husband, father and believer in Christ. https://robwillup.com