public static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("delete", delete => { delete.Description = Strings.Delete_Description; delete.HelpOption(XPlatUtility.HelpOption); delete.Option( CommandConstants.ForceEnglishOutputOption, Strings.ForceEnglishOutput_Description, CommandOptionType.NoValue); var source = delete.Option( "-s|--source <source>", Strings.Source_Description, CommandOptionType.SingleValue); var nonInteractive = delete.Option( "--non-interactive", Strings.NonInteractive_Description, CommandOptionType.NoValue); var apikey = delete.Option( "-k|--api-key <apiKey>", Strings.ApiKey_Description, CommandOptionType.SingleValue); var arguments = delete.Argument( "[root]", Strings.Delete_PackageIdAndVersion_Description, multipleValues: true); var noServiceEndpointDescription = delete.Option( "--no-service-endpoint", Strings.NoServiceEndpoint_Description, CommandOptionType.NoValue); var interactive = delete.Option( "--interactive", Strings.NuGetXplatCommand_Interactive, CommandOptionType.NoValue); delete.OnExecute(async() => { if (arguments.Values.Count < 2) { throw new ArgumentException(Strings.Delete_MissingArguments); } string packageId = arguments.Values[0]; string packageVersion = arguments.Values[1]; string sourcePath = source.Value(); string apiKeyValue = apikey.Value(); bool nonInteractiveValue = nonInteractive.HasValue(); bool noServiceEndpoint = noServiceEndpointDescription.HasValue(); DefaultCredentialServiceUtility.SetupDefaultCredentialService(getLogger(), !interactive.HasValue()); #pragma warning disable CS0618 // Type or member is obsolete PackageSourceProvider sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false); #pragma warning restore CS0618 // Type or member is obsolete await DeleteRunner.Run( sourceProvider.Settings, sourceProvider, packageId, packageVersion, sourcePath, apiKeyValue, nonInteractiveValue, noServiceEndpoint, Confirm, getLogger()); return(0); }); }); }
public static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("locals", locals => { locals.Description = Strings.LocalsCommand_Description; locals.HelpOption(XPlatUtility.HelpOption); locals.Option( CommandConstants.ForceEnglishOutputOption, Strings.ForceEnglishOutput_Description, CommandOptionType.NoValue); var clear = locals.Option( "-c|--clear", Strings.LocalsCommand_ClearDescription, CommandOptionType.NoValue); var list = locals.Option( "-l|--list", Strings.LocalsCommand_ListDescription, CommandOptionType.NoValue); var arguments = locals.Argument( "Cache Location(s)", Strings.LocalsCommand_ArgumentDescription, multipleValues: false); locals.OnExecute(() => { var logger = getLogger(); var setting = XPlatUtility.GetSettingsForCurrentWorkingDirectory(); // Using both -clear and -list command options, or neither one of them, is not supported. // We use MinArgs = 0 even though the first argument is required, // to avoid throwing a command argument validation exception and // immediately show usage help for this command instead. if ((arguments.Values.Count < 1) || string.IsNullOrWhiteSpace(arguments.Values[0])) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_NoArguments)); } else if (clear.HasValue() && list.HasValue()) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_MultipleOperations)); } else if (!clear.HasValue() && !list.HasValue()) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Strings.LocalsCommand_NoOperation)); } else { var localsArgs = new LocalsArgs(arguments.Values, setting, logger.LogInformation, logger.LogError, clear.HasValue(), list.HasValue()); var localsCommandRunner = new LocalsCommandRunner(); localsCommandRunner.ExecuteCommand(localsArgs); } return(0); }); }); }
public static void Register(CommandLineApplication app, Func <ILogger> getLogger) { app.Command("push", push => { push.Description = Strings.Push_Description; push.HelpOption(XPlatUtility.HelpOption); push.Option( CommandConstants.ForceEnglishOutputOption, Strings.ForceEnglishOutput_Description, CommandOptionType.NoValue); var source = push.Option( "-s|--source <source>", Strings.Source_Description, CommandOptionType.SingleValue); var symbolSource = push.Option( "-ss|--symbol-source <source>", Strings.SymbolSource_Description, CommandOptionType.SingleValue); var timeout = push.Option( "-t|--timeout <timeout>", Strings.Push_Timeout_Description, CommandOptionType.SingleValue); var apikey = push.Option( "-k|--api-key <apiKey>", Strings.ApiKey_Description, CommandOptionType.SingleValue); var symbolApiKey = push.Option( "-sk|--symbol-api-key <apiKey>", Strings.SymbolApiKey_Description, CommandOptionType.SingleValue); var disableBuffering = push.Option( "-d|--disable-buffering", Strings.DisableBuffering_Description, CommandOptionType.NoValue); var noSymbols = push.Option( "-n|--no-symbols", Strings.NoSymbols_Description, CommandOptionType.NoValue); var arguments = push.Argument( "[root]", Strings.Push_Package_ApiKey_Description, multipleValues: true); var noServiceEndpointDescription = push.Option( "--no-service-endpoint", Strings.NoServiceEndpoint_Description, CommandOptionType.NoValue); var interactive = push.Option( "--interactive", Strings.NuGetXplatCommand_Interactive, CommandOptionType.NoValue); var skipDuplicate = push.Option( "--skip-duplicate", Strings.PushCommandSkipDuplicateDescription, CommandOptionType.NoValue); push.OnExecute(async() => { if (arguments.Values.Count < 1) { throw new ArgumentException(Strings.Push_MissingArguments); } IList <string> packagePaths = arguments.Values; string sourcePath = source.Value(); string apiKeyValue = apikey.Value(); string symbolSourcePath = symbolSource.Value(); string symbolApiKeyValue = symbolApiKey.Value(); bool disableBufferingValue = disableBuffering.HasValue(); bool noSymbolsValue = noSymbols.HasValue(); bool noServiceEndpoint = noServiceEndpointDescription.HasValue(); bool skipDuplicateValue = skipDuplicate.HasValue(); int timeoutSeconds = 0; if (timeout.HasValue() && !int.TryParse(timeout.Value(), out timeoutSeconds)) { throw new ArgumentException(Strings.Push_InvalidTimeout); } #pragma warning disable CS0618 // Type or member is obsolete var sourceProvider = new PackageSourceProvider(XPlatUtility.GetSettingsForCurrentWorkingDirectory(), enablePackageSourcesChangedEvent: false); #pragma warning restore CS0618 // Type or member is obsolete try { DefaultCredentialServiceUtility.SetupDefaultCredentialService(getLogger(), !interactive.HasValue()); await PushRunner.Run( sourceProvider.Settings, sourceProvider, packagePaths, sourcePath, apiKeyValue, symbolSourcePath, symbolApiKeyValue, timeoutSeconds, disableBufferingValue, noSymbolsValue, noServiceEndpoint, skipDuplicateValue, getLogger()); } catch (TaskCanceledException ex) { throw new AggregateException(ex, new Exception(Strings.Push_Timeout_Error)); } return(0); }); }); }