Files
RedBear-OS/initfs/tools/src/bin/archive.rs
T
bjorn3 2c96332aa7 Add 'initfs/' from commit 'd0802237d7894881df7ddd338dfc64220d0646ff'
git-subtree-dir: initfs
git-subtree-mainline: bb25f45f43
git-subtree-split: d0802237d7
2025-04-23 19:56:49 +02:00

68 lines
2.0 KiB
Rust

use std::path::Path;
use anyhow::{Context, Result};
use clap::{Arg, Command};
use archive_common::{self as archive, Args, DEFAULT_MAX_SIZE};
fn main() -> Result<()> {
let matches = Command::new("redox-initfs-ar")
.about("create an initfs image from a directory")
.version(clap::crate_version!())
.author(clap::crate_authors!())
.arg(
Arg::new("MAX_SIZE")
.long("max-size")
.short('m')
.required(false)
.help("Set the upper limit for how large the image can become (default 64 MiB)."),
)
// TODO: support non-utf8 paths (applies to other paths as well)
.arg(
Arg::new("SOURCE")
.required(true)
.help("Specify the source directory to build the image from."),
)
.arg(
Arg::new("BOOTSTRAP_CODE")
.required(false)
.help("Specify the bootstrap ELF file to include in the image."),
)
.arg(
Arg::new("OUTPUT")
.required(true)
.long("output")
.short('o')
.help("Specify the path of the new image file."),
)
.get_matches();
env_logger::init();
let max_size = if let Some(max_size_str) = matches.get_one::<String>("MAX_SIZE") {
max_size_str
.parse::<u64>()
.context("expected an integer for MAX_SIZE")?
} else {
DEFAULT_MAX_SIZE
};
let source = matches
.get_one::<String>("SOURCE")
.expect("expected the required arg SOURCE to exist");
let bootstrap_code = matches.get_one::<String>("BOOTSTRAP_CODE");
let destination = matches
.get_one::<String>("OUTPUT")
.expect("expected the required arg OUTPUT to exist");
let args = Args {
source: Path::new(source),
bootstrap_code: bootstrap_code.map(Path::new),
destination_path: Path::new(destination),
max_size,
};
archive::archive(&args)
}