public DeleteRuntimesCommand(IReporter reporter, INetCoreHelper netCoreHelper) : base(
                "deleteruntimes",
                "deleteNetCoreRuntimes",
                "Deletes .NET Core runtimes that are installed."
                )
        {
            Debug.Assert(reporter != null);
            Debug.Assert(netCoreHelper != null);

            var optionRuntimeToDelete = this.Option <string>(
                "-v|--version",
                "Version of the runtime to be deleted. If there are multiple runtimes, in different categories matching the version and the category parameter is not passed then all will be deleted.",
                CommandOptionType.MultipleValue);

            optionRuntimeToDelete.IsRequired(errorMessage: "Version to delete is required.");

            var optionCategoryToDelete = this.Option <string>(
                "-c|--category",
                "Category for the runtime installation (for example 'Microsoft.NETCore.App' or 'Microsoft.AspNetCore.All)'",
                CommandOptionType.MultipleValue);

            var optionWhatIf = this.Option <string>(
                "-w|--whatif",
                "Will display the list of folders that would be removed if the command was executed without this switch.",
                CommandOptionType.NoValue);

            this.OnExecute(async() => {
                var runtimeVersionsToDelete = optionRuntimeToDelete.ParsedValues;
                var categories = optionCategoryToDelete.HasValue() ?
                                 optionCategoryToDelete.ParsedValues :
                                 null;

                var whatif = optionWhatIf.HasValue();
                if (whatif)
                {
                    reporter.Output("Running in whatif mode");
                }

                var runtimesToDelete = await netCoreHelper.GetRuntimesInstalledAsync(
                    (runtimeVersionsToDelete ?? (new List <string>())).ToList(),
                    (categories ?? new List <string>()).ToList());

                foreach (var runtime in runtimesToDelete)
                {
                    if (Directory.Exists(runtime.InstallPath))
                    {
                        reporter.Output($"Deleting folder at {runtime.InstallPath}");

                        if (!whatif)
                        {
                            Directory.Delete(runtime.InstallPath, true);
                        }
                    }
                }
            });
        }
Exemple #2
0
        public ListRuntimesCommand(IReporter reporter, INetCoreHelper netCoreHelper) : base(
                "listruntimes",
                "listNetCoreRuntimes",
                "Lists the .NET Core runtimes that are installed.")
        {
            Debug.Assert(reporter != null);
            Debug.Assert(netCoreHelper != null);

            // no options
            this.OnExecute(async() => {
                reporter.Output(await netCoreHelper.GetRuntimesInstalledString());
            });
        }
Exemple #3
0
        public DeleteSdksCommand(IReporter reporter, INetCoreHelper netCoreHelper) : base(
                "deletesdks",
                "deletesdks",
                "Deletes .NET Core SDKs that are installed.")
        {
            Debug.Assert(reporter != null);
            Debug.Assert(netCoreHelper != null);

            // options
            var optionSdkToDelete = this.Option <string>(
                "-v|--version",
                "SDK version to delete",
                CommandOptionType.MultipleValue);

            optionSdkToDelete.IsRequired(errorMessage: "Version to delete is required");

            var optionWhatIf = this.Option <string>(
                "--whatif",
                "Will display the list of folders that would be removed if the command was executed without this switch.",
                CommandOptionType.NoValue);

            this.OnExecute(async() => {
                var sdkVersionsToDelete = optionSdkToDelete.ParsedValues;
                var whatIf = optionWhatIf.HasValue();

                var sdksInstalled = await netCoreHelper.GetSdksInstalledAsync();

                foreach (var verToDelete in sdkVersionsToDelete)
                {
                    bool foundVerLocalPathToDelete = false;
                    foreach (var sdkInfo in sdksInstalled)
                    {
                        if (string.Compare(verToDelete, sdkInfo.Version, StringComparison.OrdinalIgnoreCase) != 0)
                        {
                            continue;
                        }

                        if (Directory.Exists(sdkInfo.InstallPath))
                        {
                            reporter.Output($"Deleting folder {sdkInfo.InstallPath}");
                            foundVerLocalPathToDelete = true;

                            if (!whatIf)
                            {
                                // perform deletion
                                Directory.Delete(sdkInfo.InstallPath, true);
                            }
                        }
                        else
                        {
                            reporter.Warn($"SDK directory not found at '{sdkInfo.InstallPath}'");
                        }
                    }

                    if (!foundVerLocalPathToDelete)
                    {
                        reporter.Warn($"No installed version found for '{verToDelete}'");
                    }
                }
            });
        }