-
Notifications
You must be signed in to change notification settings - Fork 13
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
Include tooling removal methods #69
Open
CompeyDev
wants to merge
7
commits into
rojo-rbx:main
Choose a base branch
from
CompeyDev:feat/remove-command
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
15db8c9
feat: include tooling removal methods
CompeyDev ad297cd
feat(cli): add remove subcommand
CompeyDev fe2bb28
doc: fix incorrect doc comments (x1)
CompeyDev 8519155
doc: fix incorrect doc comments (x2)
CompeyDev 8ec3f8c
doc: fix incorrect doc comments (x3)
CompeyDev 8032c53
doc: fix incorrect doc comments (x4)
CompeyDev 43e9f4e
fix(cli): incorrect number of progress updates
CompeyDev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
use anyhow::{bail, Context, Result}; | ||
use clap::Parser; | ||
use console::style; | ||
|
||
use rokit::{ | ||
discovery::discover_all_manifests, manifests::RokitManifest, storage::Home, tool::ToolAlias, | ||
}; | ||
|
||
use crate::util::CliProgressTracker; | ||
|
||
/// Removes a tool from Rokit. | ||
#[derive(Debug, Parser)] | ||
pub struct RemoveSubcommand { | ||
/// The alias of the tool to remove. | ||
pub alias: ToolAlias, | ||
/// Remove this tool globally instead of removing | ||
/// it from the nearest manifest file. | ||
#[clap(long)] | ||
pub global: bool, | ||
} | ||
|
||
impl RemoveSubcommand { | ||
pub async fn run(self, home: &Home) -> Result<()> { | ||
let tool_cache = home.tool_cache(); | ||
let tool_storage = home.tool_storage(); | ||
|
||
// 1. Load the manifest and check whether the tool | ||
// to be removed is present in the manifest | ||
let manifest_path = if self.global { | ||
home.path().to_path_buf() | ||
} else { | ||
let non_global_manifests = discover_all_manifests(true, true).await; | ||
non_global_manifests | ||
.first() | ||
.map(|m| m.path.parent().unwrap().to_path_buf()) | ||
.context( | ||
"No manifest was found for the current directory.\ | ||
\nRun `rokit init` in your project root to create one.", | ||
)? | ||
}; | ||
|
||
let mut manifest = if self.global { | ||
RokitManifest::load_or_create(&manifest_path).await? | ||
} else { | ||
RokitManifest::load(&manifest_path).await? | ||
}; | ||
if !manifest.has_tool(&self.alias) { | ||
bail!("Tool does not exist and can't be removed: {}", self.alias); | ||
} | ||
|
||
// 2. Remove the tool from the manifest | ||
let spec = manifest.get_tool(&self.alias).unwrap(); | ||
let pt = CliProgressTracker::new_with_message("Removing", 2); | ||
|
||
manifest.remove_tool(&self.alias); | ||
manifest.save(manifest_path).await?; | ||
pt.task_completed(); | ||
|
||
// 3. Uninstall the tool link | ||
if tool_cache.is_installed(&spec) { | ||
pt.update_message("Uninstalling"); | ||
tool_storage.remove_tool_link(&self.alias).await?; | ||
} | ||
pt.task_completed(); | ||
|
||
// 3. Finally, display a nice message to the user | ||
pt.finish_with_message(format!( | ||
"Removed version {} of tool {}{} {}", | ||
style(spec.version()).bold().yellow(), | ||
style(spec.name()).bold().magenta(), | ||
if self.alias.name() == spec.id().name() { | ||
String::new() | ||
} else { | ||
format!( | ||
" with alias {}", | ||
style(self.alias.to_string()).bold().cyan() | ||
) | ||
}, | ||
pt.formatted_elapsed(), | ||
)); | ||
|
||
Ok(()) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this was an auto import, so rust-analyzer put it up here, but all the imports for commands are grouped below so the new import should be there as well.