Skip to content

Commit

Permalink
Update to test READMEs
Browse files Browse the repository at this point in the history
  • Loading branch information
chipsenkbeil committed Jun 1, 2023
1 parent 3225471 commit b163094
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 88 deletions.
6 changes: 6 additions & 0 deletions distant-auth/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

mod authenticator;
mod handler;
mod methods;
Expand Down
39 changes: 4 additions & 35 deletions distant-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,12 @@
[distant_rustc_img]: https://img.shields.io/badge/distant_core-rustc_1.64+-lightgray.svg
[distant_rustc_lnk]: https://blog.rust-lang.org/2022/09/22/Rust-1.64.0.html

Library that powers the [`distant`](https://github.com/chipsenkbeil/distant)
binary.

🚧 **(Alpha stage software) This library is in rapid development and may break or change frequently!** 🚧

## Details

The `distant-core` library supplies the client, manager, and server
implementations for use with the distant API in order to communicate with
remote machines and perform actions. This library acts as the primary
implementation that powers the CLI, but is also available for other extensions
like `distant-ssh2`.
The `distant-core` library supplies the client and server interfaces along with
a client implementation for distant. The library exposes an API that downstream
libraries such as `distant-local` and `distant-ssh2` can implement to provide a
distant-compatible interface.

## Installation

Expand All @@ -31,31 +25,6 @@ You can import the dependency by adding the following to your `Cargo.toml`:
distant-core = "0.20"
```

## Examples

Below is an example of connecting to a distant server over TCP without any
encryption or authentication:

```rust
use distant_core::{
DistantClient,
DistantChannelExt,
net::{PlainCodec, TcpClientExt},
};
use std::{net::SocketAddr, path::Path};

// Connect to a server located at example.com on port 8080 that is using
// no encryption or authentication (PlainCodec)
let addr: SocketAddr = "example.com:8080".parse().unwrap();
let mut client = DistantClient::connect(addr, PlainCodec).await
.expect("Failed to connect");

// Append text to a file
// NOTE: This method comes from DistantChannelExt
client.append_file_text(Path::new("path/to/file.txt"), "new contents").await
.expect("Failed to append to file");
```

## License

This project is licensed under either of
Expand Down
6 changes: 6 additions & 0 deletions distant-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

mod api;
pub use api::*;

Expand Down
2 changes: 1 addition & 1 deletion distant-local/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ distant-local = "0.20"

## Examples

```rust
```rust,no_run
// Create a server API handler to be used with the server
let handler = distant_local::initialize_handler().unwrap();
```
Expand Down
6 changes: 6 additions & 0 deletions distant-local/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

mod api;
mod constants;
pub use api::LocalDistantApi;
Expand Down
6 changes: 6 additions & 0 deletions distant-net/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

mod authentication;
pub mod client;
pub mod common;
Expand Down
6 changes: 6 additions & 0 deletions distant-protocol/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

mod common;
mod msg;
mod request;
Expand Down
53 changes: 1 addition & 52 deletions distant-ssh2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,58 +26,7 @@ You can import the dependency by adding the following to your `Cargo.toml`:

```toml
[dependencies]
distant-ssh2 = "0.19"
```

## Examples

Below is an example of connecting to an ssh server and translating between ssh
protocol and distant protocol:

```rust
use distant_ssh2::{LocalSshAuthHandler, Ssh, SshOpts};

// Using default ssh arguments to establish a connection
let mut ssh = Ssh::connect("example.com", SshOpts::default())
.expect("Failed to connect");

// Authenticating with the server is a separate step
// 1. You can pass the local handler and authentication and host verification
// will be done over stderr
// 2. You can provide your own handlers for programmatic engagement
ssh.authenticate(LocalSshAuthHandler).await
.expect("Failed to authenticate");

// Convert into an ssh client session (no distant server required)
let client = ssh.into_distant_client().await
.expect("Failed to convert into distant client");
```

Below is an example of connecting to an ssh server, spawning a distant server
on the remote machine, and connecting to the distant server:

```rust
use distant_ssh2::{DistantLaunchOpts, LocalSshAuthHandler, Ssh, SshOpts};

// Using default ssh arguments to establish a connection
let mut ssh = Ssh::connect("example.com", SshOpts::default())
.expect("Failed to connect");

// Authenticating with the server is a separate step
// 1. You can pass the local handler and authentication and host verification
// will be done over stderr
// 2. You can provide your own handlers for programmatic engagement
ssh.authenticate(LocalSshAuthHandler).await
.expect("Failed to authenticate");

// Convert into a distant session, which involves spawning a distant server
// using the current ssh connection and then establishing a new connection
// to the distant server
//
// This takes in `DistantLaunchOpts` to specify the server's bin path,
// arguments, timeout, and whether or not to spawn using a login shell
let client = ssh.launch_and_connect(DistantLaunchOpts::default()).await
.expect("Failed to spawn server or connect to it");
distant-ssh2 = "0.20"
```

## License
Expand Down
6 changes: 6 additions & 0 deletions distant-ssh2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

#[cfg(not(any(feature = "libssh", feature = "ssh2")))]
compile_error!("Either feature \"libssh\" or \"ssh2\" must be enabled for this crate.");

Expand Down
6 changes: 6 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
#![doc = include_str!("../README.md")]

#[doc = include_str!("../README.md")]
#[cfg(doctest)]
pub struct ReadmeDoctests;

use std::process::{ExitCode, Termination};

use derive_more::{Display, Error, From};
Expand Down

0 comments on commit b163094

Please sign in to comment.