-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement self-install subcommand, improve error hygiene for linking
- Loading branch information
1 parent
950f54f
commit 1b315b7
Showing
4 changed files
with
161 additions
and
54 deletions.
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,41 @@ | ||
use anyhow::{Context, Result}; | ||
use clap::Parser; | ||
|
||
use aftman::storage::Home; | ||
|
||
/// Installs / re-installs Aftman, and updates all tool links. | ||
#[derive(Debug, Parser)] | ||
pub struct SelfInstallSubcommand {} | ||
|
||
impl SelfInstallSubcommand { | ||
pub async fn run(&self, home: &Home) -> Result<()> { | ||
let storage = home.tool_storage(); | ||
|
||
let (had_aftman_installed, was_aftman_updated) = | ||
storage.recreate_all_links().await.context( | ||
"Failed to recreate tool links!\ | ||
\nYour installation may be corrupted.", | ||
)?; | ||
|
||
// TODO: Automatically populate the PATH variable | ||
let path_was_populated = false; | ||
let path_message_lines = if !path_was_populated { | ||
"\nBinaries for Aftman and tools have been added to your PATH.\ | ||
\nPlease restart your terminal for the changes to take effect." | ||
} else { | ||
"" | ||
}; | ||
|
||
let main_message = if !had_aftman_installed { | ||
"Aftman has been installed successfully!" | ||
} else if was_aftman_updated { | ||
"Aftman was re-linked successfully!" | ||
} else { | ||
"Aftman is already up-to-date." | ||
}; | ||
|
||
tracing::info!("{main_message}{path_message_lines}"); | ||
|
||
Ok(()) | ||
} | ||
} |