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); }); }); }
private static void RegisterInstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory, IApplicationEnvironment appEnvironment) { commandsCmd.Command("install", c => { c.Description = "Installs application commands"; var argPackage = c.Argument("[package]", "The name of the application package"); var argVersion = c.Argument("[version]", "The version of the application package"); var optOverwrite = c.Option("-o|--overwrite", "Overwrites package and conflicting commands", CommandOptionType.NoValue); var feedCommandLineOptions = FeedCommandLineOptions.Add(c); c.HelpOption("-?|-h|--help"); c.OnExecute(async() => { c.ShowRootCommandFullNameAndVersion(); var feedOptions = feedCommandLineOptions.GetOptions(); var command = new InstallGlobalCommand( appEnvironment, string.IsNullOrEmpty(feedOptions.TargetPackagesFolder) ? AppCommandsFolderRepository.CreateDefault() : AppCommandsFolderRepository.Create(feedOptions.TargetPackagesFolder)); command.FeedOptions = feedOptions; command.Reports = reportsFactory.CreateReports(feedOptions.Quiet); command.OverwriteCommands = optOverwrite.HasValue(); if (feedOptions.Proxy != null) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } if (argPackage.Value == null) { c.ShowHelp(); return(2); } var success = await command.Execute(argPackage.Value, argVersion.Value); return(success ? 0 : 1); }); }); }
public static void Register(CommandLineApplication cmdApp, ReportsFactory reportsFactory, IApplicationEnvironment applicationEnvironment) { cmdApp.Command("restore", c => { c.Description = "Restore packages"; var argRoot = c.Argument("[root]", "List of projects and project folders to restore. Each value can be: a path to a project.json or global.json file, or a folder to recursively search for project.json files.", multipleValues: true); var feedCommandLineOptions = FeedCommandLineOptions.Add(c); var optLock = c.Option("--lock", "Creates dependencies file with locked property set to true. Overwrites file if it exists.", CommandOptionType.NoValue); var optUnlock = c.Option("--unlock", "Creates dependencies file with locked property set to false. Overwrites file if it exists.", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(async() => { c.ShowRootCommandFullNameAndVersion(); var feedOptions = feedCommandLineOptions.GetOptions(); var command = new RestoreCommand(applicationEnvironment); command.Reports = reportsFactory.CreateReports(feedOptions.Quiet); command.RestoreDirectories.AddRange(argRoot.Values); command.FeedOptions = feedOptions; command.Lock = optLock.HasValue(); command.Unlock = optUnlock.HasValue(); if (!string.IsNullOrEmpty(feedOptions.Proxy)) { Environment.SetEnvironmentVariable("http_proxy", feedOptions.Proxy); } var success = await command.Execute(); return(success ? 0 : 1); }); }); }