Skip to content

Commit

Permalink
Support --layers squash-other, add colors to clap
Browse files Browse the repository at this point in the history
  • Loading branch information
jssblck committed Dec 13, 2024
1 parent 200ec5b commit 8101c6d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion bin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions bin/src/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(&registry, &output, layers).await,
Mode::SquashOther => squash(&registry, &output, layers.into_iter().skip(1)).await,
Mode::Base => squash(&registry, &output, layers.into_iter().take(1)).await,
Mode::Separate => separate(&registry, &output, layers).await,
}
Expand Down
18 changes: 16 additions & 2 deletions bin/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
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::*};

mod extract;
mod list;
#[derive(Debug, Parser)]
#[command(author, version, about)]
#[command(version, about, styles = style())]
struct Cli {
#[command(subcommand)]
command: Commands,
Expand Down Expand Up @@ -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())
}

0 comments on commit 8101c6d

Please sign in to comment.