text fixes, remove file existence validations from parse
This commit is contained in:
parent
9318e8f10d
commit
9c2e8f0037
4 changed files with 4 additions and 40 deletions
|
@ -64,41 +64,5 @@ namespace Microsoft.DotNet.Cli
|
||||||
|
|
||||||
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
public static ArgumentsRule DefaultToCurrentDirectory(this ArgumentsRule rule) =>
|
||||||
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
rule.With(defaultValue: () => PathUtility.EnsureTrailingSlash(Directory.GetCurrentDirectory()));
|
||||||
|
|
||||||
public static ArgumentsRule ExistingFilesOnly(
|
|
||||||
this ArgumentsRule rule) =>
|
|
||||||
rule.And(new ArgumentsRule(o =>
|
|
||||||
{
|
|
||||||
foreach (var filePath in o.Arguments)
|
|
||||||
{
|
|
||||||
if (!File.Exists(filePath) &&
|
|
||||||
!Directory.Exists(filePath))
|
|
||||||
{
|
|
||||||
return $"File not found: {filePath}";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
|
|
||||||
public static ArgumentsRule ExistingSlnFileOrDirectoryOnly(
|
|
||||||
this ArgumentsRule rule) =>
|
|
||||||
rule
|
|
||||||
.ExistingFilesOnly()
|
|
||||||
.And(new ArgumentsRule(o =>
|
|
||||||
{
|
|
||||||
foreach (var path in o.Arguments)
|
|
||||||
{
|
|
||||||
if (path.HasExtension(".sln") ||
|
|
||||||
path.IsDirectory())
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $"Specified path '{path}' is not a directory or solution file.";
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -19,7 +19,6 @@ namespace Microsoft.DotNet.Cli
|
||||||
"add",
|
"add",
|
||||||
".NET Add Command",
|
".NET Add Command",
|
||||||
Accept.ExactlyOneArgument()
|
Accept.ExactlyOneArgument()
|
||||||
.ExistingFilesOnly()
|
|
||||||
.DefaultToCurrentDirectory()
|
.DefaultToCurrentDirectory()
|
||||||
.With(name: "PROJECT",
|
.With(name: "PROJECT",
|
||||||
description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."),
|
description: "The project file to operate on. If a file is not specified, the command will search the current directory for one."),
|
||||||
|
|
|
@ -112,8 +112,8 @@ Options:
|
||||||
.WithProject("one two three")
|
.WithProject("one two three")
|
||||||
.Execute("proj.csproj");
|
.Execute("proj.csproj");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Be("Unrecognized command or argument 'two'");
|
cmd.StdErr.Should().BeVisuallyEquivalentTo(
|
||||||
cmd.StdOut.Should().Be("Specify --help for a list of available options and commands.");
|
"Unrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
|
@ -57,7 +57,8 @@ Options:
|
||||||
.WithProject("one two three")
|
.WithProject("one two three")
|
||||||
.Execute("proj.csproj");
|
.Execute("proj.csproj");
|
||||||
cmd.ExitCode.Should().NotBe(0);
|
cmd.ExitCode.Should().NotBe(0);
|
||||||
cmd.StdErr.Should().Be("Unrecognized command or argument 'two'");
|
cmd.StdErr.Should().BeVisuallyEquivalentTo(
|
||||||
|
"Unrecognized command or argument 'one'\r\nUnrecognized command or argument 'two'\r\nUnrecognized command or argument 'three'");
|
||||||
}
|
}
|
||||||
|
|
||||||
[Theory]
|
[Theory]
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue