Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
detect non-existing references and tiny refactor of tests
Browse files Browse the repository at this point in the history
  • Loading branch information
krwq committed Nov 22, 2016
1 parent fc983d7 commit 80d4dae
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 146 deletions.
39 changes: 35 additions & 4 deletions src/dotnet/commands/dotnet-add-p2p/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,21 @@ public static int Run(string[] args)

app.HelpOption("-h|--help");

CommandArgument projectArgument = app.Argument("<PROJECT>",
CommandArgument projectArgument = app.Argument(
"<PROJECT>",
"The project file to modify. If a project file is not specified," +
" it searches the current working directory for an MSBuild file that has a file extension that ends in `proj` and uses that file.");
" it searches the current working directory for an MSBuild file that has" +
" a file extension that ends in `proj` and uses that file.");

CommandOption frameworkOption = app.Option("-f|--framework <FRAMEWORK>", "Add reference only when targetting a specific framework", CommandOptionType.SingleValue);
CommandOption frameworkOption = app.Option(
"-f|--framework <FRAMEWORK>",
"Add reference only when targetting a specific framework",
CommandOptionType.SingleValue);

CommandOption forceOption = app.Option(
"--force",
"Add reference even if it does not exist",
CommandOptionType.NoValue);

app.OnExecute(() => {
if (projectArgument.Value == null)
Expand All @@ -50,10 +60,31 @@ public static int Run(string[] args)
throw new GracefulException("You must specify at least one reference to add.");
}

List<string> references = app.RemainingArguments;
if (!forceOption.HasValue())
{
var notExisting = new List<string>();
foreach (var r in references)
{
if (!File.Exists(r))
{
notExisting.Add(r);
}
}

if (notExisting.Count > 0)
{
throw new GracefulException(
string.Join(
Environment.NewLine,
notExisting.Select((ne) => $"Reference `{ne}` does not exist.")));
}
}

int numberOfAddedReferences = AddProjectToProjectReference(
project,
frameworkOption.Value(),
app.RemainingArguments);
references);

if (numberOfAddedReferences != 0)
{
Expand Down
Loading

0 comments on commit 80d4dae

Please sign in to comment.