コード例 #1
0
        public override int Execute()
        {
            var executablePackagePath = new DirectoryPath(new CliFolderPathCalculator().ExecutablePackagesPath);

            var toolConfigurationAndExecutableDirectory = ObtainPackage(executablePackagePath);

            DirectoryPath executable = toolConfigurationAndExecutableDirectory
                                       .ExecutableDirectory
                                       .WithSubDirectories(
                toolConfigurationAndExecutableDirectory
                .Configuration
                .ToolAssemblyEntryPoint);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutableDirectory.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                string.Format(LocalizableStrings.InstallationSucceeded, commandName));

            return(0);
        }
コード例 #2
0
        public ToolInstallCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            CreateToolPackageStoreAndInstaller createToolPackageStoreAndInstaller = null,
            CreateShellShimRepository createShellShimRepository    = null,
            IEnvironmentPathInstruction environmentPathInstruction = 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");
            _framework      = appliedCommand.ValueOrDefault <string>("framework");
            _source         = appliedCommand.ValueOrDefault <string[]>("add-source");
            _global         = appliedCommand.ValueOrDefault <bool>("global");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");
            _toolPath       = appliedCommand.SingleArgumentOrDefault("tool-path");

            _createToolPackageStoreAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoreAndInstaller;

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();
            _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository;

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }
コード例 #3
0
        public ToolInstallGlobalOrToolPathCommand(
            ParseResult parseResult,
            CreateToolPackageStoresAndInstaller createToolPackageStoreAndInstaller = null,
            CreateShellShimRepository createShellShimRepository    = null,
            IEnvironmentPathInstruction environmentPathInstruction = null,
            IReporter reporter = null)
            : base(parseResult)
        {
            _packageId      = new PackageId(parseResult.ValueForArgument <string>(ToolInstallCommandParser.PackageIdArgument));
            _packageVersion = parseResult.ValueForOption <string>(ToolInstallCommandParser.VersionOption);
            _configFilePath = parseResult.ValueForOption <string>(ToolInstallCommandParser.ConfigOption);
            _framework      = parseResult.ValueForOption <string>(ToolInstallCommandParser.FrameworkOption);
            _source         = parseResult.ValueForOption <string[]>(ToolInstallCommandParser.AddSourceOption);
            _global         = parseResult.ValueForOption <bool>(ToolAppliedOption.GlobalOptionAliases.First());
            _verbosity      = Enum.GetName(parseResult.ValueForOption <VerbosityOptions>(ToolInstallCommandParser.VerbosityOption));
            _toolPath       = parseResult.ValueForOption <string>(ToolAppliedOption.ToolPathOptionAlias);

            _createToolPackageStoresAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoresAndInstaller;
            _forwardRestoreArguments             = parseResult.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand());

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();
            _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository;

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }
コード例 #4
0
        public override int Execute()
        {
            if (!_global)
            {
                throw new GracefulException(LocalizableStrings.InstallToolCommandOnlySupportGlobal);
            }

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

            var toolConfigurationAndExecutablePath = ObtainPackage(executablePackagePath, offlineFeedPath);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutablePath.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                toolConfigurationAndExecutablePath.Executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                string.Format(LocalizableStrings.InstallationSucceeded, commandName));

            return(0);
        }
コード例 #5
0
        public void GivenLinuxItShouldReturnOsxBashEnvironmentPath()
        {
            Mock <IEnvironmentProvider> provider = new Mock <IEnvironmentProvider>(MockBehavior.Loose);

            IEnvironmentPathInstruction result =
                EnvironmentPathFactory.CreateEnvironmentPathInstruction(provider.Object);

            (result is LinuxEnvironmentPath).Should().BeTrue();
        }
コード例 #6
0
        public void GivenFollowingEnvironmentVariableValueItShouldReturnOsxBashEnvironmentPath()
        {
            Mock <IEnvironmentProvider> provider = new Mock <IEnvironmentProvider>(MockBehavior.Strict);

            provider
            .Setup(p => p.GetEnvironmentVariable("SHELL"))
            .Returns("/bin/bash");

            IEnvironmentPathInstruction result =
                EnvironmentPathFactory.CreateEnvironmentPathInstruction(provider.Object);

            (result is OsxBashEnvironmentPath).Should().BeTrue();
        }
コード例 #7
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);
        }
コード例 #8
0
ファイル: InstallToolCommand.cs プロジェクト: wei12/cli
        public override int Execute()
        {
            FilePath?configFile = null;

            if (_configFilePath != null)
            {
                configFile = new FilePath(_configFilePath);
            }

            var executablePackagePath = new DirectoryPath(new CliFolderPathCalculator().ExecutablePackagesPath);

            var toolConfigurationAndExecutableDirectory = ObtainPackage(
                _packageId,
                _packageVersion,
                configFile,
                _framework,
                executablePackagePath);

            DirectoryPath executable = toolConfigurationAndExecutableDirectory
                                       .ExecutableDirectory
                                       .WithSubDirectories(
                toolConfigurationAndExecutableDirectory
                .Configuration
                .ToolAssemblyEntryPoint);

            var shellShimMaker = new ShellShimMaker(executablePackagePath.Value);
            var commandName    = toolConfigurationAndExecutableDirectory.Configuration.CommandName;

            shellShimMaker.EnsureCommandNameUniqueness(commandName);

            shellShimMaker.CreateShim(
                executable.Value,
                commandName);

            EnvironmentPathFactory
            .CreateEnvironmentPathInstruction()
            .PrintAddPathInstructionIfPathDoesNotExist();

            Reporter.Output.WriteLine(
                $"{Environment.NewLine}The installation succeeded. If there is no other instruction. You can type the following command in shell directly to invoke: {commandName}");

            return(0);
        }
