From 9d79e40378be7338a95e8e23cd6e9e10ba15e50d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20Ludue=C3=B1a?= Date: Fri, 6 Feb 2026 18:14:15 -0300 Subject: [PATCH] feat: imports command added --- src/commands/inspect/imports.rs | 41 +++++++++++++++++++++++++++++++++ src/commands/inspect/mod.rs | 5 ++++ 2 files changed, 46 insertions(+) create mode 100644 src/commands/inspect/imports.rs diff --git a/src/commands/inspect/imports.rs b/src/commands/inspect/imports.rs new file mode 100644 index 0000000..0670911 --- /dev/null +++ b/src/commands/inspect/imports.rs @@ -0,0 +1,41 @@ +use clap::Args as ClapArgs; +use miette::{Context as _, IntoDiagnostic as _}; + +use crate::config::RootConfig; +use crate::dirs; + +#[derive(ClapArgs)] +pub struct Args { + /// Path to plutus.json (relative to project root or absolute) + #[arg(long)] + path: String, + + /// Optional alias (same as in `import "…" as alias;`) + #[arg(long)] + alias: Option, +} + +pub fn run(args: Args, _config: &RootConfig) -> miette::Result<()> { + let root = dirs::protocol_root()?; + let loader = tx3_lang::importing::FsLoader::new(root); + + let type_defs = tx3_lang::importing::types_from_plutus( + &args.path, + args.alias.as_deref(), + &loader, + ) + .into_diagnostic() + .with_context(|| format!("loading {}", args.path))?; + + let alias_label = args + .alias + .as_deref() + .map(|a| format!(" (alias: {})", a)) + .unwrap_or_default(); + println!("Types from {}{}:", args.path, alias_label); + for type_def in &type_defs { + println!("{}", type_def.to_tx3_source()); + } + + Ok(()) +} diff --git a/src/commands/inspect/mod.rs b/src/commands/inspect/mod.rs index eaaed0d..df88f1f 100644 --- a/src/commands/inspect/mod.rs +++ b/src/commands/inspect/mod.rs @@ -2,10 +2,14 @@ use clap::{Args as ClapArgs, Subcommand}; use crate::config::RootConfig; +mod imports; mod tir; #[derive(Subcommand)] pub enum Command { + /// Inspect types available from a plutus.json (CIP57) file + Imports(imports::Args), + /// Inspect the intermediate representation of a transaction Tir(tir::Args), } @@ -18,6 +22,7 @@ pub struct Args { pub fn run(args: Args, config: &RootConfig) -> miette::Result<()> { match args.command { + Command::Imports(args) => imports::run(args, config), Command::Tir(args) => tir::run(args, config), } }