Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/commands/inspect/imports.rs
Original file line number Diff line number Diff line change
@@ -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<String>,
}

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(())
}
5 changes: 5 additions & 0 deletions src/commands/inspect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand All @@ -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),
}
}
Loading