private static void RegisterUninstallSubcommand(CommandLineApplication commandsCmd, ReportsFactory reportsFactory) { commandsCmd.Command("uninstall", c => { c.Description = "Uninstalls application commands"; var argCommand = c.Argument("[command]", "The name of the command to uninstall"); var optNoPurge = c.Option("--no-purge", "Do not try to remove orphaned packages", CommandOptionType.NoValue); c.HelpOption("-?|-h|--help"); c.OnExecute(() => { c.ShowRootCommandFullNameAndVersion(); var command = new UninstallCommand( AppCommandsFolderRepository.CreateDefault(), reports: reportsFactory.CreateReports(quiet: false)); command.NoPurge = optNoPurge.HasValue(); var success = command.Execute(argCommand.Value); 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 AppCommandsFolderRepository Create(string installPath) { var binFolder = installPath; var installPackagesFolder = Path.Combine(binFolder, InstallGlobalCommand.TargetPackagesFolderName); var installGlobalJsonPath = Path.Combine(installPackagesFolder, "global.json"); if (!File.Exists(installGlobalJsonPath)) { Directory.CreateDirectory(installPackagesFolder); File.WriteAllText(installGlobalJsonPath, @"{""packages"":"".""}"); } var repo = new AppCommandsFolderRepository(binFolder); repo.Load(); return(repo); }
public static AppCommandsFolderRepository Create(string installPath) { var binFolder = installPath; var installPackagesFolder = Path.Combine(binFolder, InstallGlobalCommand.TargetPackagesFolderName); var installGlobalJsonPath = Path.Combine(installPackagesFolder, "global.json"); if (!File.Exists(installGlobalJsonPath)) { Directory.CreateDirectory(installPackagesFolder); File.WriteAllText(installGlobalJsonPath, @"{""packages"":"".""}"); } var repo = new AppCommandsFolderRepository(binFolder); repo.Load(); return repo; }