diff options
Diffstat (limited to 'ipfs-api/examples/get_commands.rs')
-rw-r--r-- | ipfs-api/examples/get_commands.rs | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/ipfs-api/examples/get_commands.rs b/ipfs-api/examples/get_commands.rs index 9b5bcec..4557b70 100644 --- a/ipfs-api/examples/get_commands.rs +++ b/ipfs-api/examples/get_commands.rs @@ -6,25 +6,23 @@ // copied, modified, or distributed except according to those terms. // -use futures::Future; use ipfs_api::{response, IpfsClient}; -use tokio::runtime::current_thread::Runtime; fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { let cmd_indent = " ".repeat(indent * 4); let opt_indent = " ".repeat((indent + 1) * 4); - println!("{}[{}]", cmd_indent, cmd.name); + eprintln!("{}[{}]", cmd_indent, cmd.name); if cmd.options.len() > 0 { - println!("{}* options:", cmd_indent); + eprintln!("{}* options:", cmd_indent); for options in cmd.options.iter() { - println!("{}{}", opt_indent, &options.names[..].join(", ")); + eprintln!("{}{}", opt_indent, &options.names[..].join(", ")); } } if cmd.subcommands.len() > 0 { - println!("{}- subcommands:", cmd_indent); + eprintln!("{}- subcommands:", cmd_indent); for subcommand in cmd.subcommands.iter() { print_recursive(indent + 1, subcommand); } @@ -34,17 +32,14 @@ fn print_recursive(indent: usize, cmd: &response::CommandsResponse) { // Creates an Ipfs client, and gets a list of available commands from the // Ipfs server. // -fn main() { - println!("connecting to localhost:5001..."); +#[tokio::main] +async fn main() { + eprintln!("connecting to localhost:5001..."); let client = IpfsClient::default(); - let req = client - .commands() - .map(|commands| print_recursive(0, &commands)) - .map_err(|e| eprintln!("{}", e)); - - Runtime::new() - .expect("tokio runtime") - .block_on(req) - .expect("successful response"); + + match client.commands().await { + Ok(commands) => print_recursive(0, &commands), + Err(e) => eprintln!("error getting commands: {}", e), + } } |