|
I'm trying out various command line option parser libraries, and those with verb or command options are few and far between. CLAP[^] is one that handles verbs, e.g. I don't need a separate Console application for each task, where the CLI library just parses the options for that command. I want a library where I can have one Console app, which accepts a command/verb and the options for that verb get parsed. So far I've found only CLAP and ManyConsole[^].
E.g. I don't want to have to have import.exe filename [-repeat] but I want console.exe import filename [-repeat] .
So I built a console application called Clap, with this code:
using System;
using CLAP;
namespace Clap
{
class Program
{
static void Main(string[] args)
{
Parser.Run<Program>(args);
}
[Verb(Description = "Imports an Impro CSV report file.", Aliases = "import,imp")]
static void ImportCsv(
[Required]
[Description("Full path to the file to import.")] string filePath)
{
Console.WriteLine("Will import " + filePath);
}
}
}
When I run the application with clap /? or clap import xxx , I get the error message
Unhandled Exception: System.TypeLoadException: Could not load type 'CLAP.Parser' from assembly 'Clap, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
at Clap.Program.Main(String[] args)
Google provided zero leads, so the problem was not well known. Well, how well known is CLAP itself? The Version-=1.0.0.0 gave me the key clue. It looked like the app was trying to load CLAP.Parser from my Clap assembly, not the CLAP library assembly, which is version 4.3.
All it took was to change my assembly name and default namespace to ClapCli and the problem vanished, but just BTW, CLAP is very, very thin. It throws exceptions when verbs arguments are omitted, and expects you to decorate a method to do something with the exception. It also has no built in help provider, and requires you to decorate a method that is called when the user requests help. You must compose and format your own help text for every verb and option.
modified 25-Apr-13 5:32am.
|
|
|
|
|
If you look at one of the examples you'll find this:
using CLAP;
using CLAP.Validation;
class ClapApp
{
.
.
.
}
> "Well, how well known is CLAP itself? "
"It's true that hard work never killed anyone. But I figure, why take the chance." - Ronald Reagan
That's what machines are for.
Got a problem?
Sleep on it.
modified 25-Apr-13 5:27am.
|
|
|
|
|
I just changed my app name from 'Clap' to 'ClapCli' and it was fixed. See the last paragraph, that I've just added.
|
|
|
|
|
Your code is like a dose of clap. Errr no, Clap. No, CLAP!
--
Harvey
|
|
|
|
|
How's this one[^]?
It handles verbs as well, and allows you to not use them as well.
Gryphons Are Awesome! Gryphons Are Awesome!
|
|
|
|
|
That ended up my second choice, but ManyConsole won, with better automatic help for available verbs and their options.
|
|
|
|
|
I think you need a virus checker on that...
your code has the clap.
|
|
|
|
|
Not to be pedantic, but I think you'll find the clap is a bacterial infection.
(Just don't ask how I became an expert )
|
|
|
|