Skip to content

Commit

Permalink
Add ExpectedAsSinglePathToExistingDirectoryOrFile
Browse files Browse the repository at this point in the history
  • Loading branch information
pgolebiowski committed Jul 22, 2023
1 parent 80c2f5e commit b43093a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ public interface IUserInputToCommandOption
/// </summary>
string ExpectedAsSinglePathToExistingDirectory();

/// <summary>
/// Gets the single value of this argument, interpreted as a path to an existing file or directory.
/// This method throws a <see cref="WrongCommandUsageException" /> if the number of values is not equal to 1.
/// It throws a <see cref="MessageOnlyException" /> if no file or directory exists at the specified path.
/// </summary>
string ExpectedAsSinglePathToExistingDirectoryOrFile();

/// <summary>
/// Gets the single value of this argument, interpreted as an integer.
/// This method throws a <see cref="WrongCommandUsageException" /> if the number of values is not equal to 1.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,20 @@ public string ExpectedAsSinglePathToExistingDirectory()
return path;
}

/// <inheritdoc cref="IUserInputToCommandOption.ExpectedAsSinglePathToExistingDirectoryOrFile" />
public string ExpectedAsSinglePathToExistingDirectoryOrFile()
{
string path = this.ExpectedAsSingleValue();

if (!File.Exists(path) && !Directory.Exists(path))
{
ThrowHelper.MessageOnlyException(
$"The file or directory '{path}' does not exist.");
}

return path;
}

/// <inheritdoc cref="IUserInputToCommandOption.ExpectedAsSingleInteger" />
public int ExpectedAsSingleInteger()
{
Expand Down
2 changes: 1 addition & 1 deletion src/TreeBasedCli/TreeBasedCli.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
<id>TreeBasedCli</id>
<version>3.2.5</version>
<version>3.2.6</version>
<authors>Patryk Golebiowski</authors>
<owners>Patryk Golebiowski</owners>

Expand Down

0 comments on commit b43093a

Please sign in to comment.