using System.Collections.Generic;
public static void Main()
var line=new String('-',40);
Console.WriteLine("---show help for verbs ------");
var args = "--help".Split();
Console.WriteLine("---show help for clone verb ------");
args = "clone --help".Split();
args = "clone git://git.kernel.org/pub/scm/.../linux.git".Split();
args = new[] { "commit", "-m", "update parser setting" };
public static void Start(string[] args)
Console.WriteLine($"Args: {string.Join(' ',args.Select(x => $"\"{x}\""))}");
Parser.Default.ParseArguments(args, types)
.WithNotParsed(HandleErrors);
static Type[] LoadVerbs()
return Assembly.GetExecutingAssembly().GetTypes()
.Where(t => t.GetCustomAttribute<VerbAttribute>() != null).ToArray();
private static void Run(object obj)
void RunClone(CloneOptions opts)
Console.WriteLine("Processing Verb 'Clone'");
void RunCommit(CommitOptions opts)
Console.WriteLine("Processing Verb 'Commit'");
Console.WriteLine($"Message= {opts.Message}");
void RunAdd(AddOptions opts)
Console.WriteLine("Processing Verb 'Add'");
private static void HandleErrors(IEnumerable<Error> obj)
[Verb("clone", HelpText = "Clone a repository into a new directory.")]
internal class CloneOptions
[Option('l', "local", HelpText = HelpConstant.Clone_local)]
public bool Local { get; set; }
[Option('q', "quiet", HelpText = HelpConstant.Clone_quiet)]
public bool Quiet { get; set; }
[Value(0, MetaName = "Reoisitory", HelpText = HelpConstant.Clone_repository)]
public string Repository { get; set; }
[Usage(ApplicationAlias = "yourapp")]
public static IEnumerable<Example> Examples
yield return new Example("Normal scenario", new CloneOptions { Local = true });
[Verb("commit", HelpText = "Record changes to the repository.")]
internal class CommitOptions
[Option('i', "interactive")]
public bool Interactive { get; set; }
public bool All { get; set; }
[Option('m', "message", Required = true)]
public string Message { get; set; }
[Verb("add", HelpText = "Add file contents to the index.")]
internal class AddOptions
public bool DryRun { get; set; }
public bool Force { get; set; }
public const string Clone_local = "When the repository to clone from is on a local machine, this flag bypasses the normal \"Git aware\" transport mechanism and clones the repository by making a copy of HEAD and everything under objects and refs directories.";
public const string Clone_quiet = "Operate quietly. Progress is not reported to the standard error stream.";
public const string Clone_repository = "The (possibly remote) repository to clone from. See the GIT URLS section below for more information on specifying repositories.";
public const string Commit_message = "Use the given <msg> as the commit message. If multiple -m options are given, their values are concatenated as separate paragraphs.";
[AttributeUsage(AttributeTargets.All)]
class CustomAttribute: Attribute {}