use super::connections::ConnectionsModule;
use super::credential_definition::CredentialDefinitionModule;
use super::features::FeaturesModule;
use super::invite::InvitationsModule;
use super::issue_credential::CredentialsModule;
use super::message::MessagesModule;
use super::schema::SchemaModule;
use crate::agent::agents::Agent;
use crate::agent::agents::BaseAgent;
use crate::agent::agents::HttpAgentExtended;
use crate::agent::http_agent::HttpAgent;
use crate::error::{throw, Error};
use crate::utils::config;
use crate::utils::logger::Log;
use async_trait::async_trait;
use clap::{App, ArgMatches};
#[async_trait(?Send)]
pub trait Module<T> {
async fn run(agent: &dyn Agent, config: T);
async fn register<'a>(agent: &dyn Agent, matches: &ArgMatches<'a>);
}
pub async fn register_cli() {
let yaml = load_yaml!("../../cli.yaml");
let matches = App::from_yaml(yaml)
.version(env!("CARGO_PKG_VERSION"))
.author(env!("CARGO_PKG_AUTHORS"))
.about(env!("CARGO_PKG_DESCRIPTION"))
.get_matches();
let mut default_path = std::env::var("HOME").unwrap();
default_path.push_str("/.config/aries-cli/config.ini");
let config_path = matches.value_of("config").unwrap_or(&default_path);
let endpoint_from_config = config::get_value(config_path, "Default", "endpoint");
let api_key_from_config = config::get_value(config_path, "Default", "api-key");
let endpoint = match matches.value_of("endpoint") {
Some(endpoint) => endpoint.to_string(),
None => match endpoint_from_config {
Some(e) => e,
None => throw(Error::NoSuppliedEndpoint),
},
};
let api_key = match matches.value_of("apikey") {
Some(api_key) => Some(api_key.to_string()),
None => api_key_from_config,
};
let should_copy = matches.is_present("copy");
let suppress_output = matches.is_present("suppress-output");
let logger = Log {
should_copy,
suppress_output,
};
let base_agent = BaseAgent { logger };
let agent = HttpAgent {
base_agent,
url: endpoint,
api_key,
};
agent.check_endpoint().await;
ConnectionsModule::register(&agent, &matches).await;
InvitationsModule::register(&agent, &matches).await;
CredentialsModule::register(&agent, &matches).await;
MessagesModule::register(&agent, &matches).await;
FeaturesModule::register(&agent, &matches).await;
SchemaModule::register(&agent, &matches).await;
CredentialDefinitionModule::register(&agent, &matches).await;
}