diff options
| author | Gustav Sörnäs <gustav@sornas.net> | 2020-10-16 00:21:05 +0200 |
|---|---|---|
| committer | Gustav Sörnäs <gustav@sornas.net> | 2020-10-16 00:21:05 +0200 |
| commit | 402174bc195fd59adcee82a9b2d2b3034320406b (patch) | |
| tree | 26b927b873ab8cbb476234cd3c0bde12209acd15 | |
| parent | 5fee8b205bf9f46a038f55da51b3cdb68a0ab429 (diff) | |
| download | mum-402174bc195fd59adcee82a9b2d2b3034320406b.tar.gz | |
initial clap
| -rw-r--r-- | mumctl/Cargo.toml | 2 | ||||
| -rw-r--r-- | mumctl/src/main.rs | 69 | ||||
| -rw-r--r-- | mumlib/src/command.rs | 2 | ||||
| -rw-r--r-- | usage.org | 12 |
4 files changed, 65 insertions, 20 deletions
diff --git a/mumctl/Cargo.toml b/mumctl/Cargo.toml index 3a432d9..1f2f727 100644 --- a/mumctl/Cargo.toml +++ b/mumctl/Cargo.toml @@ -11,8 +11,8 @@ edition = "2018" [dependencies] mumlib = { path = "../mumlib" } +clap = { version = "2.33", features = ["yaml"] } log = "0.4" ipc-channel = "0.14" -#clap = "2.33" #cursive = "0.15" 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); } diff --git a/mumlib/src/command.rs b/mumlib/src/command.rs index 483d8c6..b2ac321 100644 --- a/mumlib/src/command.rs +++ b/mumlib/src/command.rs @@ -13,7 +13,7 @@ pub enum Command { host: String, port: u16, username: String, - accept_invalid_cert: bool, //TODO ask when connecting + accept_invalid_cert: bool, }, ServerDisconnect, Status, @@ -20,8 +20,8 @@ The daemon doesn't do anything by itself. Interfacing with it is done through The basic commands are the smallest subset of commands that allow the user to actually use mum for something. In this case it means connecting to a server, listing channels and connecting to channels. -** TODO server -*** TODO connect +** DONE server +*** DONE connect #+BEGIN_SRC bash $ mumctl server connect localhost your_name connecting to localhost... @@ -31,8 +31,8 @@ root │ some person | your_name #+END_SRC -** TODO channel -*** TODO list +** DONE channel +*** DONE list #+BEGIN_SRC bash $ mumctl channel list root [3](4) @@ -60,13 +60,13 @@ root [3](4) │ └─ subsubchannel [2] └─ AFK [1] #+END_SRC -*** TODO connect +*** DONE connect #+BEGIN_SRC bash $ mumctl channel connect some channel connecting to some channel... connected #+END_SRC -** TODO status +** DONE status #+BEGIN_SRC bash $ mumctl status connected to localhost:65837 as your_name |
