Skip to content

Commit

Permalink
Rename send -> action and bump to 0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Aug 1, 2021
1 parent 3cbdfb1 commit f24bb60
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 21 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "distant"
description = "Operate on a remote computer through file and process manipulation"
categories = ["command-line-utilities"]
version = "0.2.3"
version = "0.3.0"
authors = ["Chip Senkbeil <[email protected]>"]
edition = "2018"
homepage = "https://github.com/chipsenkbeil/distant"
Expand Down
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# distant

[![Crates.io][distant_crates_img]][distant_crates_lnk] [![Docs.rs][distant_doc_img]][distant_doc_lnk]

[distant_crates_img]: https://img.shields.io/crates/v/distant.svg
[distant_crates_lnk]: https://crates.io/crates/distant
[distant_doc_img]: https://docs.rs/distant/badge.svg
[distant_doc_lnk]: https://docs.rs/distant

Binary to connect with a remote machine to edit files and run programs.

## Details
Expand All @@ -25,9 +32,9 @@ starting the `distant` executable:
distant launch my.example.com

# After the session is established, you can perform different operations
# on the remote machine via `distant send {command} [args]`
distant send copy path/to/file new/path/to/file
distant send proc-run echo 'Hello, this is from the other side'
# on the remote machine via `distant action {command} [args]`
distant action copy path/to/file new/path/to/file
distant action proc-run -- echo 'Hello, this is from the other side'
```

## License
Expand Down
16 changes: 8 additions & 8 deletions src/opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,27 +50,27 @@ pub struct CommonOpt {

#[derive(Debug, StructOpt)]
pub enum Subcommand {
/// Performs some task related to the current session
Session(SessionSubcommand),

/// Sends some operation to be performed on a remote machine
Send(SendSubcommand),
/// Performs some action on a remote machine
Action(ActionSubcommand),

/// Launches the server-portion of the binary on a remote machine
Launch(LaunchSubcommand),

/// Begins listening for incoming requests
Listen(ListenSubcommand),

/// Performs some task related to the current session
Session(SessionSubcommand),
}

impl Subcommand {
/// Runs the subcommand, returning the result
pub fn run(self, opt: CommonOpt) -> Result<(), Box<dyn std::error::Error>> {
match self {
Self::Session(cmd) => subcommand::session::run(cmd, opt)?,
Self::Send(cmd) => subcommand::send::run(cmd, opt)?,
Self::Action(cmd) => subcommand::action::run(cmd, opt)?,
Self::Launch(cmd) => subcommand::launch::run(cmd, opt)?,
Self::Listen(cmd) => subcommand::listen::run(cmd, opt)?,
Self::Session(cmd) => subcommand::session::run(cmd, opt)?,
}

Ok(())
Expand Down Expand Up @@ -119,7 +119,7 @@ pub enum Mode {
/// Represents subcommand to execute some operation remotely
#[derive(Debug, StructOpt)]
#[structopt(verbatim_doc_comment)]
pub struct SendSubcommand {
pub struct ActionSubcommand {
/// Represents the format that results should be returned
///
/// Currently, there are two possible formats:
Expand Down
6 changes: 3 additions & 3 deletions src/subcommand/send.rs → src/subcommand/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::{
data::{Request, RequestPayload, Response, ResponsePayload},
net::{Client, TransportError},
opt::{CommonOpt, Mode, SendSubcommand},
opt::{ActionSubcommand, CommonOpt, Mode},
utils::{Session, SessionError},
};
use derive_more::{Display, Error, From};
Expand All @@ -26,13 +26,13 @@ pub enum Error {
MissingOperation,
}

pub fn run(cmd: SendSubcommand, opt: CommonOpt) -> Result<(), Error> {
pub fn run(cmd: ActionSubcommand, opt: CommonOpt) -> Result<(), Error> {
let rt = tokio::runtime::Runtime::new()?;

rt.block_on(async { run_async(cmd, opt).await })
}

async fn run_async(cmd: SendSubcommand, _opt: CommonOpt) -> Result<(), Error> {
async fn run_async(cmd: ActionSubcommand, _opt: CommonOpt) -> Result<(), Error> {
let session = Session::load().await?;
let mut client = Client::connect(session).await?;

Expand Down
1 change: 0 additions & 1 deletion src/subcommand/listen/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ async fn proc_run(
});

// Spawn a task that sends stdin to the process
// TODO: Should this be configurable?
let mut stdin = child.stdin.take().unwrap();
let (stdin_tx, mut stdin_rx) = mpsc::channel::<Vec<u8>>(1);
tokio::spawn(async move {
Expand Down
7 changes: 4 additions & 3 deletions src/subcommand/listen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ async fn request_loop(
}
}

/// Repeatedly sends responses out over the wire
async fn response_loop(
addr: SocketAddr,
mut transport: TransportWriteHalf,
Expand All @@ -211,10 +212,10 @@ async fn response_loop(
}
}

/// Prints out the port and **secret auth key** to share with a client when
/// establishing communication. This is **highly unsafe** and should only be
/// done when the server is launched over a secure channel such as SSH.
fn publish_data(port: u16, key: &SecretKey) {
// TODO: We have to share the key in some manner (maybe use k256 to arrive at the same key?)
// For now, we do what mosh does and print out the key knowing that this is shared over
// ssh, which should provide security
println!(
"DISTANT DATA {} {}",
port,
Expand Down
2 changes: 1 addition & 1 deletion src/subcommand/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub mod action;
pub mod launch;
pub mod listen;
pub mod send;
pub mod session;

0 comments on commit f24bb60

Please sign in to comment.