A NuGet package. It aim is to help you write extendable and command-based console programs in C# and .Net. https://www.craigoates.net/Software/Project/7
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
4.3 KiB

using Console.Waterworks;
using Console.Waterworks.Attributes;
using System;
namespace CW_Console
{
public class ConsoleCommands
{
[ListCommand()]
[Description("Displays the Help section at run-time")]
[Parameters("None")]
[Usage("CW_Console> Help")]
public static string Help()
{
CW_Liaison liaison = new CW_Liaison();
return liaison.RequestHelpDocumentation("CW_Console");
}
[ListCommand()]
[Description("Outputs to the console the command has been completed.")]
[Parameters("None")]
[Usage("CW_Console> Command1")]
public static string Command1() => "Command1 has completed";
[ListCommand()]
[Description("Repeats back to the user the string they entered.")]
[Parameters("<string> input")]
[Usage("CW_Console> Command2 \"Hello, World.\"")]
public static string Command2(string input) => $"Command2 has completed... {input} was entered";
[ListCommand()]
[Description("Repeats back to the user what int they entered.")]
[Parameters("<int> int1")]
[Usage("CW_Console> Command3 31")]
public static string Command3(int input) => $"Command3 has completed... The number {input} was entered";
[ListCommand()]
[Description("Takes the two ints and adds them together.")]
[Parameters("<int> int, <int> int2")]
[Usage("CW_Console> Command4 31 10")]
public static string Command4(int int1, int int2) => $"Command4 has completed... {int1} and {int2} was entered and make {int1 + int2} when added together";
[ListCommand()]
[Description("Take the int and double and adds them together.")]
[Parameters("<int> int1, <double1> double1")]
[Usage("CW_Console> Command5 31 25.4")]
public static string Command5(int int1, double double1) => $"Command5 has completed... {int1} and {double1} was entered and make {int1 + double1} when added together";
[ListCommand()]
[Description("Terminates the program.")]
[Parameters("None")]
[Usage("CW_Console> Quit")]
public static void Quit() => Environment.Exit(-1);
#region Alias-Methods
/*
* A NOTE ABOUT ALIAS-METHODS - DELETE AFTER READING
* =========================================================
* These methods are shorthand versions of the ones above.
* For the most part, this is a hack.
* But, it is a useful one.
* When new users start using your console program, they need help getting started.
* This is why I recommend using descriptive names for your command-methods.
* But, when your users become more familiar with the program, they will want terser commands.
* They will no longer need their hand holding. This is where these alias-commands come in.
*/
[ListCommand(false)] // change to true or delete "false" for it to show at run-time.
[Description("Alias for Command1. See Command1 for details.")]
[Parameters("None")]
[Usage("CW_Console> c1")]
public static string c1() => Command1();
[ListCommand(false)]
[Description("Alias for Command2. See Command2 for details.")]
[Parameters("None")]
[Usage("CW_Console> c2 \"Hello, World.\"")]
public static string c2(string input) => Command2(input);
[ListCommand(false)]
[Description("Alias for Command3. See Command3 for details.")]
[Parameters("None")]
[Usage("CW_Console> c3 78")]
public static string c3(int input) => Command3(input);
[ListCommand(false)]
[Description("Alias for Command4. See Command4 for details.")]
[Parameters("None")]
[Usage("CW_Console> c4 24 67")]
public static string c4(int int1, int int2) => Command4(int1, int2);
[ListCommand(false)]
[Description("Alias for Command5. See Command5 for details.")]
[Parameters("None")]
[Usage("CW_Console> c5 12 46.3")]
public static string c5(int int1, double double1) => Command5(int1, double1);
[ListCommand(false)]
[Description("Alias for Quit. See Quit for details.")]
[Parameters("None")]
[Usage("CW_Console> quit")]
public static void quit() => Quit();
#endregion
}
}