Ejemplo n.º 1
0
        public void Initialize(CLIContext context)
        {
            this.context = context;

            CLIConsole.WriteLine($"({GetType().Name})Loading setting file...");
            var filePath = Path.Combine(this.context.DataDirectoryFullPath, settingFileName);

            if (!File.Exists(filePath))
            {
                File.Create(filePath).Close();
                saveSetting(context);
            }
            setting = loadSetting(filePath);
        }
Ejemplo n.º 2
0
        public string Show(string message)
        {
            CLIConsole.WriteLine(message, PromptConfig.PromptColor);
            while (true)
            {
                CLIConsole.Write(">");
                var input = Console.ReadLine();
                if (input.Length > 0)
                {
                    return(input);
                }

                CLIConsole.WriteLine("type any word.", PromptConfig.PromptColor);
            }
        }
Ejemplo n.º 3
0
        private void InitializeCommands(IEnumerable <ICLICommand> commands)
        {
            var targets = commands.OfType <ICLICommandWithInitialize>().ToArray();

            if (targets.Any())
            {
                CLIConsole.WriteLine("Initialize...");
                foreach (var command in targets)
                {
                    command.Initialize(context);
                }
                CLIConsole.WriteLine("End Initialize...");
                CLIConsole.WriteLine();
            }
        }
Ejemplo n.º 4
0
 public (bool, string) ShowQuitable(string message)
 {
     CLIConsole.WriteLine(message, ConsoleColor.Magenta);
     while (true)
     {
         CLIConsole.Write(">");
         var rawInput = Console.ReadLine();
         var input    = rawInput.ToLower().Trim();
         if (input.Length > 0)
         {
             var isQuit = input == "q" || input == "quit";
             return(isQuit, rawInput);
         }
         CLIConsole.WriteLine("type any word.", PromptConfig.PromptColor);
     }
 }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            CLIConsole.WriteLine("Welcome to ClArc");
            CLIConsole.WriteLine();
            var commands = new CLICommandsContainer
            {
                { new CLICommandConfig("GenerateDefaultWebProject"), new CreateDefaultWebProjectCommand() },
                { new CLICommandConfig("UseCase"), new CreateUseCaseCommand() },
            };
            var context = new CLIContext(Environment.CurrentDirectory);

            using (var driver = new Driver(commands, context))
            {
                driver.Run();
            }
        }
        public void Run()
        {
            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("Create default web project");
            CLIConsole.WriteSeparator();


            string directory;

            while (true)
            {
                var(isQuit, input) = Prompt.ShowQuitable("directory:");
                if (isQuit)
                {
                    CLIConsole.WriteLine("aborted", ConsoleColor.Red);
                    return;
                }

                if (Directory.Exists(input))
                {
                    directory = input;
                    break;
                }

                CLIConsole.WriteLine("directory not found.");
            }

            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("The following WebProject will be created:");
            CLIConsole.WriteSeparator();
            CLIConsole.WriteLine("directory:");
            CLIConsole.WriteLine("- " + directory);

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

            if (yesno == YesNoPrompt.Result.Yes)
            {
                createWebProject(directory);
                CLIConsole.WriteLine("done.");
            }
            else
            {
                CLIConsole.WriteLine("end.");
            }
            CLIConsole.WriteLine();
        }
Ejemplo n.º 7
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();
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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();
            }
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
0
 private void showAbort()
 {
     CLIConsole.WriteLine("aborted", ConsoleColor.Red);
 }