Beispiel #1
0
        public InstallToolCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageObtainer toolPackageObtainer = null,
            IShellShimMaker shellShimMaker           = null,
            IEnvironmentPathInstruction environmentPathInstruction = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            if (appliedCommand == null)
            {
                throw new ArgumentNullException(nameof(appliedCommand));
            }

            _packageId      = appliedCommand.Arguments.Single();
            _packageVersion = appliedCommand.ValueOrDefault <string>("version");
            _configFilePath = appliedCommand.ValueOrDefault <string>("configfile");
            _framework      = appliedCommand.ValueOrDefault <string>("framework");
            _source         = appliedCommand.ValueOrDefault <string>("source");
            _global         = appliedCommand.ValueOrDefault <bool>("global");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");

            var cliFolderPathCalculator = new CliFolderPathCalculator();
            var offlineFeedPath         = new DirectoryPath(cliFolderPathCalculator.CliFallbackFolderPath);

            _toolPackageObtainer = toolPackageObtainer ?? new ToolPackageObtainer(
                new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath),
                offlineFeedPath,
                () => new DirectoryPath(Path.GetTempPath())
                .WithSubDirectories(Path.GetRandomFileName())
                .WithFile(Path.GetRandomFileName() + ".csproj"),
                new Lazy <string>(BundledTargetFramework.GetTargetFrameworkMoniker),
                new ProjectRestorer(reporter));

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory
                                          .CreateEnvironmentPathInstruction();

            _shellShimMaker = shellShimMaker ?? new ShellShimMaker(cliFolderPathCalculator.ToolsShimPath);

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }