Exemplo n.º 1
0
    public void CreateCommand([Option(0, "利用するテンプレート名")] string templateName, [Option(1, "作成するコンテスト名")] string contestName)
    {
        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;
        }

        var invalidFileNameString = new string(Path.GetInvalidFileNameChars());

        if (invalidFileNameString.Any(invalidChar => contestName.Contains(invalidChar)))
        {
            Console.Error.WriteLine($"WA! 以下の文字は、コンテスト名に含むことができません。");
            Console.Error.WriteLine($"    {String.Join(" ", invalidFileNameString)}");
            return;
        }
        if (Directory.Exists(contestName) || File.Exists(contestName))
        {
            Console.Error.WriteLine($"WA! {contestName} はすでに存在しています。別のコンテスト名を使用してください。");
            return;
        }

        if (!templateConfig.IsInstalled(templateName))
        {
            var template = templateConfig.Get(templateName);
            Console.Error.WriteLine($"CE! テンプレート名 {template.name} のパス {template.path} に、テンプレートが存在しません。");
            Console.Error.WriteLine($"    install コマンドと -update オプションで、修正したテンプレートへのパスを上書き登録してください。");
            return;
        }

        Console.WriteLine("WJ... コンテスト名のディレクトリを作成します。");

        Directory.CreateDirectory(contestName);
        foreach (var problemName in new List <string> {
            "A", "B", "C", "D", "E", "F"
        })
        {
            Console.WriteLine($"WJ... {problemName} ディレクトリを作成します。");
            var template    = templateConfig.Get(templateName);
            var problemPath = Path.Combine(contestName, problemName);
            DirectoryEx.Copy(template.path, problemPath);
        }

        Console.WriteLine("AC! コンテスト用の各問題の作成が完了しました。");
    }
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} を登録しました。");
            }
        }
    }