Skip to content
This repository has been archived by the owner on Dec 18, 2017. It is now read-only.

Adding dnu clearcache command #2742

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/Microsoft.Dnx.Tooling/ClearCache/ClearCacheCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.IO;

namespace Microsoft.Dnx.Tooling
{
internal class ClearCacheCommand
{
public ClearCacheCommand(Reports reports, string httpCacheDirectory)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix all the formatting please 😄 Empty line above the ctor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

{
Reports = reports;
HttpCacheDirectory = httpCacheDirectory;
}

public Reports Reports { get; }
public string HttpCacheDirectory { get; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need this as a property?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about Reports


public int Execute()
{
if (Directory.Exists(HttpCacheDirectory))
{
Reports.Information.WriteLine($"Clearing cache directory {HttpCacheDirectory}");

try
{
FileOperationUtils.DeleteFolder(HttpCacheDirectory);
Reports.Information.WriteLine("Cache cleared.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we have some extension methods for Reports to write information directly.

}
catch (Exception e)
{
Reports.Error.WriteLine($"Unable to clear cache directory: {e.Message}");
return 1;
}
}

return 0;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using Microsoft.Dnx.Runtime.Common.CommandLine;

namespace Microsoft.Dnx.Tooling
{
internal static class ClearCacheConsoleCommand
{
public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory)
{
cmdApp.Command("clear-http-cache", c =>
{
c.Description = "Clears the package cache.";
c.HelpOption("-?|-h|--help");
c.OnExecute(() =>
{
var command = new ClearCacheCommand(
reportsFactory.CreateReports(quiet: false),
DnuEnvironment.GetFolderPath(DnuFolderPath.HttpCacheDirectory));
return command.Execute();
});
});
}
}
}
1 change: 1 addition & 0 deletions src/Microsoft.Dnx.Tooling/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public int Main(string[] args)
RestoreConsoleCommand.Register(app, reportsFactory, _environment, _runtimeEnv);
WrapConsoleCommand.Register(app, reportsFactory);
FeedsConsoleCommand.Register(app, reportsFactory);
ClearCacheConsoleCommand.Register(app, reportsFactory);

return app.Execute(args);
}
Expand Down