From 8101c6d3899b919b3217121ec3b5212fae8d34cd Mon Sep 17 00:00:00 2001 From: Jessica Black Date: Fri, 13 Dec 2024 14:41:49 -0800 Subject: [PATCH] Support `--layers squash-other`, add colors to clap --- CHANGELOG.md | 6 ++++++ README.md | 1 + bin/Cargo.toml | 2 +- bin/src/extract.rs | 4 ++++ bin/src/main.rs | 18 ++++++++++++++++-- 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8804af7..fb57b54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,10 @@ +# v0.3.2 + +- General: Add color to CLI output. +- `extract`: Add `--squash-other` mode. + - `--layers squash-other`: Squash all layers other than the base layer. + # v0.3.1 - `extract`: absolute symlinks are now correctly made relative to the target directory. diff --git a/README.md b/README.md index 707e67e..e512411 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ Extracts the contents of the image to disk. # Options for `circe extract`: # --layers # squash: Combines all layers into a single layer (default). +# squash-other: Combines all layers except the base layer into a single layer. # base: Excludes all layers except the base layer. # separate: Exports each layer in a separate subdirectory. # --platform diff --git a/bin/Cargo.toml b/bin/Cargo.toml index dac255d..58a70d5 100644 --- a/bin/Cargo.toml +++ b/bin/Cargo.toml @@ -14,7 +14,7 @@ categories = ["command-line-utilities", "development-tools"] default-run = "circe" [dependencies] -clap = { version = "4.5.23", features = ["derive"] } +clap = { version = "4.5.23", features = ["color", "derive"] } color-eyre = "0.6.3" tokio = { version = "1.42.0", features = ["full"] } tracing = "0.1.41" diff --git a/bin/src/extract.rs b/bin/src/extract.rs index f8489f9..caa322b 100644 --- a/bin/src/extract.rs +++ b/bin/src/extract.rs @@ -119,6 +119,9 @@ pub enum Mode { /// Only extract the base layer. Base, + /// Squash all "other" layers; "other" layers are all layers except the base layer. + SquashOther, + /// Extract all layers to a separate directory for each layer. /// Also writes a `layers.json` file containing the list of layers in application order. Separate, @@ -152,6 +155,7 @@ pub async fn main(opts: Options) -> Result<()> { let layers = registry.layers().await.context("list layers")?; match opts.layers { Mode::Squash => squash(®istry, &output, layers).await, + Mode::SquashOther => squash(®istry, &output, layers.into_iter().skip(1)).await, Mode::Base => squash(®istry, &output, layers.into_iter().take(1)).await, Mode::Separate => separate(®istry, &output, layers).await, } diff --git a/bin/src/main.rs b/bin/src/main.rs index 96bd633..c0dd842 100644 --- a/bin/src/main.rs +++ b/bin/src/main.rs @@ -1,4 +1,7 @@ -use clap::Parser; +use clap::{ + builder::{styling::AnsiColor, Styles}, + Parser, +}; use color_eyre::eyre::Result; use tracing::level_filters::LevelFilter; use tracing_subscriber::{self, prelude::*}; @@ -6,7 +9,7 @@ use tracing_subscriber::{self, prelude::*}; mod extract; mod list; #[derive(Debug, Parser)] -#[command(author, version, about)] +#[command(version, about, styles = style())] struct Cli { #[command(subcommand)] command: Commands, @@ -54,3 +57,14 @@ async fn main() -> Result<()> { Ok(()) } + +fn style() -> Styles { + Styles::styled() + .header(AnsiColor::Yellow.on_default()) + .usage(AnsiColor::Green.on_default()) + .literal(AnsiColor::Green.on_default()) + .placeholder(AnsiColor::Green.on_default()) + .error(AnsiColor::Red.on_default()) + .invalid(AnsiColor::Red.on_default()) + .valid(AnsiColor::Blue.on_default()) +}