use crate::application::application::ApplicationConfig;
use crate::method::method_callable::MethodCallable;
use crate::method::method_manager::MethodManager;
use crate::method::method_structure::{Method, MethodArguments, MethodResult};
use crate::method::response_formatter::{JsonResponseFormatter, ResponseFormatter};
pub struct InfoCommand {
application_config: ApplicationConfig
}
impl InfoCommand {
pub fn new(application_config: ApplicationConfig) -> Self {
Self {
application_config
}
}
pub fn self_register(method_manager: &mut Box<dyn MethodManager>, application_config: ApplicationConfig) {
let callable: Box<dyn MethodCallable> = Box::new(Self::new(application_config));
method_manager.add_method(Method {
name: String::from("info"),
description: String::from("Shows information about this application"),
help: String::from("info"),
arguments: vec![],
}, callable);
}
}
impl MethodCallable for InfoCommand {
fn call(&self, _arguments: MethodArguments) -> MethodResult {
let response_message = format!(
"\
{} **version:** {} **by** {}
{}
**Running on** {}**:**{}",
&self.application_config.app_info.name,
&self.application_config.app_info.version,
&self.application_config.app_info.authors,
&self.application_config.app_info.description,
&self.application_config.ip,
&self.application_config.port
);
let mut formatter = JsonResponseFormatter::new();
formatter.add_markdown(&response_message);
formatter.as_result(0)
}
}