Last active
February 16, 2017 14:38
-
-
Save dgg/1d54e3248643a2ba275cd4e549e299bd to your computer and use it in GitHub Desktop.
not-last-console-GoCommando
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal class CustomFactory : ICommandFactory | |
{ | |
public ICommand Create(Type commandType) | |
{ | |
// do some extremelly poor-man's service locations | |
if (commandType == typeof(Something)) | |
{ | |
return new Something(Console.Out); | |
} | |
if (commandType == typeof(SomethingElse)) | |
{ | |
return new SomethingElse(Console.Out); | |
} | |
throw new ArgumentException($"Unknown command type: {commandType}"); | |
} | |
public void Release(ICommand command) | |
{ | |
// we could gently free up resources from commands here | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*NotLastConsole_GoCommando*> .\doer.exe something-else -l asd -extra value | |
The following switches do not have a corresponding parameter: | |
-extra = value | |
Invoke with -help <command> to get help for each command. | |
Exit code: -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*NotLastConsole_GoCommando*> .\doer.exe -help something-else | |
Do something else | |
Type | |
doer.exe something-else <args> | |
where <args> can consist of the following parameters: | |
-locations / -l | |
places where the something else was done | |
Examples: | |
-locations singleLocation | |
-locations multiple,comma-separated-locations | |
-awesome / -a (flag/optional) | |
include if the something else was awesome |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*NotLastConsole_GoCommando*> .\doer.exe | |
Please invoke with a command - the following commands are available: | |
something - Do something | |
something-else - Do something else | |
Invoke with -help <command> to get help for each command. | |
Exit code: -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Command("something")] | |
[Description("Do something")] | |
public class Something : ICommand | |
{ | |
private readonly ADoerOfSomething _command; | |
public Something(TextWriter writer) | |
{ | |
_command = new ADoerOfSomething(writer); | |
} | |
[Parameter("location", "l")] | |
[Description("place where the something was done")] | |
public string Location { get; set; } | |
[Parameter("times", "t", optional: true, defaultValue: "1")] | |
[Description("number of times something was done")] | |
public int Times { get; set; } | |
[Parameter("awesome", "a", optional: true)] | |
[Description("include if the something was awesome")] | |
public bool Awesome { get; set; } | |
public void Run() | |
{ | |
var options = new OptionsForSomething | |
{ | |
Location = Location, | |
Awesome = Awesome, | |
Times = Times | |
}; | |
_command.Do(options); | |
} | |
} | |
[Command("something-else")] | |
[Description("Do something else")] | |
public class SomethingElse : ICommand | |
{ | |
private readonly ADoerOfSomethingElse _command; | |
public SomethingElse(TextWriter writer) | |
{ | |
_command = new ADoerOfSomethingElse(writer); | |
} | |
[Parameter("locations", "l")] | |
[Description("places where the something else was done")] | |
[Example("singleLocation")] | |
[Example("multiple,comma-separated-locations")] | |
public string Locations { get; set; } | |
[Parameter("awesome", "a", optional: true)] | |
[Description("include if the something else was awesome")] | |
public bool Awesome { get; set; } | |
private static readonly char[] _comma = {','}; | |
public void Run() | |
{ | |
var options = new OptionsForSomethingElse | |
{ | |
Locations = Locations.Split(_comma, StringSplitOptions.RemoveEmptyEntries), | |
NotSoAwesome = !Awesome | |
}; | |
_command.Do(options); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*NotLastConsole_GoCommando*> .\doer.exe something | |
The following required parameters are missing: | |
-location - place where the something was done | |
Invoke with -help <command> to get help for each command. | |
Exit code: -1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-locations / -l | |
places where the something else was done | |
Examples: | |
-locations singleLocation | |
-locations multiple,comma-separated-locations |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*NotLastConsole_GoCommando*> .\doer.exe something -l here -times x | |
System.FormatException: Could not set value 'x' on property named 'Times' on DgonDotNet.Blog.Samples.NotLastConsole_GoCommando.Something ---> System.FormatException: Input string was not in a correct | |
format. | |
at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) | |
at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) | |
at System.String.System.IConvertible.ToInt32(IFormatProvider provider) | |
at System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) | |
at System.Convert.ChangeType(Object value, Type conversionType) | |
at GoCommando.Internals.Parameter.SetValue(Object commandInstance, String value) | |
--- End of inner exception stack trace --- | |
at GoCommando.Internals.Parameter.SetValue(Object commandInstance, String value) | |
at GoCommando.Internals.CommandInvoker.ResolveParametersFromSwitches(IEnumerable`1 switches, ICommand commandInstance, ISet`1 setParameters) | |
at GoCommando.Internals.CommandInvoker.InnerInvoke(IEnumerable`1 switches, EnvironmentSettings environmentSettings) | |
at GoCommando.Internals.CommandInvoker.Invoke(IEnumerable`1 switches, EnvironmentSettings environmentSettings) | |
at GoCommando.Go.InnerRun(ICommandFactory commandFactory) | |
at GoCommando.Go.Run(ICommandFactory commandFactory) | |
Exit code: -2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Go.Run(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment