public virtual ExitCode Execute(ITaskInteraction interaction) { interaction.Loggers[LoggerType.Result].WriteLine(WriteStyle.Fixed, this.generalHelp); interaction.Loggers[LoggerType.Result].WriteLine(); Table table = Table.Create(1, 1, 2); table.AddRow(XTaskStrings.OverviewColumn1, XTaskStrings.OverviewColumn2, XTaskStrings.OverviewColumn3); foreach (var entry in registry.Tasks) { if (entry.Task.GetAttributes<HiddenAttribute>(inherit: true).Any()) continue; string[] aliases = entry.Aliases.ToArray(); if (aliases.Length == 0) continue; ITaskDocumentation docs = entry.Task as ITaskDocumentation; table.AddRow( aliases[0], aliases.Length == 1 ? String.Empty : String.Join(", ", aliases.Skip(1)), docs == null || docs.Summary == null ? String.Empty : docs.Summary); } interaction.Loggers[LoggerType.Result].Write(table); return ExitCode.Success; }
public void GetUsage(ITaskInteraction interaction) { // Guidance for argument syntax: // IEEE Std 1003.1 http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap12.html ILogger logger = interaction.Loggers[LoggerType.Result]; if (string.IsNullOrEmpty(this.GeneralHelp)) { logger.Write(XTaskStrings.HelpNone); return; } logger.WriteLine(WriteStyle.Fixed, this.GeneralHelp); string optionDetails = this.OptionDetails; if (string.IsNullOrEmpty(optionDetails)) { return; } logger.WriteLine(); logger.WriteLine(WriteStyle.Fixed | WriteStyle.Underline, XTaskStrings.HelpOptionDetailHeader); logger.WriteLine(); logger.WriteLine(WriteStyle.Fixed, optionDetails); }
public virtual ExitCode Execute(ITaskInteraction interaction) { interaction.Loggers[LoggerType.Result].WriteLine(WriteStyle.Fixed, this.generalHelp); interaction.Loggers[LoggerType.Result].WriteLine(); Table table = Table.Create(1, 1, 2); table.AddRow(XTaskStrings.OverviewColumn1, XTaskStrings.OverviewColumn2, XTaskStrings.OverviewColumn3); foreach (var entry in registry.Tasks) { if (entry.Task.GetAttributes <HiddenAttribute>(inherit: true).Any()) { continue; } string[] aliases = entry.Aliases.ToArray(); if (aliases.Length == 0) { continue; } ITaskDocumentation docs = entry.Task as ITaskDocumentation; table.AddRow( aliases[0], aliases.Length == 1 ? String.Empty : String.Join(", ", aliases.Skip(1)), docs == null || docs.Summary == null ? String.Empty : docs.Summary); } interaction.Loggers[LoggerType.Result].Write(table); return(ExitCode.Success); }
public void HandlesNullHelp() { TestTask testTask = Substitute.ForPartsOf <TestTask>(); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); testTask.OutputUsage(interaction); testTask.Received(1).TestGetGeneralHelp(); }
public void OutputOutputs() { TestTask testTask = Substitute.ForPartsOf <TestTask>(); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); testTask.Execute(interaction); interaction.Received(1).Output("TestOutput"); }
public void HandlesNullOptionDetails() { TestTask testTask = Substitute.ForPartsOf <TestTask>(); testTask.TestGetGeneralHelp().Returns("GeneralHelp"); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); testTask.OutputUsage(interaction); testTask.Received(2).TestGetGeneralHelp(); testTask.Received(1).TestGetOptionDetails(); }
public ExitCode Execute(ITaskInteraction interaction) { _usageTracker.RecordUsage(TaskFeatureIdentifier); ITaskExecutor executor = _task.GetService <ITaskExecutor>(); if (executor != null) { return(executor.Execute(interaction)); } return(ExitCode.Success); }
/// <summary> /// Executes the given task /// </summary> public static ExitCode Execute(this ITask task, ITaskInteraction interaction) { ITaskExecutor executor = task.GetService <ITaskExecutor>(); if (executor != null) { return(executor.Execute(interaction)); } else { return(ExitCode.Success); } }
/// <summary> /// Outputs usage if any help is provided /// </summary> public static void OutputUsage(this ITask task, ITaskInteraction interaction) { ITaskDocumentation documentation = task.GetService <ITaskDocumentation>(); if (documentation == null) { interaction.Loggers[LoggerType.Result].WriteLine(WriteStyle.Fixed, XTaskStrings.HelpNone); } else { documentation.GetUsage(interaction); } }
public override ExitCode Execute(ITaskInteraction interaction) { if (string.IsNullOrEmpty(interaction.Arguments.Command)) { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.ErrorNoParametersSpecified); } else { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.UnknownCommand, interaction.Arguments.Command); } base.Execute(interaction); return(ExitCode.InvalidArgument); }
public override ExitCode Execute(ITaskInteraction interaction) { if (string.IsNullOrEmpty(interaction.Arguments.Command)) { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.ErrorNoParametersSpecified); } else { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.UnknownCommand, interaction.Arguments.Command); } base.Execute(interaction); return ExitCode.InvalidArgument; }
public void NoParameters() { ITaskRegistry registry = Substitute.For <ITaskRegistry>(); UnknownTask task = new UnknownTask(registry, "GeneralHelp"); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); ILoggers loggers = Substitute.For <ILoggers>(); interaction.Loggers.Returns(loggers); ILogger logger = Substitute.For <ILogger>(); loggers[LoggerType.Status].Returns(logger); task.Execute(interaction).Should().Be(ExitCode.InvalidArgument); logger.Received().WriteLine(WriteStyle.Error, XTaskStrings.ErrorNoParametersSpecified); }
public void UnknownTaskLogsHelp() { ITaskRegistry registry = Substitute.For <ITaskRegistry>(); UnknownTask task = new UnknownTask(registry, "GeneralHelp"); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); ILoggers loggers = Substitute.For <ILoggers>(); interaction.Loggers.Returns(loggers); ILogger logger = Substitute.For <ILogger>(); loggers[LoggerType.Result].Returns(logger); task.Execute(interaction).Should().Be(ExitCode.InvalidArgument); logger.Received().WriteLine(WriteStyle.Fixed, "GeneralHelp"); }
public void ListSettings_CountIsCorrect() { // Ensure we output the location table and all settings when listing settings // Set up loggers List <ITable> outputTables = new List <ITable>(); ILogger logger = Substitute.For <ILogger>(); logger.Write(Arg.Do <ITable>(x => outputTables.Add(x))); ILoggers loggers = Substitute.For <ILoggers>(); loggers[Arg.Any <LoggerType>()].Returns(logger); // Set up to list settings ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); interaction.Loggers.Returns(loggers); IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>(); argumentProvider.GetOption <SettingsLocation?>(StandardOptions.List).Returns(new Nullable <SettingsLocation>(SettingsLocation.Local)); interaction.Arguments.Returns(argumentProvider); // Prepare the configuration results ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.Local).Returns("LocalPath"); ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.Roaming).Returns("RoamingPath"); ((IClientSettings)argumentProvider).GetConfigurationPath(SettingsLocation.RunningExecutable).Returns("ExePath"); ClientSetting[] settings = { new ClientSetting("foo", "one", SettingsLocation.Local), new ClientSetting("bar", "two", SettingsLocation.Roaming) }; ((IClientSettings)argumentProvider).GetAllSettings().Returns(settings); DefaultsTask task = new DefaultsTask("Foo"); task.Execute(interaction).Should().Be(ExitCode.Success); outputTables.Count.Should().Be(2, "table for locations and table for settings"); outputTables[0].Rows.Skip(1).ForEachDoOne( row => row.Should().Contain(SettingsLocation.Local.ToString(), "LocalPath"), row => row.Should().Contain(SettingsLocation.Roaming.ToString(), "RoamingPath"), row => row.Should().Contain(SettingsLocation.RunningExecutable.ToString(), "ExePath")); outputTables[1].Rows.Skip(1).ForEachDoOne( row => row.Should().Contain("foo", SettingsLocation.Local.ToString(), "one"), row => row.Should().Contain("bar", SettingsLocation.Roaming.ToString(), "two")); }
public ExitCode Execute(ITaskInteraction interaction) { if (this.unknownCommand) { if (String.IsNullOrEmpty(interaction.Arguments.Command)) { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.ErrorNoParametersSpecified); } else { interaction.Loggers[LoggerType.Status].WriteLine(WriteStyle.Error, XTaskStrings.UnknownCommand, interaction.Arguments.Command); } } interaction.Loggers[LoggerType.Result].WriteLine(WriteStyle.Fixed, this.generalHelp); return this.unknownCommand ? ExitCode.InvalidArgument : ExitCode.Success; }
public void UnkownCommand() { ITaskRegistry registry = Substitute.For <ITaskRegistry>(); UnknownTask task = new UnknownTask(registry, "GeneralHelp"); ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); IArgumentProvider arguments = Substitute.For <IArgumentProvider>(); string commandName = "Foo"; interaction.Arguments.Returns(arguments); interaction.Arguments.Command.Returns(commandName); ILoggers loggers = Substitute.For <ILoggers>(); interaction.Loggers.Returns(loggers); ILogger logger = Substitute.For <ILogger>(); loggers[LoggerType.Status].Returns(logger); task.Execute(interaction).Should().Be(ExitCode.InvalidArgument); logger.Received().WriteLine(WriteStyle.Error, XTaskStrings.UnknownCommand, commandName); }
public void RemoveSetting_Removes() { // Ensure actually add a setting when adding // Set up to add settings ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>(); argumentProvider.GetOption <SettingsLocation?>(StandardOptions.Remove).Returns(new Nullable <SettingsLocation>(SettingsLocation.Roaming)); interaction.Arguments.Returns(argumentProvider); argumentProvider.Options.Returns(new Dictionary <string, string> { { "Boy", "Howdy" } }); DefaultsTask task = new DefaultsTask("Foo"); task.Execute(interaction).Should().Be(ExitCode.Success); ((IClientSettings)argumentProvider).Received(1).RemoveSetting(SettingsLocation.Roaming, "Boy"); }
public ExitCode ExecuteTask() { ITask task = _taskRegistry[ArgumentProvider.Command]; ITaskInteraction interaction = GetInteraction(task); ExitCode result = ExitCode.GeneralFailure; using (interaction as IDisposable) using (task as IDisposable) { if (ArgumentProvider.HelpRequested) { task.OutputUsage(interaction); } else { result = task.Execute(interaction); } } return(result); }
public void AddSetting_SkipOptions() { // Ensure we skip saving options that directly apply to the defaults task // Set up to add settings ITaskInteraction interaction = Substitute.For <ITaskInteraction>(); IArgumentProvider argumentProvider = Substitute.For <IArgumentProvider, IClientSettings>(); argumentProvider.GetOption <SettingsLocation?>(StandardOptions.Add).Returns(new Nullable <SettingsLocation>(SettingsLocation.Local)); interaction.Arguments.Returns(argumentProvider); argumentProvider.Options.Returns(new Dictionary <string, string> { { StandardOptions.List[0], "one" }, { StandardOptions.Add[0], "two" }, { StandardOptions.Remove[0], "three" }, }); DefaultsTask task = new DefaultsTask("Foo"); task.Execute(interaction).Should().Be(ExitCode.Success); ((IClientSettings)argumentProvider).DidNotReceiveWithAnyArgs().SaveSetting(SettingsLocation.Local, "", ""); }
public TestTaskExecution(IArgumentProvider argumentProvider, ITaskRegistry taskRegistry, ITaskInteraction interaction) : base(argumentProvider, taskRegistry, null) { this.interaction = interaction; }
public void GetUsage(ITaskInteraction interaction) { this.Execute(interaction); }
public ExitCode Execute(ITaskInteraction interaction) { _interaction = interaction; return(ExecuteInternal()); }
public ExitCode Execute(ITaskInteraction interaction) { this.interaction = interaction; return(this.ExecuteInternal()); }