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
6 changes: 2 additions & 4 deletions src/commands/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,12 +279,10 @@ pub fn run(_args: Args, config: &Config) -> miette::Result<()> {
std::fs::create_dir_all(&bindgen.output_dir).into_diagnostic()?;

let profile = config
.profiles
.clone()
.devnet()
.unwrap_or_default()
.devnet
.trp
.unwrap_or_else(|| TrpConfig::from(KnownChain::CardanoDevnet));
.unwrap_or_else(|| TrpConfig::from(KnownChain::Devnet));

let job = Job {
name: config.protocol.name.clone(),
Expand Down
6 changes: 1 addition & 5 deletions src/commands/devnet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ pub mod explore;
pub mod invoke;

pub fn ensure_devnet_home(config: &Config) -> miette::Result<PathBuf> {
let profile = config
.profiles
.as_ref()
.map(|profiles| profiles.devnet.clone())
.unwrap_or_default();
let profile = config.devnet().unwrap_or_default();

let profile_hashable = serde_json::to_vec(&profile).into_diagnostic()?;

Expand Down
35 changes: 31 additions & 4 deletions src/commands/init.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};

use crate::config::{BindingsConfig, Config, ProfilesConfig, ProtocolConfig};
use crate::config::{BindingsConfig, Config, KnownChain, ProfileConfig, ProtocolConfig};
use clap::Args as ClapArgs;
use inquire::{Confirm, MultiSelect, Text};
use inquire::{Confirm, MultiSelect, Select, Text};
use miette::IntoDiagnostic;

// Include template files at compile time
Expand Down Expand Up @@ -75,13 +75,40 @@ pub fn run(_args: Args, config: Option<&Config>) -> miette::Result<()> {
.prompt()
.into_diagnostic()?;

let available_chains = KnownChain::all();

let chain = Select::new("Chain:", available_chains.clone())
.prompt()
.unwrap_or_default();

let network = KnownChain::network(&chain);
let network = MultiSelect::new("Network:", network.to_vec())
.prompt()
.unwrap_or_default();

let generate_bindings = MultiSelect::new(
"Generate bindings for:",
vec!["Typescript", "Rust", "Go", "Python"],
)
.prompt()
.unwrap_or_default();

let mut profiles: HashMap<String, ProfileConfig> = HashMap::new();
profiles.insert(KnownChain::Devnet.to_string(), KnownChain::Devnet.into());

if !network.is_empty() {
let profiles_selected = network
.iter()
.map(|n| {
let key = format!("{chain}{n}");
let value = key.parse::<KnownChain>()?.into();
Ok((key, value))
})
.collect::<Result<HashMap<String, ProfileConfig>, miette::Error>>()?;

profiles.extend(profiles_selected)
}

let config = Config {
protocol: ProtocolConfig {
name: protocol_name,
Expand All @@ -97,7 +124,7 @@ pub fn run(_args: Args, config: Option<&Config>) -> miette::Result<()> {
plugin: binding.to_string().to_lowercase(),
})
.collect(),
profiles: ProfilesConfig::default().into(),
profiles: Some(profiles),
registry: None,
};

Expand Down
Loading