use ipfs_api::{response, IpfsClient};
fn print_recursive(indent: usize, cmd: &response::CommandsResponse) {
let cmd_indent = " ".repeat(indent * 4);
let opt_indent = " ".repeat((indent + 1) * 4);
eprintln!("{}[{}]", cmd_indent, cmd.name);
if cmd.options.len() > 0 {
eprintln!("{}* options:", cmd_indent);
for options in cmd.options.iter() {
eprintln!("{}{}", opt_indent, &options.names[..].join(", "));
}
}
if cmd.subcommands.len() > 0 {
eprintln!("{}- subcommands:", cmd_indent);
for subcommand in cmd.subcommands.iter() {
print_recursive(indent + 1, subcommand);
}
}
}
#[cfg_attr(feature = "with-actix", actix_rt::main)]
#[cfg_attr(feature = "with-hyper", tokio::main)]
async fn main() {
eprintln!("connecting to localhost:5001...");
let client = IpfsClient::default();
match client.commands().await {
Ok(commands) => print_recursive(0, &commands),
Err(e) => eprintln!("error getting commands: {}", e),
}
}