1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
use clap::{Args, Parser, Subcommand};
use parmesan::{EncoderLayout, SimdPath};
use std::path::PathBuf;
#[derive(Parser, Debug)]
#[command(
name = "parmesan",
version = parmesan::DISPLAY_VERSION,
about = "Fast, standalone PAR2 creation tool"
)]
struct Cli {
#[command(subcommand)]
pub(super) command: Command,
}
#[derive(Subcommand, Debug)]
pub(super) enum Command {
/// Create a new PAR2 recovery set for the given files (default action).
Create(CreateArgs),
/// Verify files against an existing PAR2 recovery set.
Verify(VerifyArgs),
/// Repair damaged or missing files using an existing PAR2 recovery set.
Repair(RepairArgs),
}
#[derive(Args, Debug)]
pub(super) struct CreateArgs {
/// Files or directories to protect.
#[arg(required = true)]
pub(super) files: Vec<PathBuf>,
/// Percentage of recovery data to generate.
#[arg(short, long, default_value_t = 10)]
pub(super) recovery_pct: u8,
/// Manual PAR2 slice size, e.g. "1 MiB".
#[arg(short = 's', long)]
pub(super) slice_size: Option<String>,
/// Target number of input slices.
#[arg(short = 'n', long)]
pub(super) slice_count: Option<usize>,
/// Exact number of recovery blocks to generate.
#[arg(long)]
pub(super) recovery_count: Option<usize>,
/// Maximum RAM for recovery buffers, e.g. "1 GiB".
#[arg(short = 'm', long, default_value = "1 GiB")]
pub(super) memory_limit: String,
/// Number of threads for parallel compute.
#[arg(short = 't', long)]
pub(super) threads: Option<usize>,
/// Force a specific SIMD multiplication backend.
#[arg(long, value_enum, default_value_t = SimdPath::Auto)]
pub(super) simd: SimdPath,
/// Recovery-buffer layout. `smart` is the production auto path.
/// `affine512` is the packed AVX-512+GFNI kernel (not auto on SPR yet).
#[arg(long, value_enum, default_value_t = EncoderLayout::Smart)]
pub(super) encoder: EncoderLayout,
/// Output directory for PAR2 files.
#[arg(short, long)]
pub(super) out_dir: Option<PathBuf>,
/// Base name for output PAR2 files (default: first input file's name).
#[arg(short = 'b', long)]
pub(super) base_name: Option<String>,
/// Suppress all progress and geometry output.
#[arg(short = 'q', long)]
pub(super) quiet: bool,
/// Overwrite existing PAR2 files instead of failing.
#[arg(short = 'O', long)]
pub(super) overwrite: bool,
/// Skip generating the index (.par2) file.
#[arg(long)]
pub(super) no_index: bool,
/// Recurse into directories.
#[arg(short = 'R', long)]
pub(super) recurse: bool,
/// Embed a comment in the PAR2 Creator packet (repeatable).
#[arg(short = 'c', long)]
pub(super) comment: Vec<String>,
/// Exponent of the first recovery block (default 0).
#[arg(short = 'e', long, default_value_t = 0)]
pub(super) recovery_offset: usize,
}
#[derive(Args, Debug)]
pub(super) struct VerifyArgs {
/// Path to the PAR2 index file (e.g. "movie.mkv.par2").
pub(super) index: PathBuf,
/// Suppress the per-file report; only the summary line is printed.
#[arg(short = 'q', long)]
pub(super) quiet: bool,
/// Emit a machine-readable JSON report instead of human-readable text.
#[arg(long)]
pub(super) json: bool,
}
#[derive(Args, Debug)]
pub(super) struct RepairArgs {
/// Path to the PAR2 index file (e.g. "movie.mkv.par2").
pub(super) index: PathBuf,
/// Report what would be repaired without writing any files.
#[arg(long)]
pub(super) dry_run: bool,
/// Write repaired files under this directory instead of overwriting
/// damaged/missing originals in place.
#[arg(short, long)]
pub(super) out_dir: Option<PathBuf>,
/// Suppress the per-file report; only the summary line is printed.
#[arg(short = 'q', long)]
pub(super) quiet: bool,
/// Emit a machine-readable JSON report instead of human-readable text.
#[arg(long)]
pub(super) json: bool,
}
const KNOWN_FIRST_ARGS: [&str; 8] = [
"create",
"verify",
"repair",
"help",
"-h",
"--help",
"-V",
"--version",
];
pub(super) fn parse_env() -> Command {
let mut args: Vec<String> = std::env::args().collect();
if let Some(first) = args.get(1) {
if !KNOWN_FIRST_ARGS.contains(&first.as_str()) {
args.insert(1, "create".to_string());
}
}
Cli::parse_from(args).command
}