示例#1
0
        public ToolInstallLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault(ToolAppliedOption.ToolManifest);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(appliedCommand, toolPackageInstaller);
        }
示例#2
0
        public ToolUpdateLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId            = new PackageId(appliedCommand.Arguments.Single());
            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault(ToolAppliedOption.ToolManifest);

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(appliedCommand, toolPackageInstaller);
            _toolInstallLocalCommand   = new Lazy <ToolInstallLocalCommand>(
                () => new ToolInstallLocalCommand(
                    appliedCommand,
                    parseResult,
                    _toolPackageInstaller,
                    _toolManifestFinder,
                    _toolManifestEditor,
                    _localToolsResolverCache,
                    _reporter));
        }
        public ToolUninstallLocalCommand(
            ParseResult parseResult,
            IToolManifestFinder toolManifestFinder = null,
            IToolManifestEditor toolManifestEditor = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _packageId            = new PackageId(parseResult.ValueForArgument <string>(ToolUninstallCommandParser.PackageIdArgument));
            _explicitManifestFile = parseResult.ValueForOption <string>(ToolUninstallCommandParser.ToolManifestOption);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor = toolManifestEditor ?? new ToolManifestEditor();
        }
示例#4
0
        public ToolInstallLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            DirectoryPath?nugetGlobalPackagesFolder          = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId            = new PackageId(appliedCommand.Arguments.Single());
            _packageVersion       = appliedCommand.ValueOrDefault <string>("version");
            _configFilePath       = appliedCommand.ValueOrDefault <string>("configfile");
            _sources              = appliedCommand.ValueOrDefault <string[]>("add-source");
            _verbosity            = appliedCommand.SingleArgumentOrDefault("verbosity");
            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault("--tool-manifest");

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _nugetGlobalPackagesFolder =
                nugetGlobalPackagesFolder ?? new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
        }
示例#5
0
        public ToolRestoreCommand(
            AppliedOption appliedCommand,
            ParseResult result,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            DirectoryPath?nugetGlobalPackagesFolder          = null,
            IReporter reporter = null)
            : base(result)
        {
            _options = appliedCommand ?? throw new ArgumentNullException(nameof(appliedCommand));

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: appliedCommand.OptionValuesToBeForwarded());
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder
                = toolManifestFinder
                  ?? new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));

            _localToolsResolverCache = localToolsResolverCache ??
                                       new LocalToolsResolverCache(
                new FileSystemWrapper(),
                new DirectoryPath(
                    Path.Combine(CliFolderPathCalculator.ToolsResolverCachePath)),
                LocalToolResolverCacheVersion);

            _nugetGlobalPackagesFolder =
                nugetGlobalPackagesFolder ?? new DirectoryPath(NuGetGlobalPackagesFolder.GetLocation());
            _reporter      = reporter ?? Reporter.Output;
            _errorReporter = reporter ?? Reporter.Error;

            _configFilePath = appliedCommand.ValueOrDefault <string>("configfile");
            _sources        = appliedCommand.ValueOrDefault <string[]>("add-source");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");
        }
示例#6
0
        public static (FilePath?filePath, string warningMessage) ExplicitManifestOrFindManifestContainPackageId(
            this IToolManifestFinder toolManifestFinder,
            string explicitManifestFile,
            PackageId packageId)
        {
            if (!string.IsNullOrWhiteSpace(explicitManifestFile))
            {
                return(new FilePath(explicitManifestFile), null);
            }

            IReadOnlyList <FilePath> manifestFilesContainPackageId;

            try
            {
                manifestFilesContainPackageId
                    = toolManifestFinder.FindByPackageId(packageId);
            }
            catch (ToolManifestCannotBeFoundException e)
            {
                throw new GracefulException(new[]
                {
                    e.Message,
                    LocalizableStrings.NoManifestGuide
                },
                                            verboseMessages: new[] { e.VerboseMessage },
                                            isUserError: false);
            }

            if (manifestFilesContainPackageId.Any())
            {
                string warning = null;
                if (manifestFilesContainPackageId.Count > 1)
                {
                    warning =
                        string.Format(
                            LocalizableStrings.SamePackageIdInOtherManifestFile,
                            string.Join(
                                Environment.NewLine,
                                manifestFilesContainPackageId.Skip(1).Select(m => $"\t{m}")));
                }

                return(manifestFilesContainPackageId.First(), warning);
            }

            return(null, null);
        }
