Esempio n. 1
0
        public void Run()
        {
            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("Create UseCase");
            CLIConsole.WriteSeparator();

            if (!CheckSetting(context))
            {
                showAbort();
                return;
            }

            var controllerName = Prompt.Show("controller name:");
            var actionName     = Prompt.Show("action name:");

            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("The following UseCase will be created:");
            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("directory:");
            CLIConsole.WriteLine("- " + setting.WebProjectDirectoryPath);
            CLIConsole.WriteLine("controller name:");
            CLIConsole.WriteLine("- " + controllerName);
            CLIConsole.WriteLine("action name:");
            CLIConsole.WriteLine("- " + actionName);
            CLIConsole.WriteSeparator();

            var yesno = Prompt.ShowYesNoPrompt("Look okay?");

            if (yesno == YesNoPrompt.Result.No)
            {
                showAbort();
                return;
            }

            var rootFullPath = new Uri(new Uri(setting.WebProjectDirectoryPath), ".").AbsolutePath;
            var param        = new CreateUseCaseTaskParameter(rootFullPath, setting.WebProjectDirectoryPath, controllerName, actionName);
            var task         = new CreateUseCaseTask();

            task.Run(param);

            CLIConsole.WriteLine();
            CLIConsole.WriteLine("CreateUseCase done.");
            CLIConsole.WriteLine();
        }
Esempio n. 2
0
        public Result Show(string message, Result?optResult = Result.Yes)
        {
            string promptText;

            if (optResult.HasValue)
            {
                promptText = optResult.Value == Result.Yes ? "[y] >" : "[n] >";
            }
            else
            {
                promptText = ">";
            }

            CLIConsole.Write(message, PromptConfig.PromptColor);
            CLIConsole.WriteLine("(y/n)");
            CLIConsole.Write(promptText);
            while (true)
            {
                var rawInput = Console.ReadLine();
                var input    = rawInput.ToLower().Trim();
                if (optResult.HasValue && input == "")
                {
                    var result = optResult.Value;
                    return(result);
                }

                switch (input)
                {
                case "y":
                case "yes":
                    return(Result.Yes);

                case "n":
                case "no":
                    return(Result.No);
                }

                CLIConsole.WriteLine("type 'y' or 'n'");
                CLIConsole.Write(promptText);
            }
        }
Esempio n. 3
0
        public void Run()
        {
            var commands      = commandContainer.ToArray();
            var commandOrders = commandContainer.BindToConfig(ToCommandText).ToList();

            commandOrders.Add("[Q]uit");
            var commandTexts = string.Join(System.Environment.NewLine, commandOrders);

            var firstLetters = commandContainer.BindToConfig(x => x.FirstLetter.ToString().ToUpper()).ToList();

            firstLetters.Add("Q");
            var firstLetterForPrompts = string.Join("/", firstLetters);

            InitializeCommands(commands);

            while (true)
            {
                CLIConsole.WriteLine("Available commands:");
                CLIConsole.WriteLine();
                CLIConsole.WriteLine(commandTexts);

                var(isQuit, input) = Prompt.ShowQuitable($"What would you like a command? ({firstLetterForPrompts})");
                if (isQuit)
                {
                    CLIConsole.WriteLine("Quit");
                    return;
                }

                var target = commandContainer.Find(input);
                if (target == null)
                {
                    CLIConsole.WriteLine($"Not matched({input})");
                }
                else
                {
                    target.Run();
                }
                CLIConsole.WriteLine();
            }
        }
Esempio n. 4
0
        private bool CheckSetting(CLIContext context)
        {
            if (setting.IsSetuped)
            {
                if (ValidSolution(setting.SolutionFullPath) && ValidProject(setting.WebProjectDirectoryPath))
                {
                    CLIConsole.WriteLine("Current target solution is " + setting.SolutionFullPath);
                    var result = Prompt.ShowYesNoPrompt("Would you want to change project directory?", YesNoPrompt.Result.No);
                    switch (result)
                    {
                    case YesNoPrompt.Result.Yes:
                        setting.Clear();
                        break;

                    case YesNoPrompt.Result.No:
                        return(true);

                    default:
                        return(false);
                    }
                }
                else
                {
                    setting.Clear();
                }
            }

            if (!setting.IsSetuped)
            {
                while (!setting.IsSetupSolution)
                {
                    var(isQuit, input) = Prompt.ShowQuitable(@"Type your solution by full path.");
                    if (isQuit)
                    {
                        return(false);
                    }

                    if (ValidSolution(input))
                    {
                        CLIConsole.WriteLine("Solution file accepted");
                        setting.SaveSolutionFullPath(input);
                        saveSetting(context);
                    }
                    else
                    {
                        CLIConsole.WriteLine("The file is not solution file.");
                    }
                }

                while (!setting.IsSetupWebProject)
                {
                    var(isQuit, input) = Prompt.ShowQuitable(@"Type your web project directory by full path.");
                    if (isQuit)
                    {
                        return(false);
                    }

                    if (ValidProject(input))
                    {
                        CLIConsole.WriteLine("Project direcotry accepted");
                        setting.SaveWebProjectFullPath(input);
                        saveSetting(context);
                    }
                    else
                    {
                        CLIConsole.WriteLine("The file is not web project directory.");
                    }
                }
            }
            return(true);
        }
Esempio n. 5
0
 private void showAbort()
 {
     CLIConsole.WriteLine("aborted", ConsoleColor.Red);
 }