pub struct Install { /* private fields */ }Expand description
One package to install with this machine’s package manager: the command, the question that shows it and the handoff that runs it.
Made by Install::package, which looks for pacman, apt-get, dnf, zypper, apk and
brew on PATH in that order and takes the first. The command is the manager’s own install
command with sudo in front when the application does not run as root, such as
sudo pacman -S --needed libarchive; no “yes” flag is added, so the manager shows its own
question and the person answers it.
use std::path::PathBuf;
use qframe::install::{Install, Manager};
// A machine with `apt-get` and nothing else, the application not running as root.
let lookup = |program: &str| (program == "apt-get").then(|| PathBuf::from("/usr/bin/apt-get"));
let install = Install::package_with("libarchive", lookup, false)
.expect("a package manager")
.name_for(Manager::Apt, "libarchive-tools");
assert_eq!(install.manager(), Manager::Apt);
assert_eq!(install.command_line(), "sudo apt-get install libarchive-tools");Implementations§
Source§impl Install
impl Install
Sourcepub fn package(name: &str) -> Option<Install>
pub fn package(name: &str) -> Option<Install>
The package name with this machine’s package manager, found on PATH; None when there
is none, or when name cannot be a package name (empty, starting with -, or holding a
space or a control character).
Homebrew is passed over when the application runs as root, since it refuses to run so.
Sourcepub fn package_with(
name: &str,
lookup: impl Fn(&str) -> Option<PathBuf>,
root: bool,
) -> Option<Install>
pub fn package_with( name: &str, lookup: impl Fn(&str) -> Option<PathBuf>, root: bool, ) -> Option<Install>
Install::package with the search given: lookup says where a program is, or None
when it is not installed, and root whether the application runs as root. For tests, and
for an application that decides itself where programs are.
Sourcepub fn name_for(self, manager: Manager, name: &str) -> Self
pub fn name_for(self, manager: Manager, name: &str) -> Self
Uses name instead when the package manager is manager, for a package that is called
differently there: libarchive on Arch is libarchive-tools on Debian. Nothing changes on
other managers, nor when name cannot be a package name.
Sourcepub fn program(&self) -> Vec<OsString>
pub fn program(&self) -> Vec<OsString>
The command’s words, the program first: ["sudo", "pacman", "-S", "--needed", "libarchive"].
Sourcepub fn command_line(&self) -> String
pub fn command_line(&self) -> String
The command as the person reads it: sudo pacman -S --needed libarchive. The words need
no quoting, since a package name holds no space.
Sourcepub fn confirm<Msg>(&self, on_yes: Msg) -> Confirm<Msg>
pub fn confirm<Msg>(&self, on_yes: Msg) -> Confirm<Msg>
The question to ask before installing: which package, the exact command line, and that
the package manager may ask for a password. The confirm button reads Install and sends
on_yes; Cancel, Esc and the close mark install nothing. Add
on_cancel for a message when the person declines.
The text comes from quvyta.install.title, quvyta.install.runs,
quvyta.install.asks and quvyta.install.confirm in the active language.
Sourcepub fn handoff<Msg: Send + 'static>(
&self,
on_finish: impl FnOnce(HandoffOutcome) -> Msg + Send + 'static,
) -> Handoff<Msg>
pub fn handoff<Msg: Send + 'static>( &self, on_finish: impl FnOnce(HandoffOutcome) -> Msg + Send + 'static, ) -> Handoff<Msg>
The handoff that runs the command: the terminal is the package manager’s until it ends,
with a line saying what is being installed (quvyta.install.notice) above its output,
and a key press awaited afterwards so its last lines can be read. on_finish receives how
it ended; an exit code other than zero means the package was not installed.
Return it only after the person agreed to confirm.
Trait Implementations§
impl Eq for Install
impl StructuralPartialEq for Install
Auto Trait Implementations§
impl Freeze for Install
impl RefUnwindSafe for Install
impl Send for Install
impl Sync for Install
impl Unpin for Install
impl UnsafeUnpin for Install
impl UnwindSafe for Install
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more