Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small refactorings #331

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Small refactorings #331

wants to merge 3 commits into from

Conversation

edvilme
Copy link
Member

@edvilme edvilme commented Feb 27, 2025

Addresses #304
Small refactorings to IsAdmin and other places in the execute command.

@edvilme edvilme requested a review from Copilot February 27, 2025 06:03

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Overview

This PR addresses issue #304 by ensuring that administrative privileges are correctly enforced, particularly on macOS. The changes refactor the execution flow in the uninstall command by moving the admin check to the start and combining the confirmation prompts.

  • Moved the admin check to a common entry point for both yes option and interactive prompt flows.
  • Combined the confirmation prompt conditions into a single if statement.

Reviewed Changes

File Description
src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs Refactored logic to ensure admin privileges are checked upfront and unified the confirmation prompt conditions.

Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/dotnet-core-uninstall/Shared/Commands/UninstallCommandExec.cs:43

  • [nitpick] Consider extracting the combined condition into a clearly named boolean variable (e.g., 'shouldProceed') to improve readability and maintainability.
if (parseResult.FindResultFor(CommandLineConfigs.YesOption) != null || (AskItAndReturnUserAnswer(filtered) && AskWithWarningsForRequiredBundles(filtered)))
@edvilme edvilme changed the title macOS: Fix admin priviledges Small refactorings Feb 27, 2025
@edvilme edvilme marked this pull request as ready for review February 27, 2025 17:38
@edvilme edvilme requested a review from a team February 27, 2025 23:08
var response = userResponse == null ? Console.ReadLine().Trim().ToUpper() : userResponse.ToUpper();

var response = userResponse?.ToUpper() ?? Console.ReadLine().Trim().ToUpper();

if (response.Equals("N"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be checking for NO as well, given that we check for y or yes? If we really want to restrict an interactive response, then I wonder if a loop with ReadKey is better and we only accept N/n/y/Y

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was curious as to why it accepted 'y' and 'yes', but only 'n'.

If we were to change this, I would advocate towards dropping the 'yes' over adding the 'no', as I suspect most users would use the single character option (I know I would)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants