diff --git a/Makefile b/Makefile index 5722b9d..3e54291 100644 --- a/Makefile +++ b/Makefile @@ -12,7 +12,6 @@ release: clean @cargo build --release update: release - @git pull ifeq ($(UNAME), Darwin) cp target/release/bp ~/bin/ endif diff --git a/src/sys.rs b/src/sys.rs index 0747d25..ec39498 100644 --- a/src/sys.rs +++ b/src/sys.rs @@ -5,7 +5,9 @@ use core::str; #[derive(Subcommand)] pub enum SysCommand { /// Reboot breadpi. - Reboot, + Reboot, + /// Returns the local IP address of breadpi. + Ip } pub async fn handle_sys(cmd: &SysCommand) { @@ -14,7 +16,8 @@ pub async fn handle_sys(cmd: &SysCommand) { .expect("Could not connect to breadpi"); match cmd { - SysCommand::Reboot => { sys_reboot(&session).await; } + SysCommand::Reboot => { sys_reboot(&session).await; }, + SysCommand::Ip => { ip_addr(&session).await; } } let _ = session.close(); @@ -29,4 +32,14 @@ async fn sys_reboot(session: &Session) { println!("Error rebooting! Try again, possibly directly through ssh..."); println!("Error: {:?}", String::from_utf8(cmd.stderr)); } +} + +async fn ip_addr(session: &Session) { + let cmd = session.command("hostname") + .arg("-I") + .raw_arg("| grep -o '^[0-9.]*'") + .output().await.unwrap(); + + + println!("{}", String::from_utf8(cmd.stdout).expect("nuh uh")); } \ No newline at end of file