Compare commits
2
Commits
5c262fe425
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d6999153ae | ||
|
|
70dec5834e |
No files matched your search
@@ -0,0 +1 @@
|
||||
disable_all_formatting = true
|
||||
@@ -0,0 +1,13 @@
|
||||
use super::Exit;
|
||||
|
||||
/// A subcommand that keel can run.
|
||||
pub trait Command
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit>;
|
||||
|
||||
/// The exit status used when `run` returns an error.
|
||||
///
|
||||
/// Hook subcommands return `Exit::Ok` here, so an
|
||||
/// internal error never aborts a pacman transaction.
|
||||
fn on_error(&self) -> Exit { Exit::Error }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Clear a failed state without rolling back.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Ack;
|
||||
|
||||
impl Command for Ack
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel ack") }
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
use clap::{ Args, Subcommand };
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Manage the ELF symbol index.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Cache {
|
||||
#[command(subcommand)]
|
||||
pub action: CacheAction,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum CacheAction {
|
||||
Prune(Prune),
|
||||
}
|
||||
|
||||
impl CacheAction
|
||||
{
|
||||
pub fn command(&self) -> &dyn Command
|
||||
{
|
||||
match self {
|
||||
Self::Prune(c) => c,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for Cache
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { self.action.command().run() }
|
||||
|
||||
fn on_error(&self) -> Exit { self.action.command().on_error() }
|
||||
}
|
||||
|
||||
/// Drop index entries for package versions that are no longer installed.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Prune;
|
||||
|
||||
impl Command for Prune
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel cache prune") }
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Run the pre-transaction checks as if a full system upgrade ran now.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Check {
|
||||
/// Download the package archives of the upgrade, so the ELF check can inspect them.
|
||||
#[arg(long)]
|
||||
pub download: bool,
|
||||
}
|
||||
|
||||
impl Command for Check
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel check") }
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Show the package changes between a snapshot and the live root.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Diff {
|
||||
/// The snapshot to compare with, as the snapshot provider names it.
|
||||
/// The default is the rollback target.
|
||||
#[arg(value_name = "SNAPSHOT")]
|
||||
pub snapshot: Option<String>,
|
||||
}
|
||||
|
||||
impl Command for Diff
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel diff") }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Show the detected layout and everything that would stop a rollback.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Doctor;
|
||||
|
||||
impl Command for Doctor
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel doctor") }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Delete root subvolumes set aside by earlier rollbacks once they are old enough.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Gc;
|
||||
|
||||
impl Command for Gc
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel gc") }
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
use clap::{ Args, Subcommand };
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Run one of keel's pacman hooks. Pacman passes the targets on standard input.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Hook {
|
||||
#[command(subcommand)]
|
||||
pub phase: Phase,
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Phase {
|
||||
Removals(Removals),
|
||||
Pre(Pre),
|
||||
Post(Post),
|
||||
}
|
||||
|
||||
impl Phase
|
||||
{
|
||||
pub fn command(&self) -> &dyn Command
|
||||
{
|
||||
match self {
|
||||
Self::Removals(c) => c,
|
||||
Self::Pre(c) => c,
|
||||
Self::Post(c) => c,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Command for Hook
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { self.phase.command().run() }
|
||||
|
||||
fn on_error(&self) -> Exit { self.phase.command().on_error() }
|
||||
}
|
||||
|
||||
/// Record the packages this transaction removes.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Removals;
|
||||
|
||||
impl Command for Removals
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel hook removals") }
|
||||
|
||||
fn on_error(&self) -> Exit { Exit::Ok }
|
||||
}
|
||||
|
||||
/// Check the pending transaction for skew and abort it on blocking findings.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Pre;
|
||||
|
||||
impl Command for Pre
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel hook pre") }
|
||||
|
||||
fn on_error(&self) -> Exit { Exit::Ok }
|
||||
}
|
||||
|
||||
/// Verify the system after the transaction and offer a rollback on failure.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Post;
|
||||
|
||||
impl Command for Post
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel hook post") }
|
||||
|
||||
fn on_error(&self) -> Exit { Exit::Ok }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Build the ELF symbol index for every installed package, or resume an interrupted build.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Index;
|
||||
|
||||
impl Command for Index
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel index") }
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
mod ack;
|
||||
mod cache;
|
||||
mod check;
|
||||
mod diff;
|
||||
mod doctor;
|
||||
mod gc;
|
||||
mod hook;
|
||||
mod index;
|
||||
mod notify;
|
||||
mod rollback;
|
||||
mod status;
|
||||
mod toggle;
|
||||
mod verify;
|
||||
|
||||
pub use ack::Ack;
|
||||
pub use cache::{ Cache, Prune, CacheAction };
|
||||
pub use check::Check;
|
||||
pub use diff::Diff;
|
||||
pub use doctor::Doctor;
|
||||
pub use gc::Gc;
|
||||
pub use hook::{ Pre, Hook, Post, Phase, Removals };
|
||||
pub use index::Index;
|
||||
pub use notify::Notify;
|
||||
pub use rollback::Rollback;
|
||||
pub use status::Status;
|
||||
pub use toggle::{ Enable, Disable, HookSet };
|
||||
pub use verify::Verify;
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Show a desktop notification if the last update failed, was blocked, or keel is disabled.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Notify;
|
||||
|
||||
impl Command for Notify
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel notify") }
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Replace the root subvolume with a writable copy of a snapshot.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Rollback {
|
||||
/// The snapshot to restore, as the snapshot provider names it.
|
||||
/// The default is the rollback target.
|
||||
#[arg(value_name = "SNAPSHOT", conflicts_with = "promote")]
|
||||
pub snapshot: Option<String>,
|
||||
|
||||
/// Restore the snapshot the system is currently booted from.
|
||||
#[arg(long)]
|
||||
pub promote: bool,
|
||||
|
||||
/// Skip the confirmation prompt.
|
||||
#[arg(long, short = 'y')]
|
||||
pub yes: bool,
|
||||
|
||||
/// Reboot without asking once the rollback is done.
|
||||
#[arg(long)]
|
||||
pub reboot: bool,
|
||||
|
||||
/// Wait until pacman releases its database lock, then roll back without asking.
|
||||
/// The post hook starts this in a transient unit after the user has already confirmed.
|
||||
#[arg(long, hide = true, requires = "snapshot")]
|
||||
pub deferred: bool,
|
||||
}
|
||||
|
||||
impl Command for Rollback
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel rollback") }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Show the last recorded state, its findings and rollback target, and any disabled hooks.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Status;
|
||||
|
||||
impl Command for Status
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel status") }
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
use clap::{ Args, ValueEnum };
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, ValueEnum)]
|
||||
pub enum HookSet {
|
||||
/// Both pre-transaction hooks, removals and pre.
|
||||
Pre,
|
||||
/// The post-transaction hook.
|
||||
Post,
|
||||
/// All three hooks.
|
||||
All,
|
||||
}
|
||||
|
||||
/// Unmask keel's pacman hooks.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Enable {
|
||||
pub hooks: HookSet,
|
||||
}
|
||||
|
||||
impl Command for Enable
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel enable") }
|
||||
}
|
||||
|
||||
/// Mask keel's pacman hooks. This works even when keel's config or state is broken.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Disable {
|
||||
pub hooks: HookSet,
|
||||
}
|
||||
|
||||
impl Command for Disable
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel disable") }
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
use clap::Args;
|
||||
|
||||
use crate::cli::{ Exit, Command };
|
||||
|
||||
/// Run the post-transaction checks on the current system.
|
||||
#[derive(Debug, Args)]
|
||||
pub struct Verify;
|
||||
|
||||
impl Command for Verify
|
||||
{
|
||||
fn run(&self) -> anyhow::Result<Exit> { todo!("keel verify") }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
use std::process::ExitCode;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u8)]
|
||||
pub enum Exit {
|
||||
Ok = 0,
|
||||
/// Blocking findings, or a refused rollback.
|
||||
/// The pre hook's wrapper aborts pacman on
|
||||
/// this status and on no other.
|
||||
Blocked = 1,
|
||||
/// A usage or environment error.
|
||||
Error = 2,
|
||||
}
|
||||
|
||||
impl From<Exit> for ExitCode
|
||||
{
|
||||
fn from(exit: Exit) -> Self { ExitCode::from(exit as u8) }
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
mod command;
|
||||
mod exit;
|
||||
|
||||
pub mod commands;
|
||||
|
||||
// ------
|
||||
|
||||
use clap::{ Parser, Subcommand };
|
||||
|
||||
pub use command::Command;
|
||||
pub use exit::Exit;
|
||||
|
||||
use commands::{
|
||||
Ack, Cache, Check, Diff, Disable, Doctor, Enable,
|
||||
Gc, Hook, Index, Notify, Rollback, Status, Verify,
|
||||
};
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "keel", version, about)]
|
||||
pub struct Cli {
|
||||
#[command(subcommand)]
|
||||
pub command: Commands,
|
||||
}
|
||||
|
||||
impl Cli
|
||||
{
|
||||
/// Runs the parsed subcommand and turns an error into that subcommand's error status.
|
||||
pub fn run(&self) -> Exit
|
||||
{
|
||||
let command = self.command.command();
|
||||
|
||||
match command.run()
|
||||
{
|
||||
Ok(exit) => exit,
|
||||
Err(err) => {
|
||||
eprintln!("keel: {err:#}");
|
||||
command.on_error()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Subcommand)]
|
||||
pub enum Commands {
|
||||
Hook(Hook),
|
||||
Enable(Enable),
|
||||
Disable(Disable),
|
||||
Check(Check),
|
||||
Verify(Verify),
|
||||
Status(Status),
|
||||
Notify(Notify),
|
||||
Diff(Diff),
|
||||
Rollback(Rollback),
|
||||
Ack(Ack),
|
||||
Doctor(Doctor),
|
||||
Index(Index),
|
||||
Cache(Cache),
|
||||
Gc(Gc),
|
||||
}
|
||||
|
||||
impl Commands
|
||||
{
|
||||
pub fn command(&self) -> &dyn Command
|
||||
{
|
||||
match self {
|
||||
Self::Hook(c) => c,
|
||||
Self::Enable(c) => c,
|
||||
Self::Disable(c) => c,
|
||||
Self::Check(c) => c,
|
||||
Self::Verify(c) => c,
|
||||
Self::Status(c) => c,
|
||||
Self::Notify(c) => c,
|
||||
Self::Diff(c) => c,
|
||||
Self::Rollback(c) => c,
|
||||
Self::Ack(c) => c,
|
||||
Self::Doctor(c) => c,
|
||||
Self::Index(c) => c,
|
||||
Self::Cache(c) => c,
|
||||
Self::Gc(c) => c,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
pub mod cli;
|
||||
+11
-1
@@ -1 +1,11 @@
|
||||
fn main() {}
|
||||
use std::process::ExitCode;
|
||||
use clap::Parser;
|
||||
|
||||
use keel::cli::Cli;
|
||||
|
||||
fn main() -> ExitCode
|
||||
{
|
||||
Cli::parse()
|
||||
.run()
|
||||
.into()
|
||||
}
|
||||
Reference in new issue
Block a user