public void Execute(string command) { var factory = new CommandFactory(); factory.RegisterCommands(typeof(NewCommand).Assembly); factory.BuildRun(command).Execute(); }
public async Task can_execute_command_constructor_custom_usage_all_optional_arguments() { var factory = new CommandFactory(); factory.RegisterCommand <OptionalArgumentsCommand>(); var run = factory.BuildRun("optionalarguments"); (await run.Execute()).ShouldBe(true); }
public async Task can_execute_command_no_default_constructor() { var factory = new CommandFactory(new NoDefaultConstructorCommandCreator()); factory.RegisterCommand <NoDefaultConstructorCommand>(); var run = factory.BuildRun("nodefaultconstructor"); (await run.Execute()).ShouldBe(true); }
public void build_command_with_default_command_and_empty() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(NoArgCommand); factory.BuildRun("").Command.ShouldBeOfType <NoArgCommand>(); }
public void should_allow_negative_numbes_in_flag() { var factory = new CommandFactory(); factory.RegisterCommand <MyCommand>(); factory.BuildRun("my \"-3\" --num \"-5\"") .Input.ShouldBeOfType <MyInput>() .NumFlag.ShouldBe(-5); }
public void should_allow_negative_numbers_in_arguments() { var factory = new CommandFactory(); factory.RegisterCommand <MyCommand>(); factory.BuildRun("my \"-3\"") .Input.ShouldBeOfType <MyInput>() .ArgNum.ShouldBe(-3); }
public void still_use_help_with_default_command() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(RebuildAuthorizationCommand); factory.BuildRun("help").Command.ShouldBeOfType <HelpCommand>(); }
public async Task set_up_command_prereq_using_beforebuild() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.BeforeBuild = (commandName, input) => { ConfigureMe.IsSet = true; }; var run = factory.BuildRun("depends-static"); (await run.Execute()).ShouldBe(true); }
public void fetch_the_help_command_if_the_command_is_question_mark() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var run = factory.BuildRun(new [] { "?" }); run.Command.ShouldBeOfType <HelpCommand>(); run.Input.ShouldBeOfType <HelpInput>().CommandTypes .ShouldContain(typeof(MyCommand)); }
public void build_the_default_command_using_arguments() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(RebuildAuthorizationCommand); factory.BuildRun("Hank").Input .ShouldBeOfType <MyCommandInput>() .Name.ShouldBe("Hank"); }
public void fetch_the_help_command_if_the_args_are_empty() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var run = factory.BuildRun(new string[0]); run.Command.ShouldBeOfType <HelpCommand>(); run.Input.ShouldBeOfType <HelpInput>().CommandTypes .ShouldContain(typeof(MyCommand)); }
public void build_command_with_multiargs() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var run = factory.BuildRun("my Jeremy -ft"); var input = run.Input.ShouldBeOfType <MyCommandInput>(); input.ForceFlag.ShouldBeTrue(); input.SecondFlag.ShouldBeFalse(); input.ThirdFlag.ShouldBeTrue(); }
public void trying_to_build_a_missing_command_will_list_the_existing_commands() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var commandRun = factory.BuildRun("junk"); var theInput = commandRun.Input.ShouldBeOfType <HelpInput>(); theInput.Name.ShouldEqual("junk"); theInput.InvalidCommandName.ShouldBeTrue(); commandRun.Command.ShouldBeOfType <HelpCommand>(); }
public void build_command_from_a_string() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var run = factory.BuildRun("my Jeremy --force"); run.Command.ShouldBeOfType <MyCommand>(); var input = run.Input.ShouldBeOfType <MyCommandInput>(); input.Name.ShouldEqual("Jeremy"); input.ForceFlag.ShouldBeTrue(); }
public void build_help_command_with_valid_name_argument() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); var commandRun = factory.BuildRun("help my"); var theInput = commandRun.Input.ShouldBeOfType <HelpInput>(); theInput.Name.ShouldBe("my"); theInput.InvalidCommandName.ShouldBeFalse(); theInput.Usage.ShouldNotBeNull(); commandRun.Command.ShouldBeOfType <HelpCommand>(); }
public void build_command_with_default_command_and_first_arg_is_flag() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(OnlyFlagsCommand); var commandRun = factory.BuildRun("--verbose"); commandRun.Command.ShouldBeOfType <OnlyFlagsCommand>(); commandRun.Input.ShouldBeOfType <OnlyFlagsInput>() .VerboseFlag.ShouldBeTrue(); }
public void build_help_command_with_invalid_name_argument() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var commandRun = factory.BuildRun("help junk"); var theInput = commandRun.Input.ShouldBeOfType <HelpInput>(); theInput.Name.ShouldEqual("junk"); theInput.InvalidCommandName.ShouldBeTrue(); theInput.Usage.ShouldBeNull(); commandRun.Command.ShouldBeOfType <HelpCommand>(); }
public void build_command_with_default_command_and_first_arg_for_the_default_command() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(SillyCommand); var commandRun = factory.BuildRun("blue"); commandRun.Command.ShouldBeOfType <SillyCommand>(); commandRun.Input.ShouldBeOfType <MyCommandInput>() .Name.ShouldBe("blue"); }
public void build_command_with_default_command_and_first_arg_is_flag_that_is_not_valid() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); factory.DefaultCommand = typeof(OnlyFlagsCommand); var commandRun = factory.BuildRun("--wrong"); commandRun.Command.ShouldBeOfType <HelpCommand>(); commandRun.Input.ShouldBeOfType <HelpInput>() .Name.ShouldBe("onlyflags"); }
public void ShouldBeAbleToParseAllNumbersWithQuotes(int argVal, int optVal) { var cmd = $"my \"{argVal}\" --num \"{optVal}\""; var f = new CommandFactory(); f.RegisterCommand <MyCommand>(); var runner = f.BuildRun(cmd); var input = runner.Input.ShouldBeOfType <MyInput>(); input.ArgNum.ShouldBe(argVal); input.NumFlag.ShouldBe(optVal); }
public void fetch_the_dump_usages_command_if_the_command_is_dump_usages() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().Assembly); var run = factory.BuildRun(new string[] { "dump-usages", "ripple", "somewhere.xml" }); run.Command.ShouldBeOfType <DumpUsagesCommand>(); var input = run.Input.ShouldBeOfType <DumpUsagesInput>(); input.Commands.ShouldBeTheSameAs(factory); input.ApplicationName.ShouldEqual("ripple"); input.Location.ShouldEqual("somewhere.xml"); }
public void ShouldBeAbleToParseAllNumbersWithQuotes(int argVal, int optVal) { var cmd = $"my \"{argVal}\" --num \"{optVal}\""; var f = new CommandFactory(); f.RegisterCommand <MyCommand>(); var runner = f.BuildRun(cmd); var input = runner.Input as MyInput; Assert.NotNull(input); // If this is null, then things didn't parse properly Assert.Equal(argVal, input.ArgNum); Assert.Equal(optVal, input.NumFlag); }
public void call_through_the_configure_run() { var factory = new CommandFactory(); factory.RegisterCommands(GetType().GetTypeInfo().Assembly); object input = null; object cmd = null; factory.ConfigureRun = r => { cmd = r.Command; input = r.Input; }; var run = factory.BuildRun("my Jeremy --force"); cmd.ShouldBe(run.Command); input.ShouldBe(run.Input); }
private CommandRun forArgs(string args) { return(theFactory.BuildRun(args)); }