예제 #1
0
        private void ValidateSourceFilename(ParsedArguments parsedArguments)
        {
            if (parsedArguments.SourceFilename is null)
            {
                parsedArguments.SourceFilename = GetSourceFilenameFromInput();
            }

            if (!File.Exists(parsedArguments.SourceFilename))
            {
                throw new InvalidArgumentsException($"The file {parsedArguments.SourceFilename} could not be found");
            }
        }
예제 #2
0
        public ArgumentParser(string[] args)
        {
            RawArgs         = args;
            ParsedArguments = new ParsedArguments();

            parser = new OptionSet()
            {
                {
                    "p|pgnfile=",
                    "the filename of the {PGNFILE} to load.",
                    filename => ParsedArguments.SourceFilename = filename
                },
                {
                    "o|output=",
                    "the filename of the {OUTPUT} file.",
                    filename => ParsedArguments.NewFilename = filename
                }
            };
        }
예제 #3
0
        private void ValidateOutputFilename(ParsedArguments parsedArguments)
        {
            if (parsedArguments.NewFilename is null)
            {
                parsedArguments.NewFilename = GetDefaultFenFileName(parsedArguments.SourceFilename);
            }

            if (parsedArguments.SourceFilename == parsedArguments.NewFilename)
            {
                throw new InvalidArgumentsException("Input PGN file and output file have the same name");
            }

            if (File.Exists(parsedArguments.NewFilename))
            {
                if (ShouldOverwriteNewFile(parsedArguments.NewFilename))
                {
                    File.Delete(parsedArguments.NewFilename);
                }
                else
                {
                    throw new InvalidArgumentsException($"{parsedArguments.NewFilename} already exists");
                }
            }
        }
예제 #4
0
 public void PrepareFiles(ParsedArguments parsedArguments)
 {
     ValidateSourceFilename(parsedArguments);
     ValidateOutputFilename(parsedArguments);
 }