Skip to main content

Install

Struct Install 

Source
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

Source

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.

Source

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.

Source

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.

Source

pub fn manager(&self) -> Manager

The package manager that installs the package.

Source

pub fn name(&self) -> &str

The package’s name for this manager.

Source

pub fn program(&self) -> Vec<OsString>

The command’s words, the program first: ["sudo", "pacman", "-S", "--needed", "libarchive"].

Source

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.

Source

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.

Source

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§

Source§

impl Clone for Install

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Install

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for Install

Source§

impl PartialEq for Install

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Install

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.