probe command
Some checks failed
CI / Typos (push) Failing after 16s
CI / Build and test (push) Successful in 1m14s
CI / Clippy (push) Successful in 1m21s

This commit is contained in:
2026-02-22 10:15:17 -08:00
parent 419720dd33
commit 244f682f5f
4 changed files with 49 additions and 0 deletions

1
Cargo.lock generated
View File

@@ -945,6 +945,7 @@ dependencies = [
"pile-dataset", "pile-dataset",
"pile-toolbox", "pile-toolbox",
"serde", "serde",
"serde_json",
"signal-hook", "signal-hook",
"tokio", "tokio",
"toml", "toml",

View File

@@ -24,3 +24,4 @@ tracing-indicatif = { workspace = true }
signal-hook = { workspace = true } signal-hook = { workspace = true }
anstyle = { workspace = true } anstyle = { workspace = true }
toml = { workspace = true } toml = { workspace = true }
serde_json = { workspace = true }

View File

@@ -6,6 +6,7 @@ mod check;
mod index; mod index;
mod init; mod init;
mod lookup; mod lookup;
mod probe;
use crate::GlobalContext; use crate::GlobalContext;
@@ -34,6 +35,12 @@ pub enum SubCommand {
#[command(flatten)] #[command(flatten)]
cmd: lookup::LookupCommand, cmd: lookup::LookupCommand,
}, },
/// Print all metadata from an item
Probe {
#[command(flatten)]
cmd: probe::ProbeCommand,
},
} }
impl CliCmdDispatch for SubCommand { impl CliCmdDispatch for SubCommand {
@@ -43,6 +50,7 @@ impl CliCmdDispatch for SubCommand {
Self::Check { cmd } => cmd.start(ctx), Self::Check { cmd } => cmd.start(ctx),
Self::Index { cmd } => cmd.start(ctx), Self::Index { cmd } => cmd.start(ctx),
Self::Lookup { cmd } => cmd.start(ctx), Self::Lookup { cmd } => cmd.start(ctx),
Self::Probe { cmd } => cmd.start(ctx),
} }
} }
} }

View File

@@ -0,0 +1,39 @@
use anyhow::{Context, Result};
use clap::Args;
use pile_config::Label;
use pile_dataset::{FileItem, PileValue, extract::MetaExtractor};
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);
}
}