Skip to content

Commit 7a49423

Browse files
authored
Merge pull request #12 from jubako/man_page
Generate man page for (and from) arx tool.
2 parents 2eec092 + 4d45ca6 commit 7a49423

13 files changed

+127
-36
lines changed

Cargo.lock

+35-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ license = "MIT"
1212
[workspace.dependencies]
1313
jbk = { git = "https://github.com/jubako/jubako.git", package = "jubako", version = "0.2.0" }
1414
clap = { version = "4.4.5", features = ["derive"] }
15+
clap_mangen = "0.2.20"
1516
indicatif = "0.17.7"
1617

1718
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

arx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ license.workspace = true
1414
arx = { path = "../libarx", version = "0.2.0", package="libarx", features=["cmd_utils"] }
1515
jbk.workspace = true
1616
clap.workspace = true
17+
clap_mangen.workspace = true
1718
indicatif.workspace = true
1819
env_logger = "0.10.0"
1920
anyhow = "1.0.75"

arx/src/create.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use std::rc::Rc;
88
use std::sync::Arc;
99

1010
/// Create an archive.
11-
#[derive(clap::Args, Debug)]
11+
#[derive(clap::Parser, Debug)]
1212
pub struct Options {
1313
/// File path of the archive to create.
1414
///

arx/src/dump.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ fn dump_entry(
3939
}
4040

4141
/// Print the content of an entry in the archive.
42-
#[derive(clap::Args, Debug)]
42+
#[derive(clap::Parser, Debug)]
4343
pub struct Options {
4444
/// Archive to read
4545
#[arg(value_parser)]

arx/src/extract.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::io::{BufRead, BufReader};
66
use std::path::PathBuf;
77

88
/// Extract the content of an archive
9-
#[derive(clap::Args, Debug)]
9+
#[derive(clap::Parser, Debug)]
1010
pub struct Options {
1111
/// Archive to read
1212
#[arg(short = 'f', long = "file")]

arx/src/list.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ where
135135
}
136136

137137
/// List the content in an archive.
138-
#[derive(clap::Args, Debug)]
138+
#[derive(clap::Parser, Debug)]
139139
pub struct Options {
140140
/// Archive to read
141141
#[arg(value_parser)]

arx/src/main.rs

+43-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ mod list;
77
mod mount;
88

99
use anyhow::Result;
10-
use clap::Parser;
10+
use clap::{CommandFactory, Parser};
1111
use log::error;
1212
use std::process::ExitCode;
1313

@@ -18,8 +18,24 @@ struct Cli {
1818
#[arg(short, long, action=clap::ArgAction::Count, global=true)]
1919
verbose: u8,
2020

21+
#[arg(
22+
long,
23+
num_args= 0..=1,
24+
default_missing_value = "",
25+
help_heading = "Advanced",
26+
value_parser([
27+
"create",
28+
"list",
29+
"dump",
30+
"extract",
31+
#[cfg(not(windows))]
32+
"mount"
33+
])
34+
)]
35+
generate_man_page: Option<String>,
36+
2137
#[command(subcommand)]
22-
command: Commands,
38+
command: Option<Commands>,
2339
}
2440

2541
#[derive(clap::Subcommand, Debug)]
@@ -64,13 +80,32 @@ fn run() -> Result<()> {
6480
let args = Cli::parse();
6581
configure_log(args.verbose);
6682

83+
if let Some(what) = args.generate_man_page {
84+
let command = match what.as_str() {
85+
"" => Cli::command(),
86+
"create" => create::Options::command(),
87+
"list" => list::Options::command(),
88+
"dump" => dump::Options::command(),
89+
"extract" => extract::Options::command(),
90+
#[cfg(not(windows))]
91+
"mount" => mount::Options::command(),
92+
_ => return Ok(Cli::command().print_help()?),
93+
};
94+
let man = clap_mangen::Man::new(command);
95+
man.render(&mut std::io::stdout())?;
96+
return Ok(());
97+
}
98+
6799
match args.command {
68-
Commands::Create(options) => create::create(options),
69-
Commands::List(options) => Ok(list::list(options)?),
70-
Commands::Dump(options) => Ok(dump::dump(options)?),
71-
Commands::Extract(options) => Ok(extract::extract(options)?),
72-
#[cfg(not(windows))]
73-
Commands::Mount(options) => Ok(mount::mount(options)?),
100+
None => Ok(Cli::command().print_help()?),
101+
Some(c) => match c {
102+
Commands::Create(options) => create::create(options),
103+
Commands::List(options) => Ok(list::list(options)?),
104+
Commands::Dump(options) => Ok(dump::dump(options)?),
105+
Commands::Extract(options) => Ok(extract::extract(options)?),
106+
#[cfg(not(windows))]
107+
Commands::Mount(options) => Ok(mount::mount(options)?),
108+
},
74109
}
75110
}
76111

arx/src/mount.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ impl std::fmt::Display for StatCounter {
8989
}
9090

9191
/// Mount an archive in a directory.
92-
#[derive(clap::Args, Debug)]
92+
#[derive(clap::Parser, Debug)]
9393
pub struct Options {
9494
/// Archive to read
9595
#[arg(value_parser)]

tar2arx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ arx = { path = "../libarx", version = "0.2.0", package="libarx", features=["cmd_
1515
jbk.workspace = true
1616
clap.workspace = true
1717
indicatif.workspace = true
18+
clap_mangen.workspace = true
1819
tar = "0.4.39"
1920
niffler = "2.5.0"

tar2arx/src/main.rs

+18-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use clap::Parser;
1+
use clap::{CommandFactory, Parser};
22

33
use arx::create::Adder;
44
use std::io::Read;
@@ -16,20 +16,29 @@ struct Cli {
1616
#[arg(value_parser)]
1717
tar_file: Option<String>,
1818

19+
#[arg(long, help_heading = "Advanced")]
20+
generate_man_page: bool,
21+
1922
/// Archive name to create
2023
#[arg(
2124
short,
2225
long,
2326
value_parser,
24-
required_unless_present("list_compressions")
27+
required_unless_present_any(["list_compressions", "generate_man_page"])
2528
)]
2629
outfile: Option<PathBuf>,
2730

2831
#[command(flatten)]
2932
concat_mode: Option<arx::cmd_utils::ConcatMode>,
3033

3134
/// Set compression algorithm to use
32-
#[arg(short, long, value_parser=arx::cmd_utils::compression_arg_parser, required=false, default_value = "zstd")]
35+
#[arg(
36+
short,
37+
long,
38+
value_parser=arx::cmd_utils::compression_arg_parser,
39+
required=false,
40+
default_value = "zstd"
41+
)]
3342
compression: jbk::creator::Compression,
3443

3544
/// List available compression algorithms
@@ -257,6 +266,12 @@ fn main() -> jbk::Result<()> {
257266
return Ok(());
258267
}
259268

269+
if args.generate_man_page {
270+
let man = clap_mangen::Man::new(Cli::command());
271+
man.render(&mut std::io::stdout())?;
272+
return Ok(());
273+
}
274+
260275
let mut input_size = None;
261276
let input: Box<dyn Read> = match args.tar_file {
262277
None => Box::new(std::io::stdin()),

zip2arx/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ arx = { path = "../libarx", version = "0.2.0", package="libarx", features=["cmd_
1515
jbk.workspace = true
1616
clap.workspace = true
1717
indicatif.workspace = true
18+
clap_mangen.workspace = true
1819
zip = "0.6.6"
1920
flate2 = "1.0.26"

0 commit comments

Comments
 (0)