public void Should_instantiate_correctly_by_specification() { var argument = new PathArgument(@"D:\dev"); Assert.Equal("Path", argument.Name); Assert.Equal(@"D:\dev", argument.GetValue()); Assert.Equal("-p", argument.Argument); Assert.True(argument.Required); }
public void FileInputTest() { string input = Path.GetFullPath("TestFolder/Input/InputFile.png"); string output = Path.GetFullPath("TestFolder/Output"); ArgumentParser parser = new ArgumentParser("-f", input, "-o", output); Assert.True(parser.TryGetArgument("-f", out IArgument inputArg)); Assert.True(parser.TryGetArgument("-o", out IArgument outputArg)); Assert.IsType <PathArgument>(inputArg); Assert.IsType <PathArgument>(outputArg); PathArgument inputPathArg = inputArg as PathArgument; Assert.Equal(inputPathArg.RawValue, input); Assert.Equal(input, Uri.UnescapeDataString(inputPathArg.Value.AbsolutePath).Replace('/', '\\')); PathArgument outputPathArg = outputArg as PathArgument; Assert.Equal(outputPathArg.RawValue, output); Assert.Equal(output, Uri.UnescapeDataString(outputPathArg.Value.AbsolutePath).Replace('/', '\\')); }
public bool Parse(string[] args) { if (args == null || args.Length == 0) { ActionType = ActionType.ShowHelp; return(true); } List <string> extras; try { extras = _options.Parse(args); } catch (Exception ex) { ErrorDetails = ex.Message; return(false); } if (ActionType == ActionType.ShowHelp) { return(true); } // Validation if (PathType == PathType.Unknown) { if (!extras.Any()) { ErrorDetails = "Must specify a directory"; return(false); } PathArgument = extras.First(); extras.RemoveAt(0); PathType = PathType.Directory; } if (ActionType == ActionType.Unknown) { ActionType = ActionType.ShowFull; } if (ShowAllNames && ShowAllStreams) { ErrorDetails = "--allnames and --streams cannot be used together."; return(false); } // Cleaning if (PathType == PathType.Directory) { Console.WriteLine(PathArgument); if ((PathArgument[0] == '"' || PathArgument[0] == '\'') && PathArgument[0] == PathArgument.Last()) { // Strip quotes PathArgument = PathArgument.Substring(1, PathArgument.Length - 2); } // Fixup if (!Path.IsPathRooted(PathArgument)) { PathArgument = Path.Combine(Environment.CurrentDirectory, PathArgument); } } if (!char.IsLetter(Drive)) { Drive = PathArgument[0]; } char[] volumes = Utils.GetAllAvailableVolumes().ToArray(); if (!volumes.Contains(Drive)) { ErrorDetails = "The volume " + Drive + " does not exist."; return(false); } return(true); }
public bool Parse(string[] args) { if (args == null || args.Length == 0) { ActionType = ActionType.ShowHelp; return(true); } try { _options.Parse(args); } catch (Exception ex) { ErrorDetails = ex.Message; return(false); } if (ActionType == ActionType.ShowHelp) { return(true); } // Validation if (PathType == PathType.Unknown) { ErrorDetails = "Must specify either a --file, --dir or an --mftid"; return(false); } if (ActionType == ActionType.Unknown) { ErrorDetails = "Must specify an action, such as --extents, --full or --paths"; return(false); } if (ActionType != ActionType.Unknown && PathType == PathType.Unknown) { ErrorDetails = "Must specify either a --file, --dir or --mftid for --extents, --full or --paths"; return(false); } if (!char.IsLetter(Drive) && PathType == PathType.MftId) { ErrorDetails = "Must specify --volume when using for --mftid"; return(false); } // Cleaning if (PathType == PathType.File || PathType == PathType.Directory) { if ((PathArgument[0] == '"' || PathArgument[0] == '\'') && PathArgument[0] == PathArgument.Last()) { // Strip quotes PathArgument = PathArgument.Substring(1, PathArgument.Length - 2); } // Fixup if (!Path.IsPathRooted(PathArgument)) { PathArgument = Path.Combine(Environment.CurrentDirectory, PathArgument); } } if (!char.IsLetter(Drive)) { Drive = PathArgument[0]; } char[] volumes = Utils.GetAllAvailableVolumes().ToArray(); if (!volumes.Contains(Drive)) { ErrorDetails = "The volume " + Drive + " does not exist."; return(false); } return(true); }