Tuesday, April 8, 2014

Console application design : Introduction

Console applications are programs that run at the command line aka console. Let it be the Command prompt of the windows (the cmd.exe) or the bash in *nix operating systems. They are also known as CLIs (Command line interfaces) or CUIs(Console user interfaces) in contrast to GUIs (their graphical counterparts)

Almost everyone who has done programming has seen a console application in development.

Personally, these were my first programs that i have written, in C!

So lately, i have been working on a console application in C#. It's a program that calls a web based API and accumulates the XML results the API spits out and generates a huge file.

Console applications have a common set of terminology no matter which programming language you have used to develop them or where they are running.

Some of these are command line arguments, the input,output and the error streams, piping, help.

For example, a program may take in a file name as a command line argument and do some processing on it and display results. An example may be the number of lines in the file. Or the attributes of the file in the file system.

And then how the program can be used can be intuitive if it has a help system that users can look at by invoking the program with a /? or -h option.

So, i was wondering, and i have never wondered before, until i saw Node.js command line program development using libraries, for parsing command line arguments, displaying help etc such as Commander.

Interestingly, the Node.js commander has been inspired by Ruby's Commander. It should not be so surprising since both of these tools are produced at the same shop.

These libraries are cool since they help us with developing the applications rapidly focusing on the application development instead of the common chores of every command line application such as displaying help, options and command line arguments parsing!

Then i wondered if there were any best design practices for developing in the C# world, or a library, that would help me with the common stuff in each command based program?

Then i read this wonderful article, that i recommend strongly for any developer to understand how command line programs work and giving ideas in designing them.

I hope you see the value of the article as i have.

Also, apparently there is a library that people use called Command line parser library for the C# world!

In it's own words

"The Command Line Parser Library offers to CLR applications a clean and concise API for manipulating command line arguments and related tasks. It allows you to display an help screen with an high degree of customization and a simple way to report syntax errors to the user. Everything that is boring and repetitive to be programmed stands up on library shoulders, letting you concentrate yourself on core logic. "

Awesome, so fire up a console based project in Visual studio.
Install the nuget package using the command

PM>Install-Package CommandLineParser

and start developing your next beautiful Command line program!

I will build one and post an example soon!

No comments:

Post a Comment