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::{Parser, Subcommand, ValueEnum};
use std::path::PathBuf;
#[derive(Parser, Debug)]
pub struct DiskCli {
/// Target disk image path
#[arg(long, value_name = "PATH")]
pub disk: PathBuf,
/// Partition selector: index or name
#[arg(long, value_name = "ID|NAME")]
pub part: Option<String>,
#[command(subcommand)]
pub action: DiskAction,
}
#[derive(Subcommand, Debug)]
pub enum DiskAction {
/// Create a blank disk image
Mkimg {
/// Image size (bytes or with K/M/G suffix)
#[arg(long, value_name = "SIZE")]
size: String,
/// Allow overwrite existing file
#[arg(long)]
overwrite: bool,
},
/// Create GPT partition table using parameter.txt
Mkgpt {
/// Parameter file path (e.g. parameter.txt)
#[arg(short = 'f', long, value_name = "PATH")]
file: PathBuf,
/// Alignment size (default 1M)
#[arg(long, default_value = "1M", value_name = "SIZE")]
align: String,
/// Skip confirmation
#[arg(short = 'y', long)]
yes: bool,
},
/// Format filesystem on partition or whole disk
Mkfs {
/// Filesystem type (ext4/fat32)
#[arg(long, value_enum)]
fstype: FsType,
/// Volume label (optional)
#[arg(long, value_name = "LABEL")]
label: Option<String>,
/// Skip confirmation
#[arg(short = 'y', long)]
yes: bool,
},
/// List files in directory
Ls {
/// Directory path inside image
#[arg(value_name = "PATH", default_value = "/")]
path: String,
},
/// Copy files between host and image
Cp {
#[arg(value_name = "SRC")]
src: String,
#[arg(value_name = "DST")]
dst: String,
/// Recursive copy for directories
#[arg(short = 'r', long)]
recursive: bool,
/// Overwrite existing destination
#[arg(short = 'f', long)]
force: bool,
/// Preserve timestamps (best effort)
#[arg(long)]
preserve: bool,
},
/// Move/rename files between host and image
Mv {
#[arg(value_name = "SRC")]
src: String,
#[arg(value_name = "DST")]
dst: String,
/// Overwrite existing destination
#[arg(short = 'f', long)]
force: bool,
},
/// Remove file or directory inside image
Rm {
#[arg(value_name = "PATH")]
path: String,
/// Recursive remove for directories
#[arg(short = 'r', long)]
recursive: bool,
/// Ignore missing target
#[arg(short = 'f', long)]
force: bool,
/// Skip confirmation
#[arg(short = 'y', long)]
yes: bool,
},
/// Create directory inside image
Mkdir {
#[arg(value_name = "PATH")]
path: String,
/// Create parent directories
#[arg(short = 'p', long)]
parents: bool,
},
/// Print file content inside image
Cat {
#[arg(value_name = "PATH")]
path: String,
/// Read only first N bytes
#[arg(long, value_name = "N")]
bytes: Option<usize>,
/// Start offset
#[arg(long, value_name = "N")]
offset: Option<u64>,
},
/// Show disk and partition info
Info {
/// JSON output
#[arg(long)]
json: bool,
},
}
#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum FsType {
Ext4,
Fat32,
}