A project that makes it easier to add command line arguments to applications.
-
Install the NuGet package. It adds the SimpleArgs dll and an ArgsHandler.cs file.
install-package Rhyous.SimpleArgs // Or if you don't want a separate dll, install this: install-package Rhyous.SimpleArgs.Sources
-
Add your new Arguments to the InitializeArguments override of the ArgsHandler.cs file.
public override void InitializeArguments() { Arguments.AddRange(new List<Argument> { new Argument { Name = "Echo", ShortName = "E", Description = "I echo to the console whater you put after Echo=", Example = "Echo=\"Hello, World!\"", Action = (value) => { Console.WriteLine(value);} }, // Add more args here }); }
-
In Program.cs add this line of code to Main()
static void Main(string[] args) { new ArgsManager<ArgsHandler>().Start(args); }
-
In the ArgsHandler.cs file, your new take action point is in the HandleArgs() method.
public void HandleArgs(IReadArgs inArgsHandler) { base.HandleArgs(inArgsHandler); Console.WriteLine("I handled the args!!!"); // This is where you start your work now }
-
If you run with no args, you will be given usage.
Usage: SimpleArgs.Example.exe Echo="Hello, World!" Arguments: Echo (Optional) I echo to the console whater you put after Echo= Press any key to continue . . .
-
Access your arguments statically anywhere using static class Args.
Args.Value("Echo") // returns value Args.Get("Echo") // Returns Argument object