Exemple #1
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 = Settings.LoadDefaultSettings(root: null, configFileName: null, machineWideSettings: null);
                    // 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);
                });
            });
        }
Exemple #2
0
 public GeneralOptionControl()
 {
     InitializeComponent();
     _settings            = ServiceLocator.GetInstance <Configuration.ISettings>();
     _outputConsoleLogger = ServiceLocator.GetInstance <INuGetUILogger>();
     _localsCommandRunner = new LocalsCommandRunner();
     AutoScroll           = true;
     Debug.Assert(_settings != null);
 }
        public GeneralOptionControl()
        {
            InitializeComponent();
            var componentModel = NuGetUIThreadHelper.JoinableTaskFactory.Run(ServiceLocator.GetComponentModelAsync);

            _settings            = componentModel.GetService <ISettings>();
            _outputConsoleLogger = componentModel.GetService <INuGetUILogger>();
            _localsCommandRunner = new LocalsCommandRunner();
            AutoScroll           = true;
            Debug.Assert(_settings != null);
        }
Exemple #4
0
        public GeneralOptionControl(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            InitializeComponent();
            _settings            = ServiceLocator.GetInstance <Configuration.ISettings>();
            _serviceprovider     = serviceProvider;
            _outputConsoleLogger = ServiceLocator.GetInstance <INuGetUILogger>();
            _localsCommandRunner = new LocalsCommandRunner();
            Debug.Assert(_settings != null);
        }