Skip to content

Commit 90a64ef

Browse files
committed
Support printing flags in check header command.
1 parent ee1e0c2 commit 90a64ef

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

crates/sos/src/commands/check.rs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ pub enum Command {
2424
},
2525
/// Print a vault file header.
2626
Header {
27+
/// Print the header flags.
28+
#[clap(short, long)]
29+
verbose: bool,
30+
2731
/// Vault file path.
2832
file: PathBuf,
2933
},
@@ -48,7 +52,7 @@ pub async fn run(cmd: Command) -> Result<()> {
4852
Command::Vault { file, verbose } => {
4953
verify_vault(file, verbose).await?;
5054
}
51-
Command::Header { file } => header(file).await?,
55+
Command::Header { file, verbose } => header(file, verbose).await?,
5256
Command::Keys { file } => keys(file).await?,
5357
Command::Events { verbose, file } => {
5458
verify_events(file, verbose).await?;
@@ -104,13 +108,41 @@ pub(crate) async fn verify_events(
104108
}
105109

106110
/// Print a vault header.
107-
pub async fn header(vault: PathBuf) -> Result<()> {
111+
pub async fn header(vault: PathBuf, verbose: bool) -> Result<()> {
108112
if !vfs::metadata(&vault).await?.is_file() {
109113
return Err(Error::NotFile(vault));
110114
}
111115

112116
let header = Header::read_header_file(&vault).await?;
113117
println!("{}", header);
118+
if verbose {
119+
let mut details = Vec::new();
120+
details.push(("identity", header.flags().is_identity()));
121+
details.push(("system", header.flags().is_system()));
122+
details.push(("default", header.flags().is_default()));
123+
details.push(("archive", header.flags().is_archive()));
124+
details.push(("device", header.flags().is_device()));
125+
details.push(("contact", header.flags().is_contact()));
126+
details.push(("authenticator", header.flags().is_authenticator()));
127+
details.push(("sync_disabled", header.flags().is_sync_disabled()));
128+
details.push(("shared", header.flags().is_shared()));
129+
130+
let details =
131+
details.into_iter().filter(|(_, v)| *v).collect::<Vec<_>>();
132+
133+
let mut len = 0;
134+
for (k, _) in &details {
135+
len = std::cmp::max(len, k.len());
136+
}
137+
138+
for (name, value) in details {
139+
if value {
140+
let padding = " ".repeat(len - name.len() + 2);
141+
let name = format!("{}{}", padding, name);
142+
println!("{}: {}", name, value);
143+
}
144+
}
145+
}
114146
Ok(())
115147
}
116148

0 commit comments

Comments
 (0)