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"); } }
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 } }; }
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"); } } }
public void PrepareFiles(ParsedArguments parsedArguments) { ValidateSourceFilename(parsedArguments); ValidateOutputFilename(parsedArguments); }