Exemplo n.º 1
0
    public void RemoveCommand([Option(0, "テンプレート名")] string templateName)
    {
        var templateConfig = new TemplateConfig();

        if (!templateConfig.IsInstalled(templateName))
        {
            Console.Error.WriteLine($"WA! {templateName} がテンプレート名に存在しません。");
            Console.Error.WriteLine($"    テンプレート一覧を確認してください。");

            Console.WriteLine($"テンプレート名 : テンプレートへのパス");
            foreach (var template in templateConfig.ListTemplate())
            {
                Console.WriteLine($"{template.name} : {template.path}");
            }
            return;
        }

        templateConfig.Remove(templateName);
        templateConfig.Write();
        Console.WriteLine($"AC! テンプレート名 {templateName} を登録解除しました。");
    }
Exemplo n.º 2
0
    public void InstallCommand(
        [Option(0, "テンプレート名")] string templateName,
        [Option(1, "テンプレートへのパス")] string templatePath,
        [Option("u", "テンプレートを上書き登録する")] bool update = false
        )
    {
        var templateConfig    = new TemplateConfig();
        var invalidPathString = new string(Path.GetInvalidPathChars());

        if (invalidPathString.Any(invalidChar => templatePath.Contains(invalidChar)))
        {
            Console.Error.WriteLine($"WA! 以下の文字は、テンプレートへのパスに含むことができません。");
            Console.Error.WriteLine($"    {String.Join(" ", invalidPathString)}");
            return;
        }

        if (!Directory.Exists(templatePath))
        {
            Console.Error.WriteLine($"WA! {templatePath} は存在しません。");
            Console.Error.WriteLine($"    存在するテンプレートへのパスを指定してください。");
            return;
        }

        var installTemplate = new Template {
            name = templateName, path = Path.GetFullPath(templatePath)
        };

        if (update)
        {
            if (!templateConfig.IsInstalled(installTemplate.name))
            {
                Console.Error.WriteLine($"WA! テンプレート名 {installTemplate.name} は登録されていません。");
                Console.Error.WriteLine($"    テンプレート一覧を確認してください。");
                Console.WriteLine($"テンプレート名 : テンプレートへのパス");
                foreach (var template in templateConfig.ListTemplate())
                {
                    Console.WriteLine($"{template.name} : {template.path}");
                }
            }
            else
            {
                templateConfig.Update(installTemplate);
                templateConfig.Write();
                Console.WriteLine($"AC! テンプレート名 {installTemplate.name} に、{installTemplate.path} を上書き登録しました。");
            }
        }
        else
        {
            if (templateConfig.IsInstalled(installTemplate.name))
            {
                Console.Error.WriteLine($"WA! テンプレート名 {installTemplate.name} には、テンプレートへのパス {templateConfig.Get(installTemplate.name).path} が既に登録されています。");
                Console.Error.WriteLine($"    -update オプションで、テンプレートの上書き登録を行うことができます。");
            }
            else
            {
                templateConfig.Add(installTemplate);
                templateConfig.Write();
                Console.WriteLine($"AC! テンプレート名 {installTemplate.name} に、{installTemplate.path} を登録しました。");
            }
        }
    }