probe command
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -945,6 +945,7 @@ dependencies = [
|
||||
"pile-dataset",
|
||||
"pile-toolbox",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"signal-hook",
|
||||
"tokio",
|
||||
"toml",
|
||||
|
||||
@@ -24,3 +24,4 @@ tracing-indicatif = { workspace = true }
|
||||
signal-hook = { workspace = true }
|
||||
anstyle = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
serde_json = { workspace = true }
|
||||
|
||||
@@ -6,6 +6,7 @@ mod check;
|
||||
mod index;
|
||||
mod init;
|
||||
mod lookup;
|
||||
mod probe;
|
||||
|
||||
use crate::GlobalContext;
|
||||
|
||||
@@ -34,6 +35,12 @@ pub enum SubCommand {
|
||||
#[command(flatten)]
|
||||
cmd: lookup::LookupCommand,
|
||||
},
|
||||
|
||||
/// Print all metadata from an item
|
||||
Probe {
|
||||
#[command(flatten)]
|
||||
cmd: probe::ProbeCommand,
|
||||
},
|
||||
}
|
||||
|
||||
impl CliCmdDispatch for SubCommand {
|
||||
@@ -43,6 +50,7 @@ impl CliCmdDispatch for SubCommand {
|
||||
Self::Check { cmd } => cmd.start(ctx),
|
||||
Self::Index { cmd } => cmd.start(ctx),
|
||||
Self::Lookup { cmd } => cmd.start(ctx),
|
||||
Self::Probe { cmd } => cmd.start(ctx),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
42
crates/pile/src/command/probe.rs
Normal file
42
crates/pile/src/command/probe.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use anyhow::{Context, Result};
|
||||
use clap::Args;
|
||||
use pile_config::Label;
|
||||
use pile_dataset::{
|
||||
FileItem,
|
||||
extract::{MetaExtractor, PileValue},
|
||||
};
|
||||
use pile_toolbox::cancelabletask::{CancelFlag, CancelableTaskError};
|
||||
use std::{fmt::Debug, path::PathBuf, rc::Rc};
|
||||
|
||||
use crate::{CliCmd, GlobalContext};
|
||||
|
||||
#[derive(Debug, Args)]
|
||||
pub struct ProbeCommand {
|
||||
/// The file to probe
|
||||
file: PathBuf,
|
||||
}
|
||||
|
||||
impl CliCmd for ProbeCommand {
|
||||
#[expect(clippy::print_stdout)]
|
||||
#[expect(clippy::unwrap_used)]
|
||||
async fn run(
|
||||
self,
|
||||
_ctx: GlobalContext,
|
||||
_flag: CancelFlag,
|
||||
) -> Result<i32, CancelableTaskError<anyhow::Error>> {
|
||||
let item = FileItem {
|
||||
path: self.file.clone(),
|
||||
source_name: Label::new("probe-source").unwrap(),
|
||||
};
|
||||
|
||||
let value = PileValue::Extractor(Rc::new(MetaExtractor::new(&item)));
|
||||
let json = value
|
||||
.to_json()
|
||||
.with_context(|| format!("while extracting {}", self.file.display()))?;
|
||||
|
||||
let json = serde_json::to_string_pretty(&json).unwrap();
|
||||
|
||||
println!("{json}");
|
||||
return Ok(0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user