コード例 #9
0
        public InstallToolCommand(
            AppliedOption appliedCommand,
            ParseResult parseResult,
            IToolPackageStore toolPackageStore                     = null,
            IToolPackageInstaller toolPackageInstaller             = null,
            IShellShimRepository shellShimRepository               = null,
            IEnvironmentPathInstruction environmentPathInstruction = 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");
            _framework      = appliedCommand.ValueOrDefault <string>("framework");
            _source         = appliedCommand.ValueOrDefault <string>("source");
            _global         = appliedCommand.ValueOrDefault <bool>("global");
            _verbosity      = appliedCommand.SingleArgumentOrDefault("verbosity");

            var cliFolderPathCalculator = new CliFolderPathCalculator();

            _toolPackageStore = toolPackageStore
                                ?? new ToolPackageStore(new DirectoryPath(cliFolderPathCalculator.ToolsPackagePath));

            _toolPackageInstaller = toolPackageInstaller
                                    ?? new ToolPackageInstaller(
                _toolPackageStore,
                new ProjectRestorer(_reporter));

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();

            _shellShimRepository = shellShimRepository
                                   ?? new ShellShimRepository(new DirectoryPath(cliFolderPathCalculator.ToolsShimPath));

            _reporter      = (reporter ?? Reporter.Output);
            _errorReporter = (reporter ?? Reporter.Error);
        }
コード例 #10
0
        public ToolInstallGlobalOrToolPathCommand(
            ParseResult parseResult,
            CreateToolPackageStoresAndInstaller createToolPackageStoreAndInstaller = null,
            CreateShellShimRepository createShellShimRepository    = null,
            IEnvironmentPathInstruction environmentPathInstruction = null,
            IReporter reporter = null,
            INuGetPackageDownloader nugetPackageDownloader = null)
            : base(parseResult)
        {
            _packageId          = new PackageId(parseResult.ValueForArgument <string>(ToolInstallCommandParser.PackageIdArgument));
            _packageVersion     = parseResult.ValueForOption <string>(ToolInstallCommandParser.VersionOption);
            _configFilePath     = parseResult.ValueForOption <string>(ToolInstallCommandParser.ConfigOption);
            _framework          = parseResult.ValueForOption <string>(ToolInstallCommandParser.FrameworkOption);
            _source             = parseResult.ValueForOption <string[]>(ToolInstallCommandParser.AddSourceOption);
            _global             = parseResult.ValueForOption <bool>(ToolAppliedOption.GlobalOptionAliases.First());
            _verbosity          = Enum.GetName(parseResult.ValueForOption <VerbosityOptions>(ToolInstallCommandParser.VerbosityOption));
            _toolPath           = parseResult.ValueForOption <string>(ToolAppliedOption.ToolPathOptionAlias);
            _architectureOption = parseResult.ValueForOption <string>(ToolInstallCommandParser.ArchitectureOption);

            _createToolPackageStoresAndInstaller = createToolPackageStoreAndInstaller ?? ToolPackageFactory.CreateToolPackageStoresAndInstaller;
            _forwardRestoreArguments             = parseResult.OptionValuesToBeForwarded(ToolInstallCommandParser.GetCommand());

            _environmentPathInstruction = environmentPathInstruction
                                          ?? EnvironmentPathFactory.CreateEnvironmentPathInstruction();
            _createShellShimRepository = createShellShimRepository ?? ShellShimRepositoryFactory.CreateShellShimRepository;
            var tempDir               = new DirectoryPath(Path.Combine(Path.GetTempPath(), "dotnet-tool-install"));
            var configOption          = parseResult.ValueForOption(ToolInstallCommandParser.ConfigOption);
            var sourceOption          = parseResult.ValueForOption(ToolInstallCommandParser.AddSourceOption);
            var packageSourceLocation = new PackageSourceLocation(string.IsNullOrEmpty(configOption) ? null : new FilePath(configOption), additionalSourceFeeds: sourceOption);
            var restoreAction         = new RestoreActionConfig(DisableParallel: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.DisableParallelOption),
                                                                NoCache: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.NoCacheOption),
                                                                IgnoreFailedSources: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.IgnoreFailedSourcesOption),
                                                                Interactive: parseResult.ValueForOption(ToolCommandRestorePassThroughOptions.InteractiveRestoreOption));

            nugetPackageDownloader ??= new NuGetPackageDownloader(tempDir, verboseLogger: new NullLogger(), restoreActionConfig: restoreAction);
            _shellShimTemplateFinder = new ShellShimTemplateFinder(nugetPackageDownloader, tempDir, packageSourceLocation);

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