Пример #1
0
        private int HandleCommand(string alias)
        {
            if (string.IsNullOrWhiteSpace(alias))
            {
                PrintMessage("Cannot specific alias name.", ConsoleColor.Red);
                return(-1);
            }

            CopyBaseSettings.LoadFromFile();
            CopyBasePathItem setting = CopyBaseSettings.Items.Find(item => item.Alias == alias);

            if (setting == null)
            {
                PrintMessage("No alias matched", ConsoleColor.Red);
                return(-1);
            }
            PrintMessage(setting.ToString(), ConsoleColor.Yellow);

            bool choose = UserChoiceProcess("Are you sure you want to copy the base code?");

            if (choose)
            {
                File.Copy(setting.Element.BaseFilePath, setting.Element.TargetFilePath, overwrite: true);
                PrintMessage("Copy complete.");
            }
            else
            {
                PrintMessage("Copy canceled.");
            }

            return(0);
        }
Пример #2
0
        private int HandleSetupCommand(string alias, string baseFilePath, string targetFilePath)
        {
            if (string.IsNullOrWhiteSpace(alias))
            {
                PrintMessage("Cannot specify alias.", ConsoleColor.Red);
                return(-1);
            }
            if (string.IsNullOrWhiteSpace(baseFilePath) || !File.Exists(baseFilePath))
            {
                PrintMessage("The base file doesn't exist.", ConsoleColor.Red);
                return(-1);
            }
            if (string.IsNullOrWhiteSpace(targetFilePath) || !File.Exists(targetFilePath))
            {
                PrintMessage("The target file doesn't exist.", ConsoleColor.Red);
                return(-1);
            }

            CopyBaseSettings.LoadFromFile();
            CopyBasePathItem list = CopyBaseSettings.Items.Find(x => x.Alias == alias);

            if (list != null)
            {
                PrintMessage("An alias with the same name already exists.\n", ConsoleColor.Red);
                PrintMessage(list.ToString(), ConsoleColor.Yellow);
                return(-1);
            }

            CopyBaseSettings.Items.Add(new CopyBasePathItem()
            {
                Alias   = alias,
                Element = new CopyBasePathItem.FilePathElement()
                {
                    BaseFilePath   = baseFilePath,
                    TargetFilePath = targetFilePath
                }
            });
            CopyBaseSettings.SaveToFile();

            PrintMessage("Alias add completed!");

            return(0);
        }