Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(rust): Rename Ockam Command MessageFormat to OutputFormat #3073

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct GenerateEnrollmentTokenCommand {
Expand Down Expand Up @@ -59,9 +59,9 @@ async fn generate(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<EnrollmentToken>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("Token generated successfully: {:?}", body.token),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("Token generated successfully: {:?}", body.token),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ockam_multiaddr::MultiAddr;

use crate::node::NodeOpts;
use crate::util::{api, connect_to, stop_node, DEFAULT_CLOUD_ADDRESS};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct CreateCommand {
Expand Down Expand Up @@ -70,12 +70,12 @@ async fn create(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<ForwarderInfo>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!(
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!(
"Forwarder created! You can send messages to it via this address:\n{}",
body.remote_address()
),
MessageFormat::Json => json!({
OutputFormat::Json => json!({
"remote_address": body.remote_address(),
})
.to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct CreateCommand {
Expand Down Expand Up @@ -65,9 +65,9 @@ async fn create(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Invitation>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => "Invitation created".to_string(),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => "Invitation created".to_string(),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct ListCommand;
Expand Down Expand Up @@ -53,9 +53,9 @@ async fn list(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Vec<Invitation>>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("{body:#?}"),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("{body:#?}"),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
12 changes: 9 additions & 3 deletions implementations/rust/ockam/ockam_command/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,14 @@ pub struct GlobalArgs {
)]
verbose: u8,

#[clap(global = true, long, short, value_enum, default_value = "plain")]
message_format: MessageFormat,
#[clap(
global = true,
long = "format",
short = 'f',
value_enum,
default_value = "plain"
)]
output_format: OutputFormat,

// if test_argument_parser is true, command arguments are checked
// but the command is not executed.
Expand All @@ -108,7 +114,7 @@ pub struct GlobalArgs {
}

#[derive(Debug, Clone, ArgEnum)]
pub enum MessageFormat {
pub enum OutputFormat {
Plain,
Json,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct CreateCommand {
Expand Down Expand Up @@ -66,9 +66,9 @@ async fn create(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Project>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => "Project created".to_string(),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => "Project created".to_string(),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct DeleteCommand {
Expand Down Expand Up @@ -61,9 +61,9 @@ async fn delete(

let res = match header.status() {
Some(Status::Ok) => {
let output = match opts.global_args.message_format {
MessageFormat::Plain => "Project deleted".to_string(),
MessageFormat::Json => json!({
let output = match opts.global_args.output_format {
OutputFormat::Plain => "Project deleted".to_string(),
OutputFormat::Json => json!({
"id": project_id,
})
.to_string(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct ListCommand;
Expand Down Expand Up @@ -53,9 +53,9 @@ async fn list(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Vec<Project>>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("{body:#?}"),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("{body:#?}"),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct ShowCommand {
Expand Down Expand Up @@ -66,9 +66,9 @@ async fn show(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Project>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("{body:#?}"),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("{body:#?}"),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct CreateCommand {
Expand Down Expand Up @@ -65,9 +65,9 @@ async fn create(
let body = dec
.decode::<Space>()
.context("Failed to decode response body")?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => "Space created".to_string(),
MessageFormat::Json => serde_json::to_string(&body)
let output = match opts.global_args.output_format {
OutputFormat::Plain => "Space created".to_string(),
OutputFormat::Json => serde_json::to_string(&body)
.context("Failed to serialize command output as json")?,
};
Ok(output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct DeleteCommand {
Expand Down Expand Up @@ -57,9 +57,9 @@ async fn delete(

let res = match header.status() {
Some(Status::Ok) => {
let output = match opts.global_args.message_format {
MessageFormat::Plain => "Space deleted".to_string(),
MessageFormat::Json => json!({
let output = match opts.global_args.output_format {
OutputFormat::Plain => "Space deleted".to_string(),
OutputFormat::Json => json!({
"id": space_id,
})
.to_string(),
Expand Down
8 changes: 4 additions & 4 deletions implementations/rust/ockam/ockam_command/src/space/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct ListCommand;
Expand Down Expand Up @@ -53,9 +53,9 @@ async fn list(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Vec<Space>>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("{body:#?}"),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("{body:#?}"),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down
8 changes: 4 additions & 4 deletions implementations/rust/ockam/ockam_command/src/space/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use ockam_core::Route;
use crate::node::NodeOpts;
use crate::util::api::CloudOpts;
use crate::util::{api, connect_to, stop_node};
use crate::{CommandGlobalOpts, MessageFormat};
use crate::{CommandGlobalOpts, OutputFormat};

#[derive(Clone, Debug, Args)]
pub struct ShowCommand {
Expand Down Expand Up @@ -57,9 +57,9 @@ async fn show(
let res = match header.status() {
Some(Status::Ok) => {
let body = dec.decode::<Space>()?;
let output = match opts.global_args.message_format {
MessageFormat::Plain => format!("{body:#?}"),
MessageFormat::Json => serde_json::to_string(&body)?,
let output = match opts.global_args.output_format {
OutputFormat::Plain => format!("{body:#?}"),
OutputFormat::Json => serde_json::to_string(&body)?,
};
Ok(output)
}
Expand Down