Skip to content

Commit

Permalink
docs(rust): update command docs
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianbenavides committed Dec 19, 2023
1 parent dd4332b commit b81cf02
Show file tree
Hide file tree
Showing 27 changed files with 57 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl CreateTcpListener {
#[rustfmt::skip]
#[cbor(map)]
pub struct DeleteTransport {
/// The transport ID to delete
/// The transport processor address or socket address to delete
#[n(1)] pub address: String,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use ockam_transport_tcp::{TcpConnection, TcpListener, TcpListenerInfo, TcpSender
use std::net::SocketAddrV4;

/// Response body when interacting with a transport
#[derive(Debug, Clone, Decode, Encode)]
#[derive(Debug, Clone, Decode, Encode, serde::Serialize)]
#[rustfmt::skip]
#[cbor(map)]
pub struct TransportStatus {
Expand Down
2 changes: 1 addition & 1 deletion implementations/rust/ockam/ockam_command/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl NodeCommand {

#[derive(Clone, Debug, Args)]
pub struct NodeOpts {
/// Perform the command on the given NODE_NAME
/// Perform the command on the given node
#[arg(global = true, id = "at", value_name = "NODE_NAME", long, value_parser = extract_address_value)]
pub at_node: Option<String>,
}
3 changes: 0 additions & 3 deletions implementations/rust/ockam/ockam_command/src/node/start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ after_long_help = docs::after_help(AFTER_LONG_HELP)
pub struct StartCommand {
/// Name of the node to be started
node_name: Option<String>,

#[arg(long, default_value = "false")]
aws_kms: bool,
}

impl StartCommand {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
# Return the path to the stdout log file of the default node
$ ockam node logs

# Return the path to the stderr log file of the given node
$ ockam node logs n --err

# Pipe the logs to a file into another tool to process it
$ cat < $(ockam node logs n)
```
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct CreateCommand {
relay_name: String,

/// Node for which to create the relay
#[arg(long, id = "NODE", value_parser = extract_address_value)]
#[arg(long, id = "NODE_NAME", value_parser = extract_address_value)]
to: Option<String>,

/// Route to the node at which to create the relay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ async fn run_impl(
.to_string()
.color(OckamColor::PrimaryResource.color())
) + &fmt_log!(
"At node /node/{}",
"At node {}{}",
"/node/".color(OckamColor::PrimaryResource.color()),
node.node_name().color(OckamColor::PrimaryResource.color())
),
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
```sh
$ ockam node create n1
$ ockam node create n2

# Create a secure channel listener with a custom name on the default node
$ ockam secure-channel-listener create test --at n2
/service/test
✔ Secure Channel Listener at /service/test created successfully
At node /node/n2

# Create a secure channel from n1 to our test secure channel listener on n2
$ ockam secure-channel create --from /node/n1 --to /node/n2/service/test
/service/09738b73c54b81d48531f659aaa22533
$ ockam secure-channel create --from /node/n1 --to /node/n2/service/api
✔ Secure Channel at /service/5c2a940cf008783cfd8d7012e772d674 created successfully
From /node/n1 to /node/n2/service/api
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```sh
$ ockam secure-channel-listener delete scaddr --at n1
$ ockam secure-channel-listener delete 8eb3bfc8a6419f24c05ddd627d144bec --at n1
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```sh
$ ockam secure-channel-listener show scaddr --at n1
$ ockam secure-channel-listener show 8eb3bfc8a6419f24c05ddd627d144bec --at n1
```
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ Every node, created with Ockam Command, starts a secure channel listener at addr
$ ockam node create a
$ ockam node create b
$ ockam secure-channel create --from a --to /node/b/service/api
Created Secure Channel:
• From: /node/a
• To: /node/b/service/api (/ip4/127.0.0.1/tcp/53483/service/api)
• At: /service/d92ef0aea946ec01cdbccc5b9d3f2e16
✔ Secure Channel at /service/a2b1a2275d02308a7920499b5f49e4ee created successfully
From /node/n1 to /node/n2/service/api

$ ockam message send hello --from a --to /service/d92ef0aea946ec01cdbccc5b9d3f2e16/service/uppercase
HELLO
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```sh
$ ockam secure-channel delete scaddr --at n1
$ ockam secure-channel delete 8eb3bfc8a6419f24c05ddd627d144bec --at n1
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
```sh
$ ockam secure-channel show scaddr --at n1
$ ockam secure-channel show 8eb3bfc8a6419f24c05ddd627d144bec --at n1
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct DeleteCommand {
#[command(flatten)]
node_opts: NodeOpts,

/// TCP connection ID
/// TCP connection internal address or socket address
pub address: String,

/// Confirm the deletion without prompting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,15 @@ impl Output for TransportStatus {
)?;
writeln!(
output,
"Worker {}",
self.worker_addr
.to_string()
.color(OckamColor::PrimaryResource.color())
)?;
writeln!(
output,
"Processor {}",
"Internal Address {}",
self.processor_address
.to_string()
.color(OckamColor::PrimaryResource.color())
)?;

write!(
output,
"{}",
"Socket Address {}",
self.socket_addr
.to_string()
.color(OckamColor::PrimaryResource.color())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub struct ShowCommand {
#[command(flatten)]
pub node_opts: NodeOpts,

/// TCP connection Worker Address or Tcp Address
/// TCP connection internal address or socket address
pub address: String,
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
```sh
# To delete a TCP connection given its ID on the default node
# To delete a TCP connection given its internal address on the default node
$ ockam tcp-connection delete d59c01ab8d9683f8c454df746e627b43

# To delete a TCP connection given its ID on a specific node
# To delete a TCP connection given its socket address on the default node
$ ockam tcp-connection delete 127.0.0.1:5000

# To delete a TCP connection given its internal address on a specific node
$ ockam tcp-connection delete d59c01ab8d9683f8c454df746e627b43 --at n1
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
```sh
# To show a TCP connection given its ID
# To show a TCP connection given its internal address
$ ockam tcp-connection show d59c01ab8d9683f8c454df746e627b43

# To show a TCP connection given its socket address
$ ockam tcp-connection show 127.0.0.1:5000
```
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const AFTER_LONG_HELP: &str = include_str!("./static/create/after_long_help.txt"
#[command(after_long_help = docs::after_help(AFTER_LONG_HELP))]
pub struct CreateCommand {
/// Node on which to start the tcp inlet.
#[arg(long, display_order = 900, id = "NODE", value_parser = extract_address_value)]
#[arg(long, display_order = 900, id = "NODE_NAME", value_parser = extract_address_value)]
at: Option<String>,

/// Address on which to accept tcp connections.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
# To delete a TCP inlet given its alias on the default node
$ ockam tcp-inlet delete myinlet

# To delete a TCP inlet given its ID on a specific node
# To delete a TCP inlet given its alias on a specific node
$ ockam tcp-inlet delete myinlet --at n1
```
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct DeleteCommand {
#[command(flatten)]
node_opts: NodeOpts,

/// Tcp Listener ID
/// TCP Listener internal address
pub address: String,

/// Confirm the deletion without prompting
Expand Down
31 changes: 8 additions & 23 deletions implementations/rust/ockam/ockam_command/src/tcp/listener/show.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use clap::Args;
use indoc::formatdoc;
use miette::IntoDiagnostic;

use ockam::Context;
use ockam_api::nodes::models::transport::TransportStatus;
use ockam_api::nodes::BackgroundNode;
use ockam_core::api::Request;

use crate::node::NodeOpts;
use crate::output::Output;
use crate::util::node_rpc;
use crate::{docs, CommandGlobalOpts};

Expand All @@ -22,7 +23,7 @@ pub struct ShowCommand {
#[command(flatten)]
pub node_opts: NodeOpts,

/// TCP listener Worker Address or Tcp Address
/// TCP listener internal address or socket address
pub address: String,
}

Expand All @@ -43,26 +44,10 @@ async fn run_impl(
Request::get(format!("/node/tcp/listener/{}", &cmd.address)),
)
.await?;

let TransportStatus {
tt,
tm,
socket_addr,
processor_address,
flow_control_id,
..
} = transport_status;

let plain = formatdoc! {r#"
TCP Listener:
Type: {tt}
Mode: {tm}
Socket address: {socket_addr}
Worker address: {processor_address}
Flow Control Id: {flow_control_id}
"#};

opts.terminal.stdout().plain(plain).write_line()?;

opts.terminal
.stdout()
.plain(transport_status.output()?)
.json(serde_json::to_string(&transport_status).into_diagnostic()?)
.write_line()?;
Ok(())
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
```sh
# To delete a TCP listener given its ID on the default node
# To delete a TCP listener given its internal address on the default node
$ ockam tcp-listener delete d59c01ab8d9683f8c454df746e627b43

# To delete a TCP listener given its ID on a specific node
# To delete a TCP listener given its socket address on the default node
$ ockam tcp-listener delete 127.0.0.1:5000

# To delete a TCP listener given its internal address on a specific node
$ ockam tcp-listener delete d59c01ab8d9683f8c454df746e627b43 --at n1
```
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
```sh
# To show a TCP listener given its ID
# To show a TCP listener given its internal address
$ ockam tcp-listener show d59c01ab8d9683f8c454df746e627b43

# To show a TCP listener given its socket address
$ ockam tcp-listener show 127.0.0.1:5000
```
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const AFTER_LONG_HELP: &str = include_str!("./static/create/after_long_help.txt"
#[command(after_long_help = docs::after_help(AFTER_LONG_HELP))]
pub struct CreateCommand {
/// Node on which to start the tcp outlet.
#[arg(long, display_order = 900, id = "NODE", value_parser = extract_address_value)]
#[arg(long, display_order = 900, id = "NODE_NAME", value_parser = extract_address_value)]
at: Option<String>,

/// Address of the tcp outlet.
Expand Down
4 changes: 2 additions & 2 deletions implementations/rust/ockam/ockam_command/src/terminal/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ macro_rules! fmt_log {
macro_rules! fmt_ok {
($input:expr) => {
format!("{} {}",
" ✔"
" ✔"
.color($crate::terminal::OckamColor::FmtOKBackground.color())
.bold(),
format!($input))
};
($input:expr, $($args:expr),+) => {
format!("{} {}",
" ✔"
" ✔"
.color($crate::terminal::OckamColor::FmtOKBackground.color())
.bold(),
format!($input, $($args),+))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ after_long_help = docs::after_help(AFTER_LONG_HELP)
)]
pub struct ListCommand {
/// Node at which to lookup workers
#[arg(value_name = "NODE", long, display_order = 800, value_parser = extract_address_value)]
#[arg(value_name = "NODE_NAME", long, display_order = 800, value_parser = extract_address_value)]
at: Option<String>,
}

Expand Down

0 comments on commit b81cf02

Please sign in to comment.