From 8c783923b72248edafb983b7cdb015a913c332fa Mon Sep 17 00:00:00 2001 From: Oliver Mueller Date: Fri, 14 Aug 2020 19:44:03 +0200 Subject: [PATCH] Move help to client rename console -> command_processor --- .../src/{console.rs => command_processor.rs} | 35 +- north/src/main.rs | 11 +- north_api/src/proto/api.proto | 25 +- north_api/src/proto/api.rs | 620 +++--------------- north_client/src/main.rs | 101 +-- 5 files changed, 139 insertions(+), 653 deletions(-) rename north/src/{console.rs => command_processor.rs} (90%) diff --git a/north/src/console.rs b/north/src/command_processor.rs similarity index 90% rename from north/src/console.rs rename to north/src/command_processor.rs index da3dd340c..435d6d747 100644 --- a/north/src/console.rs +++ b/north/src/command_processor.rs @@ -21,28 +21,13 @@ use north_api::proto::api; use protobuf::{parse_from_bytes, Message}; use std::time; -/// Helptext displayed on the `help` command. The `dcon` tool parses this text -/// and creates suggestions and completions. Ensure to a correct helptext when -/// adding/removing/changing commands. -const HELP: &str = "\ - help: Display help text\n\ - list: List all loaded images\n\ - ps: List running instances\n\ - shutdown: Stop the north runtime\n\ - settings: Dump north configuration\n\ - start: PATTERN Start containers matching PATTERN e.g 'start hello*'. Omit PATTERN to start all containers\n\ - stop: PATTERN Stop all containers matching PATTERN. Omit PATTERN to stop all running containers\n\ - uninstall: PATTERN: Unmount and remove all containers matching PATTERN\n\ - update: Run update with provided ressources\n\ - versions: Version list of installed applications"; - pub async fn init(tx: &EventTx) -> Result<()> { let rx = serve().await?; let tx = tx.clone(); // Spawn a task that handles lines received on the debug port. task::spawn(async move { while let Ok((line, tx_reply)) = rx.recv().await { - tx.send(Event::Console(line, tx_reply)).await; + tx.send(Event::Command(line, tx_reply)).await; } }); @@ -54,21 +39,15 @@ pub async fn process( command: &[u8], reply: sync::Sender>, ) -> Result<()> { - debug!("process an incomming command: {:#X?}", command); match parse_from_bytes::(&command) { Ok(_) => (), - Err(e) => debug!("could not parse from bytes: {}", e), + Err(e) => debug!("Could not parse from bytes: {}", e), } let command = parse_from_bytes::(&command)?; - debug!("parsing done"); info!("Running command:\'{}\'", command.get_description()); - // let mut commands = command.split_whitespace(); - // if let Some(cmd) = commands.next() { - // let args = commands.collect::>(); let start_timestamp = time::Instant::now(); let response: Result = match command.instruction { - Some(api::Command_oneof_instruction::help_text(_)) => help(), Some(api::Command_oneof_instruction::list_containers(_)) => list(state).await, Some(api::Command_oneof_instruction::running_containers(_)) => ps(state).await, Some(api::Command_oneof_instruction::start_container(ref id)) => { @@ -123,16 +102,6 @@ pub async fn process( Ok(()) } -/// Return the help text -fn help() -> Result { - debug!("sending back help"); - let mut response = api::Response::new(); - let mut help_info = api::HelpInfo::new(); - help_info.set_content(HELP.into()); - response.content = Some(api::Response_oneof_content::help_response(help_info)); - Ok(response) -} - /// List all known containers instances and their state. async fn list(state: &State) -> Result { let mut response = api::Response::new(); diff --git a/north/src/main.rs b/north/src/main.rs index e27e4246e..232921bbb 100644 --- a/north/src/main.rs +++ b/north/src/main.rs @@ -26,7 +26,7 @@ use nix::unistd::{self, chown}; use north_common::manifest::Name; use std::collections::HashMap; -mod console; +mod command_processor; #[cfg(any(target_os = "android", target_os = "linux"))] pub mod linux; mod npk; @@ -46,8 +46,8 @@ pub type EventTx = sync::Sender; #[allow(clippy::large_enum_variant)] #[derive(Debug)] pub enum Event { - /// Incomming console command - Console(Vec, sync::Sender>), + /// Incomming command + Command(Vec, sync::Sender>), /// A instance exited with return code Exit(Name, i32), /// Out of memory event occured @@ -155,7 +155,7 @@ async fn main() -> Result<()> { ); // Initialize console - console::init(&tx).await?; + command_processor::init(&tx).await?; // Autostart flagged containers. Each container with the `autostart` option // set to true in the manifest is started. @@ -174,14 +174,13 @@ async fn main() -> Result<()> { // Enter main loop while let Ok(event) = rx.recv().await { - debug!("received event: {:?}", event); match event { Event::ChildOutput { name, fd, line } => on_child_output(&mut state, &name, fd, &line), // Debug console commands are handled via the main loop in order to get access // to the global state. Therefore the console server receives a tx handle to the // main loop and issues `Event::Console`. Processing of the command takes place // in the console module again but with access to `state`. - Event::Console(cmd, txr) => console::process(&mut state, &cmd, txr).await?, + Event::Command(cmd, txr) => command_processor::process(&mut state, &cmd, txr).await?, // The OOM event is signaled by the cgroup memory monitor if configured in a manifest. // If a out of memory condition occours this is signaled with `Event::Oom` which // carries the id of the container that is oom. diff --git a/north_api/src/proto/api.proto b/north_api/src/proto/api.proto index 43d5af982..83a631a01 100644 --- a/north_api/src/proto/api.proto +++ b/north_api/src/proto/api.proto @@ -34,8 +34,6 @@ message ProcessInfo { optional int64 uptime = 9; // in us } -message HelpInfo { required string content = 1; } - message ProcessList { repeated ProcessInfo processes = 1; } message ContainerList { repeated ContainerInfo containers = 1; } @@ -84,14 +82,13 @@ message Response { oneof content { ContainerList container_list = 1; ProcessList process_list = 2; - HelpInfo help_response = 3; - StartedResponse start_response = 4; - StoppedResponse stop_response = 5; - StatusResponse default_status = 6; - UninstallResponse uninstall_response = 7; - UpdateResponse update_response = 8; - Settings settings_response = 9; - Versions versions_response = 10; + StartedResponse start_response = 3; + StoppedResponse stop_response = 4; + StatusResponse default_status = 5; + UninstallResponse uninstall_response = 6; + UpdateResponse update_response = 7; + Settings settings_response = 8; + Versions versions_response = 9; } optional int64 duration = 20; } @@ -102,7 +99,6 @@ message Command { message Ps {} message ContainerIdentification { optional string regex = 1; } message Update { required string update_dir = 1; } - message Help {} message Shutdown {} message GetSettings {} message GetVersions {} @@ -114,10 +110,9 @@ message Command { ContainerIdentification stop_container = 5; ContainerIdentification uninstall_container = 6; Update update = 7; - Help help_text = 8; - Shutdown shutdown = 9; - GetSettings get_settings = 10; - GetVersions get_versions = 11; + Shutdown shutdown = 8; + GetSettings get_settings = 9; + GetVersions get_versions = 10; } } diff --git a/north_api/src/proto/api.rs b/north_api/src/proto/api.rs index 6e7c176f5..5021219c7 100644 --- a/north_api/src/proto/api.rs +++ b/north_api/src/proto/api.rs @@ -936,178 +936,6 @@ impl ::protobuf::reflect::ProtobufValue for ProcessInfo_Type { } } -#[derive(PartialEq,Clone,Default)] -pub struct HelpInfo { - // message fields - content: ::protobuf::SingularField<::std::string::String>, - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a HelpInfo { - fn default() -> &'a HelpInfo { - ::default_instance() - } -} - -impl HelpInfo { - pub fn new() -> HelpInfo { - ::std::default::Default::default() - } - - // required string content = 1; - - - pub fn get_content(&self) -> &str { - match self.content.as_ref() { - Some(v) => &v, - None => "", - } - } - pub fn clear_content(&mut self) { - self.content.clear(); - } - - pub fn has_content(&self) -> bool { - self.content.is_some() - } - - // Param is passed by value, moved - pub fn set_content(&mut self, v: ::std::string::String) { - self.content = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_content(&mut self) -> &mut ::std::string::String { - if self.content.is_none() { - self.content.set_default(); - } - self.content.as_mut().unwrap() - } - - // Take field - pub fn take_content(&mut self) -> ::std::string::String { - self.content.take().unwrap_or_else(|| ::std::string::String::new()) - } -} - -impl ::protobuf::Message for HelpInfo { - fn is_initialized(&self) -> bool { - if self.content.is_none() { - return false; - } - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - 1 => { - ::protobuf::rt::read_singular_string_into(wire_type, is, &mut self.content)?; - }, - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - if let Some(ref v) = self.content.as_ref() { - my_size += ::protobuf::rt::string_size(1, &v); - } - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - if let Some(ref v) = self.content.as_ref() { - os.write_string(1, &v)?; - } - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> HelpInfo { - HelpInfo::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let mut fields = ::std::vec::Vec::new(); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "content", - |m: &HelpInfo| { &m.content }, - |m: &mut HelpInfo| { &mut m.content }, - )); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "HelpInfo", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static HelpInfo { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(HelpInfo::new) - } -} - -impl ::protobuf::Clear for HelpInfo { - fn clear(&mut self) { - self.content.clear(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for HelpInfo { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for HelpInfo { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - #[derive(PartialEq,Clone,Default)] pub struct ProcessList { // message fields @@ -3366,7 +3194,6 @@ impl<'a> ::std::default::Default for &'a Response { pub enum Response_oneof_content { container_list(ContainerList), process_list(ProcessList), - help_response(HelpInfo), start_response(StartedResponse), stop_response(StoppedResponse), default_status(StatusResponse), @@ -3479,56 +3306,7 @@ impl Response { } } - // optional .north.HelpInfo help_response = 3; - - - pub fn get_help_response(&self) -> &HelpInfo { - match self.content { - ::std::option::Option::Some(Response_oneof_content::help_response(ref v)) => v, - _ => ::default_instance(), - } - } - pub fn clear_help_response(&mut self) { - self.content = ::std::option::Option::None; - } - - pub fn has_help_response(&self) -> bool { - match self.content { - ::std::option::Option::Some(Response_oneof_content::help_response(..)) => true, - _ => false, - } - } - - // Param is passed by value, moved - pub fn set_help_response(&mut self, v: HelpInfo) { - self.content = ::std::option::Option::Some(Response_oneof_content::help_response(v)) - } - - // Mutable pointer to the field. - pub fn mut_help_response(&mut self) -> &mut HelpInfo { - if let ::std::option::Option::Some(Response_oneof_content::help_response(_)) = self.content { - } else { - self.content = ::std::option::Option::Some(Response_oneof_content::help_response(HelpInfo::new())); - } - match self.content { - ::std::option::Option::Some(Response_oneof_content::help_response(ref mut v)) => v, - _ => panic!(), - } - } - - // Take field - pub fn take_help_response(&mut self) -> HelpInfo { - if self.has_help_response() { - match self.content.take() { - ::std::option::Option::Some(Response_oneof_content::help_response(v)) => v, - _ => panic!(), - } - } else { - HelpInfo::new() - } - } - - // optional .north.StartedResponse start_response = 4; + // optional .north.StartedResponse start_response = 3; pub fn get_start_response(&self) -> &StartedResponse { @@ -3577,7 +3355,7 @@ impl Response { } } - // optional .north.StoppedResponse stop_response = 5; + // optional .north.StoppedResponse stop_response = 4; pub fn get_stop_response(&self) -> &StoppedResponse { @@ -3626,7 +3404,7 @@ impl Response { } } - // optional .north.StatusResponse default_status = 6; + // optional .north.StatusResponse default_status = 5; pub fn get_default_status(&self) -> &StatusResponse { @@ -3675,7 +3453,7 @@ impl Response { } } - // optional .north.UninstallResponse uninstall_response = 7; + // optional .north.UninstallResponse uninstall_response = 6; pub fn get_uninstall_response(&self) -> &UninstallResponse { @@ -3724,7 +3502,7 @@ impl Response { } } - // optional .north.UpdateResponse update_response = 8; + // optional .north.UpdateResponse update_response = 7; pub fn get_update_response(&self) -> &UpdateResponse { @@ -3773,7 +3551,7 @@ impl Response { } } - // optional .north.Settings settings_response = 9; + // optional .north.Settings settings_response = 8; pub fn get_settings_response(&self) -> &Settings { @@ -3822,7 +3600,7 @@ impl Response { } } - // optional .north.Versions versions_response = 10; + // optional .north.Versions versions_response = 9; pub fn get_versions_response(&self) -> &Versions { @@ -3903,11 +3681,6 @@ impl ::protobuf::Message for Response { return false; } } - if let Some(Response_oneof_content::help_response(ref v)) = self.content { - if !v.is_initialized() { - return false; - } - } if let Some(Response_oneof_content::start_response(ref v)) = self.content { if !v.is_initialized() { return false; @@ -3963,48 +3736,42 @@ impl ::protobuf::Message for Response { self.content = ::std::option::Option::Some(Response_oneof_content::process_list(is.read_message()?)); }, 3 => { - if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - self.content = ::std::option::Option::Some(Response_oneof_content::help_response(is.read_message()?)); - }, - 4 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::start_response(is.read_message()?)); }, - 5 => { + 4 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::stop_response(is.read_message()?)); }, - 6 => { + 5 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::default_status(is.read_message()?)); }, - 7 => { + 6 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::uninstall_response(is.read_message()?)); }, - 8 => { + 7 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::update_response(is.read_message()?)); }, - 9 => { + 8 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.content = ::std::option::Option::Some(Response_oneof_content::settings_response(is.read_message()?)); }, - 10 => { + 9 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } @@ -4042,10 +3809,6 @@ impl ::protobuf::Message for Response { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }, - &Response_oneof_content::help_response(ref v) => { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }, &Response_oneof_content::start_response(ref v) => { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; @@ -4097,43 +3860,38 @@ impl ::protobuf::Message for Response { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, - &Response_oneof_content::help_response(ref v) => { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }, &Response_oneof_content::start_response(ref v) => { - os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::stop_response(ref v) => { - os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(4, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::default_status(ref v) => { - os.write_tag(6, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(5, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::uninstall_response(ref v) => { - os.write_tag(7, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(6, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::update_response(ref v) => { - os.write_tag(8, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(7, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::settings_response(ref v) => { - os.write_tag(9, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(8, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Response_oneof_content::versions_response(ref v) => { - os.write_tag(10, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(9, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, @@ -4187,11 +3945,6 @@ impl ::protobuf::Message for Response { Response::has_process_list, Response::get_process_list, )); - fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, HelpInfo>( - "help_response", - Response::has_help_response, - Response::get_help_response, - )); fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, StartedResponse>( "start_response", Response::has_start_response, @@ -4257,7 +4010,6 @@ impl ::protobuf::Clear for Response { self.content = ::std::option::Option::None; self.content = ::std::option::Option::None; self.content = ::std::option::Option::None; - self.content = ::std::option::Option::None; self.duration = ::std::option::Option::None; self.unknown_fields.clear(); } @@ -4300,7 +4052,6 @@ pub enum Command_oneof_instruction { stop_container(Command_ContainerIdentification), uninstall_container(Command_ContainerIdentification), update(Command_Update), - help_text(Command_Help), shutdown(Command_Shutdown), get_settings(Command_GetSettings), get_versions(Command_GetVersions), @@ -4641,56 +4392,7 @@ impl Command { } } - // optional .north.Command.Help help_text = 8; - - - pub fn get_help_text(&self) -> &Command_Help { - match self.instruction { - ::std::option::Option::Some(Command_oneof_instruction::help_text(ref v)) => v, - _ => ::default_instance(), - } - } - pub fn clear_help_text(&mut self) { - self.instruction = ::std::option::Option::None; - } - - pub fn has_help_text(&self) -> bool { - match self.instruction { - ::std::option::Option::Some(Command_oneof_instruction::help_text(..)) => true, - _ => false, - } - } - - // Param is passed by value, moved - pub fn set_help_text(&mut self, v: Command_Help) { - self.instruction = ::std::option::Option::Some(Command_oneof_instruction::help_text(v)) - } - - // Mutable pointer to the field. - pub fn mut_help_text(&mut self) -> &mut Command_Help { - if let ::std::option::Option::Some(Command_oneof_instruction::help_text(_)) = self.instruction { - } else { - self.instruction = ::std::option::Option::Some(Command_oneof_instruction::help_text(Command_Help::new())); - } - match self.instruction { - ::std::option::Option::Some(Command_oneof_instruction::help_text(ref mut v)) => v, - _ => panic!(), - } - } - - // Take field - pub fn take_help_text(&mut self) -> Command_Help { - if self.has_help_text() { - match self.instruction.take() { - ::std::option::Option::Some(Command_oneof_instruction::help_text(v)) => v, - _ => panic!(), - } - } else { - Command_Help::new() - } - } - - // optional .north.Command.Shutdown shutdown = 9; + // optional .north.Command.Shutdown shutdown = 8; pub fn get_shutdown(&self) -> &Command_Shutdown { @@ -4739,7 +4441,7 @@ impl Command { } } - // optional .north.Command.GetSettings get_settings = 10; + // optional .north.Command.GetSettings get_settings = 9; pub fn get_get_settings(&self) -> &Command_GetSettings { @@ -4788,7 +4490,7 @@ impl Command { } } - // optional .north.Command.GetVersions get_versions = 11; + // optional .north.Command.GetVersions get_versions = 10; pub fn get_get_versions(&self) -> &Command_GetVersions { @@ -4870,11 +4572,6 @@ impl ::protobuf::Message for Command { return false; } } - if let Some(Command_oneof_instruction::help_text(ref v)) = self.instruction { - if !v.is_initialized() { - return false; - } - } if let Some(Command_oneof_instruction::shutdown(ref v)) = self.instruction { if !v.is_initialized() { return false; @@ -4937,24 +4634,18 @@ impl ::protobuf::Message for Command { self.instruction = ::std::option::Option::Some(Command_oneof_instruction::update(is.read_message()?)); }, 8 => { - if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - self.instruction = ::std::option::Option::Some(Command_oneof_instruction::help_text(is.read_message()?)); - }, - 9 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.instruction = ::std::option::Option::Some(Command_oneof_instruction::shutdown(is.read_message()?)); }, - 10 => { + 9 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } self.instruction = ::std::option::Option::Some(Command_oneof_instruction::get_settings(is.read_message()?)); }, - 11 => { + 10 => { if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); } @@ -5001,10 +4692,6 @@ impl ::protobuf::Message for Command { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; }, - &Command_oneof_instruction::help_text(ref v) => { - let len = v.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }, &Command_oneof_instruction::shutdown(ref v) => { let len = v.compute_size(); my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; @@ -5060,23 +4747,18 @@ impl ::protobuf::Message for Command { os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, - &Command_oneof_instruction::help_text(ref v) => { - os.write_tag(8, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }, &Command_oneof_instruction::shutdown(ref v) => { - os.write_tag(9, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(8, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Command_oneof_instruction::get_settings(ref v) => { - os.write_tag(10, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(9, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, &Command_oneof_instruction::get_versions(ref v) => { - os.write_tag(11, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_tag(10, ::protobuf::wire_format::WireTypeLengthDelimited)?; os.write_raw_varint32(v.get_cached_size())?; v.write_to_with_cached_sizes(os)?; }, @@ -5155,11 +4837,6 @@ impl ::protobuf::Message for Command { Command::has_update, Command::get_update, )); - fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, Command_Help>( - "help_text", - Command::has_help_text, - Command::get_help_text, - )); fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, Command_Shutdown>( "shutdown", Command::has_shutdown, @@ -5201,7 +4878,6 @@ impl ::protobuf::Clear for Command { self.instruction = ::std::option::Option::None; self.instruction = ::std::option::Option::None; self.instruction = ::std::option::Option::None; - self.instruction = ::std::option::Option::None; self.unknown_fields.clear(); } } @@ -5791,122 +5467,6 @@ impl ::protobuf::reflect::ProtobufValue for Command_Update { } } -#[derive(PartialEq,Clone,Default)] -pub struct Command_Help { - // special fields - pub unknown_fields: ::protobuf::UnknownFields, - pub cached_size: ::protobuf::CachedSize, -} - -impl<'a> ::std::default::Default for &'a Command_Help { - fn default() -> &'a Command_Help { - ::default_instance() - } -} - -impl Command_Help { - pub fn new() -> Command_Help { - ::std::default::Default::default() - } -} - -impl ::protobuf::Message for Command_Help { - fn is_initialized(&self) -> bool { - true - } - - fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream<'_>) -> ::protobuf::ProtobufResult<()> { - while !is.eof()? { - let (field_number, wire_type) = is.read_tag_unpack()?; - match field_number { - _ => { - ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; - }, - }; - } - ::std::result::Result::Ok(()) - } - - // Compute sizes of nested messages - #[allow(unused_variables)] - fn compute_size(&self) -> u32 { - let mut my_size = 0; - my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); - self.cached_size.set(my_size); - my_size - } - - fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream<'_>) -> ::protobuf::ProtobufResult<()> { - os.write_unknown_fields(self.get_unknown_fields())?; - ::std::result::Result::Ok(()) - } - - fn get_cached_size(&self) -> u32 { - self.cached_size.get() - } - - fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { - &self.unknown_fields - } - - fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { - &mut self.unknown_fields - } - - fn as_any(&self) -> &dyn (::std::any::Any) { - self as &dyn (::std::any::Any) - } - fn as_any_mut(&mut self) -> &mut dyn (::std::any::Any) { - self as &mut dyn (::std::any::Any) - } - fn into_any(self: ::std::boxed::Box) -> ::std::boxed::Box { - self - } - - fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { - Self::descriptor_static() - } - - fn new() -> Command_Help { - Command_Help::new() - } - - fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { - static descriptor: ::protobuf::rt::LazyV2<::protobuf::reflect::MessageDescriptor> = ::protobuf::rt::LazyV2::INIT; - descriptor.get(|| { - let fields = ::std::vec::Vec::new(); - ::protobuf::reflect::MessageDescriptor::new_pb_name::( - "Command.Help", - fields, - file_descriptor_proto() - ) - }) - } - - fn default_instance() -> &'static Command_Help { - static instance: ::protobuf::rt::LazyV2 = ::protobuf::rt::LazyV2::INIT; - instance.get(Command_Help::new) - } -} - -impl ::protobuf::Clear for Command_Help { - fn clear(&mut self) { - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Command_Help { - fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Command_Help { - fn as_ref(&self) -> ::protobuf::reflect::ReflectValueRef { - ::protobuf::reflect::ReflectValueRef::Message(self) - } -} - #[derive(PartialEq,Clone,Default)] pub struct Command_Shutdown { // special fields @@ -6877,70 +6437,66 @@ static file_descriptor_proto_data: &'static [u8] = b"\ \x01(\x04R\x06sharedB\0\x12\x14\n\x04text\x18\x07\x20\x01(\x04R\x04textB\ \0\x12\x14\n\x04data\x18\x08\x20\x01(\x04R\x04dataB\0\x12\x18\n\x06uptim\ e\x18\t\x20\x01(\x03R\x06uptimeB\0\"+\n\x04Type\x12\x07\n\x03APP\x10\0\ - \x12\x0c\n\x08RESOURCE\x10\x01\x12\n\n\x06SYSTEM\x10\x02\x1a\0:\0\"(\n\ - \x08HelpInfo\x12\x1a\n\x07content\x18\x01\x20\x02(\tR\x07contentB\0:\0\"\ - C\n\x0bProcessList\x122\n\tprocesses\x18\x01\x20\x03(\x0b2\x12.north.Pro\ - cessInfoR\tprocessesB\0:\0\"I\n\rContainerList\x126\n\ncontainers\x18\ - \x01\x20\x03(\x0b2\x14.north.ContainerInfoR\ncontainersB\0:\0\"b\n\x0eSt\ - atusResponse\x12!\n\x0bstatus_info\x18\x01\x20\x01(\tR\nstatusInfoB\0\ - \x12+\n\x10command_response\x18\x02\x20\x01(\tR\x0fcommandResponseB\0:\0\ - \"\x8e\x01\n\x11UninstallResponse\x12:\n\x06status\x18\x01\x20\x03(\x0b2\ - \x20.north.UninstallResponse.OutcomeR\x06statusB\0\x1a;\n\x07Outcome\x12\ - \x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x18\n\x06result\x18\ - \x02\x20\x01(\tR\x06resultB\0:\0:\0\"\xc3\x01\n\x0eUpdateResponse\x12C\n\ - \x0bupdate_list\x18\x01\x20\x03(\x0b2\x20.north.UpdateResponse.UpdateInf\ - oR\nupdateListB\0\x1aj\n\nUpdateInfo\x12\x14\n\x04name\x18\x01\x20\x01(\ - \tR\x04nameB\0\x12!\n\x0bold_version\x18\x02\x20\x01(\tR\noldVersionB\0\ - \x12!\n\x0bnew_version\x18\x03\x20\x01(\tR\nnewVersionB\0:\0:\0\"\xc3\ - \x01\n\x0fStartedResponse\x12G\n\x0cstartup_list\x18\x01\x20\x03(\x0b2\"\ - .north.StartedResponse.StartupInfoR\x0bstartupListB\0\x1ae\n\x0bStartupI\ - nfo\x12\x10\n\x02id\x18\x01\x20\x02(\tR\x02idB\0\x12\x1a\n\x07success\ - \x18\x02\x20\x01(\tR\x07successB\0\x12&\n\x0eduration_in_ns\x18\x03\x20\ - \x01(\x04R\x0cdurationInNsB\0:\0:\0\"\xb7\x01\n\x0fStoppedResponse\x12>\ - \n\tstop_list\x18\x01\x20\x03(\x0b2\x1f.north.StoppedResponse.StopInfoR\ - \x08stopListB\0\x1ab\n\x08StopInfo\x12\x10\n\x02id\x18\x01\x20\x02(\tR\ - \x02idB\0\x12\x1a\n\x07success\x18\x02\x20\x01(\tR\x07successB\0\x12&\n\ - \x0eduration_in_ns\x18\x03\x20\x01(\x04R\x0cdurationInNsB\0:\0:\0\"\xc6\ - \x05\n\x08Response\x12?\n\x0econtainer_list\x18\x01\x20\x01(\x0b2\x14.no\ - rth.ContainerListH\0R\rcontainerListB\0\x129\n\x0cprocess_list\x18\x02\ - \x20\x01(\x0b2\x12.north.ProcessListH\0R\x0bprocessListB\0\x128\n\rhelp_\ - response\x18\x03\x20\x01(\x0b2\x0f.north.HelpInfoH\0R\x0chelpResponseB\0\ - \x12A\n\x0estart_response\x18\x04\x20\x01(\x0b2\x16.north.StartedRespons\ - eH\0R\rstartResponseB\0\x12?\n\rstop_response\x18\x05\x20\x01(\x0b2\x16.\ - north.StoppedResponseH\0R\x0cstopResponseB\0\x12@\n\x0edefault_status\ - \x18\x06\x20\x01(\x0b2\x15.north.StatusResponseH\0R\rdefaultStatusB\0\ - \x12K\n\x12uninstall_response\x18\x07\x20\x01(\x0b2\x18.north.UninstallR\ - esponseH\0R\x11uninstallResponseB\0\x12B\n\x0fupdate_response\x18\x08\ - \x20\x01(\x0b2\x15.north.UpdateResponseH\0R\x0eupdateResponseB\0\x12@\n\ - \x11settings_response\x18\t\x20\x01(\x0b2\x0f.north.SettingsH\0R\x10sett\ - ingsResponseB\0\x12@\n\x11versions_response\x18\n\x20\x01(\x0b2\x0f.nort\ - h.VersionsH\0R\x10versionsResponseB\0\x12\x1c\n\x08duration\x18\x14\x20\ - \x01(\x03R\x08durationB\0B\t\n\x07content:\0\"\xa1\x07\n\x07Command\x12\ - \"\n\x0bdescription\x18\x01\x20\x01(\tR\x0bdescriptionB\0\x12@\n\x0flist\ - _containers\x18\x02\x20\x01(\x0b2\x13.north.Command.ListH\0R\x0elistCont\ - ainersB\0\x12D\n\x12running_containers\x18\x03\x20\x01(\x0b2\x11.north.C\ - ommand.PsH\0R\x11runningContainersB\0\x12S\n\x0fstart_container\x18\x04\ - \x20\x01(\x0b2&.north.Command.ContainerIdentificationH\0R\x0estartContai\ - nerB\0\x12Q\n\x0estop_container\x18\x05\x20\x01(\x0b2&.north.Command.Con\ - tainerIdentificationH\0R\rstopContainerB\0\x12[\n\x13uninstall_container\ - \x18\x06\x20\x01(\x0b2&.north.Command.ContainerIdentificationH\0R\x12uni\ - nstallContainerB\0\x121\n\x06update\x18\x07\x20\x01(\x0b2\x15.north.Comm\ - and.UpdateH\0R\x06updateB\0\x124\n\thelp_text\x18\x08\x20\x01(\x0b2\x13.\ - north.Command.HelpH\0R\x08helpTextB\0\x127\n\x08shutdown\x18\t\x20\x01(\ - \x0b2\x17.north.Command.ShutdownH\0R\x08shutdownB\0\x12A\n\x0cget_settin\ - gs\x18\n\x20\x01(\x0b2\x1a.north.Command.GetSettingsH\0R\x0bgetSettingsB\ - \0\x12A\n\x0cget_versions\x18\x0b\x20\x01(\x0b2\x1a.north.Command.GetVer\ - sionsH\0R\x0bgetVersionsB\0\x1a\x08\n\x04List:\0\x1a\x06\n\x02Ps:\0\x1a3\ - \n\x17ContainerIdentification\x12\x16\n\x05regex\x18\x01\x20\x01(\tR\x05\ - regexB\0:\0\x1a+\n\x06Update\x12\x1f\n\nupdate_dir\x18\x01\x20\x02(\tR\t\ - updateDirB\0:\0\x1a\x08\n\x04Help:\0\x1a\x0c\n\x08Shutdown:\0\x1a\x0f\n\ - \x0bGetSettings:\0\x1a\x0f\n\x0bGetVersions:\0B\r\n\x0binstruction:\0\"0\ - \n\x08Settings\x12\"\n\x0bdescription\x18\x01\x20\x01(\tR\x0bdescription\ - B\0:\0\"\xaa\x01\n\x08Versions\x123\n\x05infos\x18\x01\x20\x03(\x0b2\x1b\ - .north.Versions.VersionInfoR\x05infosB\0\x1ag\n\x0bVersionInfo\x12\x14\n\ - \x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x1a\n\x07version\x18\x02\x20\ - \x01(\tR\x07versionB\0\x12$\n\x0carchitecture\x18\x03\x20\x01(\tR\x0carc\ - hitectureB\0:\0:\0B\0b\x06proto2\ + \x12\x0c\n\x08RESOURCE\x10\x01\x12\n\n\x06SYSTEM\x10\x02\x1a\0:\0\"C\n\ + \x0bProcessList\x122\n\tprocesses\x18\x01\x20\x03(\x0b2\x12.north.Proces\ + sInfoR\tprocessesB\0:\0\"I\n\rContainerList\x126\n\ncontainers\x18\x01\ + \x20\x03(\x0b2\x14.north.ContainerInfoR\ncontainersB\0:\0\"b\n\x0eStatus\ + Response\x12!\n\x0bstatus_info\x18\x01\x20\x01(\tR\nstatusInfoB\0\x12+\n\ + \x10command_response\x18\x02\x20\x01(\tR\x0fcommandResponseB\0:\0\"\x8e\ + \x01\n\x11UninstallResponse\x12:\n\x06status\x18\x01\x20\x03(\x0b2\x20.n\ + orth.UninstallResponse.OutcomeR\x06statusB\0\x1a;\n\x07Outcome\x12\x14\n\ + \x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\x18\n\x06result\x18\x02\x20\ + \x01(\tR\x06resultB\0:\0:\0\"\xc3\x01\n\x0eUpdateResponse\x12C\n\x0bupda\ + te_list\x18\x01\x20\x03(\x0b2\x20.north.UpdateResponse.UpdateInfoR\nupda\ + teListB\0\x1aj\n\nUpdateInfo\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04na\ + meB\0\x12!\n\x0bold_version\x18\x02\x20\x01(\tR\noldVersionB\0\x12!\n\ + \x0bnew_version\x18\x03\x20\x01(\tR\nnewVersionB\0:\0:\0\"\xc3\x01\n\x0f\ + StartedResponse\x12G\n\x0cstartup_list\x18\x01\x20\x03(\x0b2\".north.Sta\ + rtedResponse.StartupInfoR\x0bstartupListB\0\x1ae\n\x0bStartupInfo\x12\ + \x10\n\x02id\x18\x01\x20\x02(\tR\x02idB\0\x12\x1a\n\x07success\x18\x02\ + \x20\x01(\tR\x07successB\0\x12&\n\x0eduration_in_ns\x18\x03\x20\x01(\x04\ + R\x0cdurationInNsB\0:\0:\0\"\xb7\x01\n\x0fStoppedResponse\x12>\n\tstop_l\ + ist\x18\x01\x20\x03(\x0b2\x1f.north.StoppedResponse.StopInfoR\x08stopLis\ + tB\0\x1ab\n\x08StopInfo\x12\x10\n\x02id\x18\x01\x20\x02(\tR\x02idB\0\x12\ + \x1a\n\x07success\x18\x02\x20\x01(\tR\x07successB\0\x12&\n\x0eduration_i\ + n_ns\x18\x03\x20\x01(\x04R\x0cdurationInNsB\0:\0:\0\"\x8c\x05\n\x08Respo\ + nse\x12?\n\x0econtainer_list\x18\x01\x20\x01(\x0b2\x14.north.ContainerLi\ + stH\0R\rcontainerListB\0\x129\n\x0cprocess_list\x18\x02\x20\x01(\x0b2\ + \x12.north.ProcessListH\0R\x0bprocessListB\0\x12A\n\x0estart_response\ + \x18\x03\x20\x01(\x0b2\x16.north.StartedResponseH\0R\rstartResponseB\0\ + \x12?\n\rstop_response\x18\x04\x20\x01(\x0b2\x16.north.StoppedResponseH\ + \0R\x0cstopResponseB\0\x12@\n\x0edefault_status\x18\x05\x20\x01(\x0b2\ + \x15.north.StatusResponseH\0R\rdefaultStatusB\0\x12K\n\x12uninstall_resp\ + onse\x18\x06\x20\x01(\x0b2\x18.north.UninstallResponseH\0R\x11uninstallR\ + esponseB\0\x12B\n\x0fupdate_response\x18\x07\x20\x01(\x0b2\x15.north.Upd\ + ateResponseH\0R\x0eupdateResponseB\0\x12@\n\x11settings_response\x18\x08\ + \x20\x01(\x0b2\x0f.north.SettingsH\0R\x10settingsResponseB\0\x12@\n\x11v\ + ersions_response\x18\t\x20\x01(\x0b2\x0f.north.VersionsH\0R\x10versionsR\ + esponseB\0\x12\x1c\n\x08duration\x18\x14\x20\x01(\x03R\x08durationB\0B\t\ + \n\x07content:\0\"\xe1\x06\n\x07Command\x12\"\n\x0bdescription\x18\x01\ + \x20\x01(\tR\x0bdescriptionB\0\x12@\n\x0flist_containers\x18\x02\x20\x01\ + (\x0b2\x13.north.Command.ListH\0R\x0elistContainersB\0\x12D\n\x12running\ + _containers\x18\x03\x20\x01(\x0b2\x11.north.Command.PsH\0R\x11runningCon\ + tainersB\0\x12S\n\x0fstart_container\x18\x04\x20\x01(\x0b2&.north.Comman\ + d.ContainerIdentificationH\0R\x0estartContainerB\0\x12Q\n\x0estop_contai\ + ner\x18\x05\x20\x01(\x0b2&.north.Command.ContainerIdentificationH\0R\rst\ + opContainerB\0\x12[\n\x13uninstall_container\x18\x06\x20\x01(\x0b2&.nort\ + h.Command.ContainerIdentificationH\0R\x12uninstallContainerB\0\x121\n\ + \x06update\x18\x07\x20\x01(\x0b2\x15.north.Command.UpdateH\0R\x06updateB\ + \0\x127\n\x08shutdown\x18\x08\x20\x01(\x0b2\x17.north.Command.ShutdownH\ + \0R\x08shutdownB\0\x12A\n\x0cget_settings\x18\t\x20\x01(\x0b2\x1a.north.\ + Command.GetSettingsH\0R\x0bgetSettingsB\0\x12A\n\x0cget_versions\x18\n\ + \x20\x01(\x0b2\x1a.north.Command.GetVersionsH\0R\x0bgetVersionsB\0\x1a\ + \x08\n\x04List:\0\x1a\x06\n\x02Ps:\0\x1a3\n\x17ContainerIdentification\ + \x12\x16\n\x05regex\x18\x01\x20\x01(\tR\x05regexB\0:\0\x1a+\n\x06Update\ + \x12\x1f\n\nupdate_dir\x18\x01\x20\x02(\tR\tupdateDirB\0:\0\x1a\x0c\n\ + \x08Shutdown:\0\x1a\x0f\n\x0bGetSettings:\0\x1a\x0f\n\x0bGetVersions:\0B\ + \r\n\x0binstruction:\0\"0\n\x08Settings\x12\"\n\x0bdescription\x18\x01\ + \x20\x01(\tR\x0bdescriptionB\0:\0\"\xaa\x01\n\x08Versions\x123\n\x05info\ + s\x18\x01\x20\x03(\x0b2\x1b.north.Versions.VersionInfoR\x05infosB\0\x1ag\ + \n\x0bVersionInfo\x12\x14\n\x04name\x18\x01\x20\x01(\tR\x04nameB\0\x12\ + \x1a\n\x07version\x18\x02\x20\x01(\tR\x07versionB\0\x12$\n\x0carchitectu\ + re\x18\x03\x20\x01(\tR\x0carchitectureB\0:\0:\0B\0b\x06proto2\ "; static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT; diff --git a/north_client/src/main.rs b/north_client/src/main.rs index 5511ef00a..5934d6b6e 100644 --- a/north_client/src/main.rs +++ b/north_client/src/main.rs @@ -20,7 +20,7 @@ use clap::{value_t, App, AppSettings, Arg}; use itertools::Itertools; use log::{debug, info, warn}; use north_api::proto::api; -use prettytable::{cell, format, row, Table}; +use prettytable::{format, Table}; use protobuf::{parse_from_bytes, Message}; use rustyline::{ completion::{Completer, FilenameCompleter, Pair}, @@ -33,6 +33,7 @@ use rustyline::{ use rustyline_derive::Validator; use std::{ borrow::Cow::{self, Owned}, + collections::HashMap, collections::HashSet, env, fs, io::{Read, Write}, @@ -44,20 +45,24 @@ use std::{ static PROMPT: &str = ">> "; const BUFFER_SIZE: usize = 64 * 1024; lazy_static! { - static ref COMMAND_LIST: Vec<&'static str> = { - let mut v = Vec::new(); - v.push("help"); - v.push("list"); - v.push("ps"); - v.push("start"); - v.push("stop"); - v.push("uninstall"); - v.push("update"); - v.push("settings"); - v.push("versions"); - v.push("shutdown"); - v + static ref COMMANDS: HashMap<&'static str, &'static str> = { + let mut m = HashMap::new(); + m.insert("help", "Display help text"); + m.insert("list", "List all loaded images"); + m.insert("ps", "List running instances"); + m.insert("shutdown", "Stop the north runtime"); + m.insert("settings", "Dump north configuration"); + m.insert("start", "PATTERN Start containers matching PATTERN e.g 'start hello*'. Omit PATTERN to start all containers"); + m.insert("stop", "PATTERN Stop all containers matching PATTERN. Omit PATTERN to stop all running containers"); + m.insert( + "uninstall", + "PATTERN: Unmount and remove all containers matching PATTERN", + ); + m.insert("update", "Run update with provided ressources"); + m.insert("versions", "Version list of installed applications"); + m }; + static ref COMMAND_LIST: Vec<&'static str> = COMMANDS.keys().copied().collect(); } fn start_command(regex_str: Option<&str>) -> api::Command { @@ -88,17 +93,8 @@ fn uninstall_command(regex_str: Option<&str>) -> api::Command { if let Some(r) = regex_str { id_cmd.set_regex(r.to_string()); } - cmd.instruction = Some(api::Command_oneof_instruction::stop_container(id_cmd)); - cmd.set_description(String::from("update")); - cmd -} - -fn help_command() -> api::Command { - let mut cmd = api::Command::new(); - cmd.instruction = Some(api::Command_oneof_instruction::help_text( - api::Command_Help::new(), - )); - cmd.set_description(String::from("help")); + cmd.instruction = Some(api::Command_oneof_instruction::uninstall_container(id_cmd)); + cmd.set_description(String::from("uninstall")); cmd } @@ -218,13 +214,13 @@ fn cli() -> Opt { } #[derive(Validator)] -struct DConHelper { +struct NstarHelper { file_name: FilenameCompleter, brackets_highliter: MatchingBracketHighlighter, history_hinter: HistoryHinter, } -impl Completer for DConHelper { +impl Completer for NstarHelper { type Candidate = Pair; fn complete( @@ -237,7 +233,7 @@ impl Completer for DConHelper { } } -impl Hinter for DConHelper { +impl Hinter for NstarHelper { fn hint(&self, line: &str, pos: usize, ctx: &rustyline::Context<'_>) -> Option { let hint = command_hint(line, pos, ctx); if hint.is_some() { @@ -248,7 +244,7 @@ impl Hinter for DConHelper { } } -impl Highlighter for DConHelper { +impl Highlighter for NstarHelper { fn highlight_prompt<'b, 's: 'b, 'p: 'b>( &'s self, prompt: &'p str, @@ -274,7 +270,7 @@ impl Highlighter for DConHelper { } } -impl Helper for DConHelper {} +impl Helper for NstarHelper {} fn command_hint(line: &str, pos: usize, _ctx: &rustyline::Context<'_>) -> Option { did_you_mean(&line, COMMAND_LIST.iter()).and_then(|s| { @@ -338,9 +334,6 @@ fn run(addr: &str, cmd: &api::Command) -> Result { Some(api::Response_oneof_content::process_list(info)) => { reply.push_str(&format_ps_reply(info)?); } - Some(api::Response_oneof_content::help_response(help)) => { - reply.push_str(&format_help(help)?); - } Some(api::Response_oneof_content::uninstall_response(resp)) => { reply.push_str(&format_uninstall(resp)?); } @@ -372,37 +365,6 @@ fn run(addr: &str, cmd: &api::Command) -> Result { } } -fn format_help(help_response: api::HelpInfo) -> Result { - let mut table = Table::new(); - let format = format::FormatBuilder::new() - .column_separator('|') - .separators(&[], format::LineSeparator::new('-', '+', '+', '+')) - .padding(1, 1) - .build(); - table.set_format(format); - table.set_titles(row!["Command", "Subcommands", "Help"]); - - let mut last_cmd = ""; - for l in help_response - .get_content() - .lines() - .filter(|n| !n.is_empty()) - { - let mut split = l.split_terminator(':').map(str::trim); - if let Some(e) = split.next() { - let mut cmd = e.split(' ').map(str::trim); - let help = split.map(str::trim).collect::>().join(" "); - if let Some(e) = cmd.next() { - let args = cmd.collect::>().join(" "); - let c = if last_cmd == e { "" } else { e }; - last_cmd = e; - table.add_row(row![bFg->c, Fc->args, help]); - } - } - } - Ok(format!("{}", table)) -} - fn format_ps_reply(process_list: api::ProcessList) -> Result { use pretty_bytes::converter::convert; let headings = vec![[ @@ -617,7 +579,7 @@ fn format_versions(version_response: api::Versions) -> Result { fn run_cmd( cmd_str: &str, opt: &Opt, - editor: &mut Editor, + editor: &mut Editor, commands_entered: Option<&mut HashSet>, ) -> Result<()> { let cmd_str = cmd_str.trim(); @@ -630,7 +592,12 @@ fn run_cmd( return Ok(()); } if cmd_str == "help" || cmd_str == "?" { - command = Some(help_command()); + let mut result = vec![]; + for (cmd, explanation) in COMMANDS.iter() { + result.push(vec![cmd.to_string(), explanation.to_string()]); + } + println!("{}", to_table(result)?); + return Ok(()); } else if stripped_cmd.starts_with("list") { command = Some(list_command()); } else if stripped_cmd.starts_with("ps") { @@ -720,7 +687,7 @@ fn main() -> Result<()> { .output_stream(OutputStreamType::Stdout) .max_history_size(1000) .build(); - let h = DConHelper { + let h = NstarHelper { file_name: FilenameCompleter::new(), brackets_highliter: MatchingBracketHighlighter::new(), history_hinter: HistoryHinter {},