예제 #1
0
        private void ListCommands()
        {
            var types = CommandLoader.LoadTypes().OrderBy(t => t.GetCustomAttribute <CommandLineCommandAttribute>().Command);

            this.IO.Writer.WriteLine();
            this.IO.Writer.WriteLine("   {0}", SR.Resource("CommandLine_Commands"));
            this.IO.Writer.WriteLine();

            var max = types.Max(t => t.GetCustomAttribute <CommandLineCommandAttribute>().Command.Length) + 10;

            foreach (var type in types)
            {
                var attr = type.GetCustomAttribute <CommandLineCommandAttribute>();

                this.IO.Writer.Write(attr.Command.PadLeft(attr.Command.Length + 3).PadRight(max));

                var descName = "CommandLine_" + attr.Description;
                var desc     = SR.Resource(descName);

                if (string.Equals(descName, desc, StringComparison.OrdinalIgnoreCase))
                {
                    this.IO.Writer.WriteLine(attr.Description);
                }
                else
                {
                    this.IO.Writer.WriteLine(desc);
                }
            }

            this.IO.Writer.WriteLine();
        }
예제 #2
0
        public override Task <bool> Execute()
        {
            var comm = CommandLoader.CreateCommandExecutor(this.Command, this.Parameters.WithCommand(this.Command), ((ICommand)this).IO);

            if (comm == null)
            {
                if (!string.IsNullOrWhiteSpace(this.Command))
                {
                    this.WriteLine();
                    this.WriteLine(SR.Resource("CommandLine_UnknownCommand", this.Command));
                }

                this.DisplayUserDefaults();

                this.ListCommands();
            }
            else
            {
                this.WriteLine();

                this.WriteCommandLabel(comm.GetType());

                this.DisplayUserDefaults();

                comm.DisplayHelp();
            }

            return(Task.FromResult(true));
        }
예제 #3
0
        private void ListCommands()
        {
            var types = CommandLoader.LoadTypes().OrderBy(t => t.GetCustomAttribute <CommandLineCommandAttribute>().Command);

            this.WriteLine();
            this.WriteHeader(SR.Resource("CommandLine_Commands"));
            this.WriteLine();

            var max = types.Max(t => t.GetCustomAttribute <CommandLineCommandAttribute>().Command.Split('|').OrderByDescending(s => s.Length).First().Length) + 10;

            foreach (var type in types)
            {
                this.WriteCommandLabel(type, max);
            }
        }
예제 #4
0
        public override Task <bool> Execute()
        {
            var comm = CommandLoader.CreateCommandExecutor(this.Command, null, this.IO);

            if (comm == null)
            {
                if (!string.IsNullOrWhiteSpace(this.Command))
                {
                    this.IO.Writer.WriteLine();
                    this.IO.Writer.WriteLine(SR.Resource("CommandLine_UnknownCommand", this.Command));
                }

                this.DisplayUserDefaults();

                this.ListCommands();
            }
            else
            {
                this.DisplayUserDefaults();
            }

            return(Task.FromResult(true));
        }
예제 #5
0
        public ICommand CreateCommandExecutor(InputControl io)
        {
            string commandValue = this.Command;

            return(CommandLoader.CreateCommandExecutor(commandValue, this, io));
        }