use crate::{StandardOptions, SysexitsError};
use asimov_directory::fs::{HandleResolver, ResolveHandle};
use asimov_id::Id;
use asimov_protocol::Node;
use color_print::ceprintln;
use core::error::Error;
pub async fn connect(
id: &Id,
_ticket: &Option<String>,
_flags: &StandardOptions,
) -> Result<(), Box<dyn Error>> {
let node = Node::default().bind().await?.start().await?;
node.online().await;
let mut resolver = HandleResolver::default().await?;
let Some(endpoint) = resolver.resolve_first(id.clone()).await? else {
return Err(SysexitsError::EX_NOUSER.into());
};
let connection = node.connect(endpoint).await?;
ceprintln!("<s,g>✓</> {:?}", connection.hello());
node.terminate().await?;
Ok(())
}