public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment) { cmdApp.Command("install", c => { c.Description = "Install the given dependency"; var argName = c.Argument("[name]", "Name of the dependency to add"); var argVersion = c.Argument("[version]", "Version of the dependency to add, default is the latest version."); var argProject = c.Argument("[project]", "Path to project, default is current directory"); var feedCommandLineOptions = FeedCommandLineOptions.Add(c); c.HelpOption("-?|-h|--help"); c.OnExecute(async () => { c.ShowRootCommandFullNameAndVersion(); var feedOptions = feedCommandLineOptions.GetOptions(); var reports = reportsFactory.CreateReports(feedOptions.Quiet); var addCmd = new AddCommand(); addCmd.Reports = reports; addCmd.Name = argName.Value; addCmd.Version = argVersion.Value; addCmd.ProjectDir = argProject.Value; var restoreCmd = new RestoreCommand(appEnvironment); restoreCmd.Reports = reports; restoreCmd.FeedOptions = feedOptions; restoreCmd.RestoreDirectories.Add(argProject.Value); if (!string.IsNullOrEmpty(feedOptions.Proxy)) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } var installCmd = new InstallCommand(addCmd, restoreCmd); installCmd.Reports = reports; var success = await installCmd.ExecuteCommand(); return success ? 0 : 1; }); }); }
public InstallCommand(AddCommand addCmd, RestoreCommand restoreCmd) { _addCommand = addCmd; _restoreCommand = restoreCmd; }