feat: Loki can now update itself via .update and --update commands

This commit is contained in:
2026-05-19 14:29:44 -06:00
parent 5a9a00bc6f
commit afa0e4af67
10 changed files with 698 additions and 9 deletions
+30
View File
@@ -137,6 +137,12 @@ pub struct Cli {
/// Generate static shell completion scripts
#[arg(long, value_name = "SHELL", value_enum)]
pub completions: Option<ShellCompletion>,
/// Update Loki to the latest release, or to a specific version
#[arg(long, value_name = "VERSION")]
pub update: Option<Option<String>>,
/// With --update, update even if Loki was installed via a package manager
#[arg(long, requires = "update")]
pub force: bool,
}
impl Cli {
@@ -396,4 +402,28 @@ mod tests {
let cli = parse(&["--macro", "my-macro"]);
assert_eq!(cli.macro_name, Some("my-macro".to_string()));
}
#[test]
fn parse_update_flag_no_value() {
let cli = parse(&["--update"]);
assert_eq!(cli.update, Some(None));
}
#[test]
fn parse_update_flag_with_version() {
let cli = parse(&["--update", "v0.4.0"]);
assert_eq!(cli.update, Some(Some("v0.4.0".to_string())));
}
#[test]
fn parse_update_with_force() {
let cli = parse(&["--update", "--force"]);
assert_eq!(cli.update, Some(None));
assert!(cli.force);
}
#[test]
fn parse_force_without_update_fails() {
assert!(Cli::try_parse_from(["loki", "--force"]).is_err());
}
}