luxe update and /update, editable question answers, and a version bump owed once per release
- luxe update and /update update Luxe with the command for however it was installed (cargo or Homebrew), run one program at a time with the terminal attached, then check that the luxe on PATH is the new version. Luxe never downloads or replaces its own binary. The start screen says "Update available · /update". - A question's typed answer edits at its caret: arrows, word jumps, Home, End and Delete work, and up and down move through a wrapped answer before leaving it. - The version check owes a bump once per release: the version on main is the next release, and only a released one (a v-tag) has to move. - Dependency updates arrive through the sync, so Dependabot and the weekly jobs no longer run here.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
//! Update notice — whether a newer Luxe exists, and what *this* user should run to get it.
|
||||
//!
|
||||
//! Luxe does not update itself. What it does is notice that it is behind and say so once, in the
|
||||
//! dashboard footer, naming the command that matches how this copy was installed. Telling somebody
|
||||
//! who installed through Homebrew to run `cargo install --force` is worse than saying nothing: it
|
||||
//! is wrong, and following it leaves them with two Luxes and no idea which one is on `PATH`.
|
||||
//! Luxe never rewrites its own binary. It notices that it is behind and says so in the dashboard
|
||||
//! footer, and on request runs the update command that matches how this copy was installed, so
|
||||
//! the install's owner does the replacing. Telling somebody who installed through Homebrew to run
|
||||
//! `cargo install --force` is worse than saying nothing: it is wrong, and following it leaves them
|
||||
//! with two Luxes and no idea which one is on `PATH`.
|
||||
//!
|
||||
//! Everything here is pure or reads a local file. The one network call lives in `luxe-cli`, which
|
||||
//! is where outbound requests belong; this module only decides what to make of the answer. That
|
||||
@@ -82,12 +83,17 @@ impl InstallSource {
|
||||
Self::Archive
|
||||
}
|
||||
|
||||
/// What to tell the reader to run, or `None` when the honest answer is "however you installed
|
||||
/// it". A wrong command is worse than an absent one, so this refuses to guess.
|
||||
pub fn update_command(&self) -> Option<&'static str> {
|
||||
/// The commands that update this install, in order, each as a program and its arguments, or
|
||||
/// `None` when the honest answer is "however you installed it". A wrong command is worse than
|
||||
/// an absent one, so this refuses to guess.
|
||||
///
|
||||
/// Run directly rather than through a shell, so nothing in them is ever interpreted. Homebrew
|
||||
/// refreshes its index first, or `upgrade` can find nothing newer than the release the notice
|
||||
/// already read; cargo installs `--locked`, the dependency versions the release was tested with.
|
||||
pub fn update_steps(&self) -> Option<&'static [&'static [&'static str]]> {
|
||||
match self {
|
||||
Self::Cargo => Some("cargo install --force luxe-cli"),
|
||||
Self::Homebrew => Some("brew upgrade luxe"),
|
||||
Self::Cargo => Some(&[&["cargo", "install", "--locked", "--force", "luxe-cli"]]),
|
||||
Self::Homebrew => Some(&[&["brew", "update"], &["brew", "upgrade", "luxe"]]),
|
||||
// Which package manager owns it is not knowable without querying one, and guessing
|
||||
// `apt` on an Arch machine is the failure this whole function exists to avoid.
|
||||
Self::SystemPackage => None,
|
||||
@@ -95,6 +101,12 @@ impl InstallSource {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`Self::update_steps`] as one line a person could type: the steps joined with `&&`.
|
||||
pub fn update_command(&self) -> Option<String> {
|
||||
let steps = self.update_steps()?;
|
||||
Some(steps.iter().map(|step| step.join(" ")).collect::<Vec<_>>().join(" && "))
|
||||
}
|
||||
|
||||
/// The advice, as a sentence fragment that follows "— ".
|
||||
pub fn advice(&self) -> String {
|
||||
match self.update_command() {
|
||||
|
||||
@@ -9,7 +9,26 @@ fn a_cargo_install_is_told_to_use_cargo() {
|
||||
] {
|
||||
assert_eq!(InstallSource::from_path(Path::new(path)), InstallSource::Cargo, "{path}");
|
||||
}
|
||||
assert_eq!(InstallSource::Cargo.update_command(), Some("cargo install --force luxe-cli"));
|
||||
assert_eq!(
|
||||
InstallSource::Cargo.update_command().as_deref(),
|
||||
Some("cargo install --locked --force luxe-cli")
|
||||
);
|
||||
}
|
||||
|
||||
/// The steps are what runs, one program at a time with no shell between, so they are pinned as
|
||||
/// argument lists: a flag moved into the wrong step, or a shell operator turned into an argument,
|
||||
/// would read the same in the joined line and run very differently.
|
||||
#[test]
|
||||
fn the_update_steps_are_the_owners_own_commands() {
|
||||
let cargo: &[&[&str]] = &[&["cargo", "install", "--locked", "--force", "luxe-cli"]];
|
||||
let brew: &[&[&str]] = &[&["brew", "update"], &["brew", "upgrade", "luxe"]];
|
||||
assert_eq!(InstallSource::Cargo.update_steps(), Some(cargo));
|
||||
assert_eq!(InstallSource::Homebrew.update_steps(), Some(brew));
|
||||
assert_eq!(
|
||||
InstallSource::Homebrew.update_command().as_deref(),
|
||||
Some("brew update && brew upgrade luxe")
|
||||
);
|
||||
assert_eq!(InstallSource::Archive.update_steps(), None, "a download has no owner to ask");
|
||||
}
|
||||
|
||||
/// Homebrew is checked first because its Linux and Intel-macOS prefixes sit *inside* paths the
|
||||
@@ -91,7 +110,7 @@ fn a_notice_names_both_versions_and_the_command() {
|
||||
let line = notice.line();
|
||||
assert!(line.contains("0.2.0"), "{line}");
|
||||
assert!(line.contains("you have 0.1.0"), "{line}");
|
||||
assert!(line.contains("cargo install --force luxe-cli"), "{line}");
|
||||
assert!(line.contains("cargo install --locked --force luxe-cli"), "{line}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user