163 lines
5.6 KiB
Rust
163 lines
5.6 KiB
Rust
use clap::{value_parser, Arg, ArgAction, Command, ValueHint};
|
|
|
|
pub fn haggis() -> Command {
|
|
Command::new("haggis")
|
|
.about("Create and extract Haggis archives")
|
|
.author("Nathan Fisher")
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
.propagate_version(true)
|
|
.arg_required_else_help(true)
|
|
.subcommands([create(), extract(), list()])
|
|
}
|
|
|
|
pub fn extract() -> Command {
|
|
Command::new("extract")
|
|
.about("Extract a Haggis archive")
|
|
.author("Nathan Fisher")
|
|
.visible_alias("ex")
|
|
.args([
|
|
Arg::new("zstd")
|
|
.help("Filter data through zstd")
|
|
.short('z')
|
|
.long("zstd")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("quiet")
|
|
.help("Do not show progress")
|
|
.short('q')
|
|
.long("quiet")
|
|
.visible_alias("silent")
|
|
.action(ArgAction::SetFalse),
|
|
Arg::new("stdin")
|
|
.help("Read archive from stdin")
|
|
.short('i')
|
|
.long("stdin")
|
|
.action(ArgAction::SetTrue)
|
|
.conflicts_with("archive"),
|
|
Arg::new("change")
|
|
.help("Change to another working directory before performing the operation")
|
|
.value_name("directory")
|
|
.visible_alias("directory")
|
|
.visible_alias("root")
|
|
.short('c')
|
|
.long("change")
|
|
.num_args(1),
|
|
Arg::new("uid")
|
|
.help("Set the user ID to the specified number")
|
|
.short('u')
|
|
.long("uid")
|
|
.value_parser(clap::value_parser!(u32))
|
|
.num_args(1),
|
|
Arg::new("gid")
|
|
.help("Set the group ID to the specified number")
|
|
.short('g')
|
|
.long("gid")
|
|
.value_parser(clap::value_parser!(u32))
|
|
.num_args(1),
|
|
Arg::new("archive")
|
|
.num_args(1)
|
|
.required_unless_present("stdin")
|
|
.value_hint(ValueHint::FilePath),
|
|
])
|
|
}
|
|
|
|
pub fn create() -> Command {
|
|
Command::new("create")
|
|
.about("Create a Haggis archive")
|
|
.author("Nathan Fisher")
|
|
.visible_alias("cr")
|
|
.allow_missing_positional(true)
|
|
.args([
|
|
Arg::new("algorithm")
|
|
.help("the checksum algorithm to use")
|
|
.short('a')
|
|
.long("algorithm")
|
|
.value_parser(["md5", "sha1", "sha256", "skip"])
|
|
.default_value("skip")
|
|
.num_args(1)
|
|
.required(false),
|
|
Arg::new("zstd")
|
|
.help("Filter data through zstd")
|
|
.short('z')
|
|
.long("zstd")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("level")
|
|
.help("set the compression level for zstd, from 0-21")
|
|
.short('l')
|
|
.long("level")
|
|
.requires("zstd")
|
|
.num_args(1)
|
|
.default_value("3")
|
|
.value_parser(value_parser!(i32).range(0..=21)),
|
|
Arg::new("quiet")
|
|
.help("Do not show progress")
|
|
.short('q')
|
|
.long("quiet")
|
|
.visible_alias("silent")
|
|
.action(ArgAction::SetFalse),
|
|
Arg::new("stdout")
|
|
.help("Write archive to stdout")
|
|
.short('o')
|
|
.long("stdout")
|
|
.conflicts_with("output")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("uid")
|
|
.help("Set the user ID to the specified number")
|
|
.short('u')
|
|
.long("uid")
|
|
.value_parser(clap::value_parser!(u32))
|
|
.num_args(1),
|
|
Arg::new("gid")
|
|
.help("Set the group ID to the specified number")
|
|
.short('g')
|
|
.long("gid")
|
|
.value_parser(clap::value_parser!(u32))
|
|
.num_args(1),
|
|
Arg::new("output")
|
|
.num_args(1)
|
|
.required_unless_present("stdout")
|
|
.value_hint(ValueHint::FilePath),
|
|
Arg::new("files")
|
|
.num_args(1..)
|
|
.required(true)
|
|
.value_hint(ValueHint::AnyPath),
|
|
])
|
|
}
|
|
|
|
pub fn list() -> Command {
|
|
Command::new("list")
|
|
.about("List files in a Haggis archive")
|
|
.author("Nathan Fisher")
|
|
.visible_alias("ls")
|
|
.args([
|
|
Arg::new("long")
|
|
.help("Display a long listing with file properties and permissions")
|
|
.short('l')
|
|
.long("long")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("files")
|
|
.help("Omit displaying directory entries")
|
|
.short('f')
|
|
.long("files")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("zstd")
|
|
.help("Filter data through zstd")
|
|
.short('z')
|
|
.long("zstd")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("color")
|
|
.help("Colorize output")
|
|
.short('c')
|
|
.long("color")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("nosort")
|
|
.help("Display archive nodes in the order they appear rather than sorted")
|
|
.short('n')
|
|
.long("no-sort")
|
|
.action(ArgAction::SetTrue),
|
|
Arg::new("archive")
|
|
.num_args(1)
|
|
.required(true)
|
|
.value_hint(ValueHint::FilePath),
|
|
])
|
|
}
|