aboutsummaryrefslogtreecommitdiffstats
path: root/mumctl/src
diff options
context:
space:
mode:
authorGustav Sörnäs <gustav@sornas.net>2020-10-16 00:21:05 +0200
committerGustav Sörnäs <gustav@sornas.net>2020-10-16 00:21:05 +0200
commit402174bc195fd59adcee82a9b2d2b3034320406b (patch)
tree26b927b873ab8cbb476234cd3c0bde12209acd15 /mumctl/src
parent5fee8b205bf9f46a038f55da51b3cdb68a0ab429 (diff)
downloadmum-402174bc195fd59adcee82a9b2d2b3034320406b.tar.gz
initial clap
Diffstat (limited to 'mumctl/src')
-rw-r--r--mumctl/src/main.rs69
1 files changed, 57 insertions, 12 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs
index 39986f0..e4746d3 100644
--- a/mumctl/src/main.rs
+++ b/mumctl/src/main.rs
@@ -1,3 +1,4 @@
+use clap::{App, Arg, SubCommand};
use ipc_channel::ipc::{self, IpcReceiver, IpcSender};
use log::*;
use mumlib::command::{Command, CommandResponse};
@@ -7,25 +8,69 @@ use std::fs;
fn main() {
setup_logger();
+ let matches = App::new("mumctl")
+ .subcommand(SubCommand::with_name("server")
+ .subcommand(SubCommand::with_name("connect")
+ .arg(Arg::with_name("host")
+ .required(true)
+ .index(1))
+ .arg(Arg::with_name("username")
+ .required(true)
+ .index(2)))
+ .subcommand(SubCommand::with_name("disconnect")))
+ .subcommand(SubCommand::with_name("channel")
+ .subcommand(SubCommand::with_name("list")
+ .arg(Arg::with_name("short")
+ .short("s")
+ .long("short")))
+ .subcommand(SubCommand::with_name("connect")
+ .arg(Arg::with_name("channel")
+ .required(true))))
+ .subcommand(SubCommand::with_name("status"))
+ .get_matches();
+
+ let command =
+ if let Some(matches) = matches.subcommand_matches("server") {
+ if let Some(matches) = matches.subcommand_matches("connect") {
+ let host = matches.value_of("host").unwrap();
+ let username = matches.value_of("username").unwrap();
+ Some(Command::ServerConnect {
+ host: host.to_string(),
+ port: 64738u16, //TODO
+ username: username.to_string(),
+ accept_invalid_cert: true, //TODO
+ })
+ } else {
+ None
+ }
+ } else if let Some(matches) = matches.subcommand_matches("channel") {
+ if let Some(matches) = matches.subcommand_matches("list") {
+ if matches.is_present("short") {
+ None //TODO
+ } else {
+ None //TODO
+ }
+ } else if let Some(_matches) = matches.subcommand_matches("connect") {
+ None //TODO
+ } else {
+ None
+ }
+ } else if let Some(_matches) = matches.subcommand_matches("status") {
+ None //TODO
+ } else {
+ None
+ };
+
debug!("Creating channel");
let (tx_client, rx_client): (IpcSender<Result<Option<CommandResponse>, ()>>,
IpcReceiver<Result<Option<CommandResponse>, ()>>) = ipc::channel().unwrap();
let server_name = fs::read_to_string("/var/tmp/mumd-oneshot").unwrap(); //TODO don't panic
- debug!("Connecting to mumd at {}", server_name);
+ info!("Sending {:#?}", command);
let tx0 = IpcSender::connect(server_name).unwrap();
- let connect_command = Command::ServerConnect {
- host: "10.0.0.10".to_string(),
- port: 64738u16,
- username: "gustav-mumd".to_string(),
- accept_invalid_cert: true,
- };
- debug!("Sending {:?} to mumd", connect_command);
- tx0.send((
- connect_command,
- tx_client)) .unwrap();
+ tx0.send((command.unwrap(), tx_client)).unwrap();
debug!("Reading response");
let response = rx_client.recv().unwrap();
- debug!("{:?}", response);
+ debug!("\n{:#?}", response);
}