Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding "--help" parameter to C# console application

Almost all the .exe's I use via command line have a help function that gets called by the "--help" command.

How do I implement this in C#? Is it as simple as checking whether or not the parameter in args[] is the string "--help"??

like image 667
user2450099 Avatar asked Mar 10 '26 16:03

user2450099


1 Answers

With *nix commands, it's common to obtain help either via -h or --help. Many windows commands will offer help with /?. So it's not bad practice to do something like:

public static void Main(string[] args)
{
    if (args.Length == 1 && HelpRequired(args[0]))
    {
        DisplayHelp();
    }
    else
    {
        ...
    }
}

private static bool HelpRequired(string param)
{
    return param == "-h" || param == "--help" || param == "/?";
}
like image 81
David Arno Avatar answered Mar 13 '26 05:03

David Arno