void PrintGeneralHelp(string executable)
        {
            Console.ResetColor();
            Console.Write("Usage: ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(executable + " <command> [<options>]");
            Console.ResetColor();
            Console.WriteLine();
            Console.WriteLine("Where <command> is one of: ");
            Console.WriteLine();

            foreach (var possible in commands.List().OrderBy(x => x.Name))
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("  " + possible.Name.PadRight(15, ' '));
                Console.ResetColor();
                Console.WriteLine("   " + possible.Description);
            }

            Console.WriteLine();
            Console.Write("Or use ");
            Console.ForegroundColor = ConsoleColor.White;
            Console.Write(executable + " help <command>");
            Console.ResetColor();
            Console.WriteLine(" for more details.");
        }
 private void RegisterCommandAttributes(ContainerBuilder builder)
 {
     foreach (var commandMetadata in CommandLocator.List(assembly))
     {
         builder.RegisterInstance(commandMetadata).As <ICommandMetadata>();
     }
 }
Exemple #3
0
        IReadOnlyDictionary <string, string[]> GetCompletionMap()
        {
            var commandMetadatas = commands.List();

            return(commandMetadatas.ToDictionary(
                       c => c.Name,
                       c =>
            {
                var subCommand = (CommandBase)commands.Find(c.Name);
                return subCommand.GetOptionNames().ToArray();
            }));
        }
Exemple #4
0
        /// <summary>
        /// Replicate the code that used to be run when executing a command
        /// </summary>
        private void DoOldCalamariExecutionPipeline()
        {
            // We manually replicate the type lookups that used to happen
            var runCommand = (ICommand)Activator.CreateInstance(
                CommandLocator.Find("run-script", typeof(RunScriptCommand).Assembly),
                new CalamariVariableDictionary(),
                new CombinedScriptEngine());
            var helpCommand = (ICommand)Activator.CreateInstance(
                CommandLocator.Find("help", typeof(HelpCommand).Assembly),
                CommandLocator.List(typeof(RunScriptCommand).Assembly),
                runCommand);

            new Calamari.Program(
                helpCommand,
                new HelpCommand(Enumerable.Empty <ICommandMetadata>()));
        }
Exemple #5
0
        public void SetUp()
        {
            originalOutput = Console.Out;
            output         = new StringWriter();
            Console.SetOut(output);

            commandLocator        = Substitute.For <ICommandLocator>();
            logger                = new LoggerConfiguration().WriteTo.TextWriter(output).CreateLogger();
            commandOutputProvider = new CommandOutputProvider(logger);
            commandLocator.List().Returns(new ICommandMetadata[]
            {
                new CommandAttribute("test"),
                new CommandAttribute("help")
            });
            commandLocator.Find("help").Returns(new HelpCommand(commandLocator, commandOutputProvider));
            commandLocator.Find("test").Returns(new TestCommand(commandOutputProvider));
            completeCommand = new CompleteCommand(commandLocator, commandOutputProvider);
        }
Exemple #6
0
    public void SetUp()
    {
        originalOutput = Console.Out;
        output         = new StringWriter();
        Console.SetOut(output);

        commandLocator        = Substitute.For <ICommandLocator>();
        logger                = new LoggerConfiguration().WriteTo.TextWriter(output).CreateLogger();
        commandOutputProvider = new CommandOutputProvider("TestApp", "1.0.0", new DefaultCommandOutputJsonSerializer(), logger);
        commandLocator.List()
        .Returns(new ICommandMetadata[]
        {
            new CommandAttribute("test"),
            new CommandAttribute("help")
        });
        var helpCommand = new HelpCommand(new Lazy <ICommandLocator>(() => commandLocator), commandOutputProvider);
        var testCommand = new TestCommand(commandOutputProvider);

        commandLocator.Find("help").Returns(helpCommand);
        commandLocator.Find("test").Returns(testCommand);
        completeCommand = new CompleteCommand(new Lazy <ICommandLocator>(() => commandLocator), commandOutputProvider);
    }