示例#7
0
        public ToolInstallLocalCommand(
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _explicitManifestFile = parseResult.ValueForOption <string>(ToolAppliedOption.ToolManifestOptionAlias);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(parseResult, toolPackageInstaller);
        }
示例#8
0
        public ToolUpdateLocalCommand(
            ParseResult parseResult,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            IToolManifestEditor toolManifestEditor           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _packageId            = new PackageId(parseResult.GetValueForArgument(ToolUpdateCommandParser.PackageIdArgument));
            _explicitManifestFile = parseResult.GetValueForOption(ToolUpdateCommandParser.ToolManifestOption);

            _reporter = (reporter ?? Reporter.Output);

            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: parseResult.OptionValuesToBeForwarded(ToolUpdateCommandParser.GetCommand()));
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor        = toolManifestEditor ?? new ToolManifestEditor();
            _localToolsResolverCache   = localToolsResolverCache ?? new LocalToolsResolverCache();
            _toolLocalPackageInstaller = new ToolInstallLocalInstaller(parseResult, toolPackageInstaller);
            _toolInstallLocalCommand   = new Lazy <ToolInstallLocalCommand>(
                () => new ToolInstallLocalCommand(
                    parseResult,
                    _toolPackageInstaller,
                    _toolManifestFinder,
                    _toolManifestEditor,
                    _localToolsResolverCache,
                    _reporter));
        }
示例#9
0
        public ToolUninstallLocalCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolManifestFinder toolManifestFinder = null,
            IToolManifestEditor toolManifestEditor = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId            = new PackageId(appliedCommand.Arguments.Single());
            _explicitManifestFile = appliedCommand.SingleArgumentOrDefault(ToolAppliedOption.ToolManifest);

            _reporter = (reporter ?? Reporter.Output);

            _toolManifestFinder = toolManifestFinder ??
                                  new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));
            _toolManifestEditor = toolManifestEditor ?? new ToolManifestEditor();
        }
示例#10
0
        public ToolRestoreCommand(
            ParseResult result,
            IToolPackageInstaller toolPackageInstaller       = null,
            IToolManifestFinder toolManifestFinder           = null,
            ILocalToolsResolverCache localToolsResolverCache = null,
            IFileSystem fileSystem = null,
            IReporter reporter     = null)
            : base(result)
        {
            if (toolPackageInstaller == null)
            {
                (IToolPackageStore,
                 IToolPackageStoreQuery,
                 IToolPackageInstaller installer)toolPackageStoresAndInstaller
                    = ToolPackageFactory.CreateToolPackageStoresAndInstaller(
                          additionalRestoreArguments: result.OptionValuesToBeForwarded(ToolRestoreCommandParser.GetCommand()));
                _toolPackageInstaller = toolPackageStoresAndInstaller.installer;
            }
            else
            {
                _toolPackageInstaller = toolPackageInstaller;
            }

            _toolManifestFinder
                = toolManifestFinder
                  ?? new ToolManifestFinder(new DirectoryPath(Directory.GetCurrentDirectory()));

            _localToolsResolverCache = localToolsResolverCache ?? new LocalToolsResolverCache();
            _fileSystem = fileSystem ?? new FileSystemWrapper();

            _reporter      = reporter ?? Reporter.Output;
            _errorReporter = reporter ?? Reporter.Error;

            _configFilePath = result.ValueForOption <string>(ToolRestoreCommandParser.ConfigOption);
            _sources        = result.ValueForOption <string[]>(ToolRestoreCommandParser.AddSourceOption);
            _verbosity      = Enum.GetName(result.ValueForOption <VerbosityOptions>(ToolRestoreCommandParser.VerbosityOption));
        }