Compare commits

..
2 Commits
Author SHA1 Message Date
Overlord d6999153ae Fix formatting issues. 2026-10-17 01:38:34 +02:00
Overlord 70dec5834e Add core CLI command structure and subcommands. 2026-10-16 22:24:35 +02:00
20 changed files with 449 additions and 1 deletions

No files matched your search

+1
View File
@@ -0,0 +1 @@
disable_all_formatting = true
+13
View File
@@ -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 }
}
+12
View File
@@ -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") }
}
+41
View File
@@ -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") }
}
+16
View File
@@ -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") }
}
+17
View File
@@ -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") }
}
+12
View File
@@ -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") }
}
+12
View File
@@ -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") }
}
+69
View File
@@ -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 }
}
+12
View File
@@ -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") }
}
+27
View File
@@ -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;
+12
View File
@@ -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") }
}
+34
View File
@@ -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") }
}
+12
View File
@@ -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") }
}
+35
View File
@@ -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") }
}
+12
View File
@@ -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") }
}
+18
View File
@@ -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) }
}
+82
View File
@@ -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,
}
}
}
+1
View File
@@ -0,0 +1 @@
pub mod cli;
+11 -1
View File
@@ -1 +1,11 @@
fn main() {}
use std::process::ExitCode;
use clap::Parser;
use keel::cli::Cli;
fn main() -> ExitCode
{
Cli::parse()
.run()
.into()
}