summaryrefslogtreecommitdiffstats
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/core/plugin_sm/Cargo.toml1
-rw-r--r--crates/core/tedge/Cargo.toml2
-rw-r--r--crates/core/tedge/src/cli/certificate/cli.rs10
-rw-r--r--crates/core/tedge/src/cli/config/cli.rs7
-rw-r--r--crates/core/tedge/src/cli/connect/cli.rs7
-rw-r--r--crates/core/tedge/src/cli/disconnect/cli.rs3
-rw-r--r--crates/core/tedge/src/cli/mod.rs16
-rw-r--r--crates/core/tedge/src/cli/mqtt/cli.rs11
-rw-r--r--crates/core/tedge/src/command.rs2
-rw-r--r--crates/core/tedge/src/main.rs4
-rw-r--r--crates/core/tedge_agent/Cargo.toml2
-rw-r--r--crates/core/tedge_agent/src/main.rs14
-rw-r--r--crates/core/tedge_mapper/Cargo.toml2
-rw-r--r--crates/core/tedge_mapper/src/main.rs19
14 files changed, 49 insertions, 51 deletions
diff --git a/crates/core/plugin_sm/Cargo.toml b/crates/core/plugin_sm/Cargo.toml
index 20a2fc1d..4924b113 100644
--- a/crates/core/plugin_sm/Cargo.toml
+++ b/crates/core/plugin_sm/Cargo.toml
@@ -21,7 +21,6 @@ url = "2.2"
[dev-dependencies]
anyhow = "1.0"
assert_matches = "1.5"
-structopt = "0.3"
serial_test = "0.5.1"
tempfile = "3.2"
test-case = "1.2.1"
diff --git a/crates/core/tedge/Cargo.toml b/crates/core/tedge/Cargo.toml
index 2180b35c..f19a91e7 100644
--- a/crates/core/tedge/Cargo.toml
+++ b/crates/core/tedge/Cargo.toml
@@ -16,6 +16,7 @@ maintainer-scripts = "../../../configuration/debian/tedge"
anyhow = "1.0"
base64 = "0.13"
certificate = { path = "../../common/certificate" }
+clap = { version = "3", features = ["cargo", "derive"] }
futures = "0.3"
hyper = { version = "0.14", default-features = false }
reqwest = { version = "0.11", default-features = false, features = ["blocking", "json", "rustls-tls", "stream"] }
@@ -25,7 +26,6 @@ rustls = "0.20.2"
rustls_0_19 = {package = "rustls", version = "0.19.0" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
-structopt = "0.3"
tedge_config = { path = "../../common/tedge_config" }
tedge_users = { path = "../../common/tedge_users" }
tedge_utils = { path = "../../common/tedge_utils" }
diff --git a/crates/core/tedge/src/cli/certificate/cli.rs b/crates/core/tedge/src/cli/certificate/cli.rs
index 7ef78fb5..a3e9db64 100644
--- a/crates/core/tedge/src/cli/certificate/cli.rs
+++ b/crates/core/tedge/src/cli/certificate/cli.rs
@@ -3,15 +3,14 @@ use super::{create::CreateCertCmd, remove::RemoveCertCmd, show::ShowCertCmd, upl
use crate::command::{BuildCommand, BuildContext, Command};
use crate::ConfigError;
-use structopt::StructOpt;
use tedge_config::*;
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum TEdgeCertCli {
/// Create a self-signed device certificate
Create {
/// The device identifier to be used as the common name for the certificate
- #[structopt(long = "device-id")]
+ #[clap(long = "device-id")]
id: String,
},
@@ -22,6 +21,7 @@ pub enum TEdgeCertCli {
Remove,
/// Upload root certificate
+ #[clap(subcommand)]
Upload(UploadCertCli),
}
@@ -73,13 +73,13 @@ impl BuildCommand for TEdgeCertCli {
}
}
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum UploadCertCli {
/// Upload root certificate to Cumulocity
///
/// The command will upload root certificate to Cumulocity.
C8y {
- #[structopt(long = "user")]
+ #[clap(long = "user")]
/// Provided username should be a Cumulocity user with tenant management permissions.
/// The password is requested on /dev/tty, unless the $C8YPASS env var is set to the user password.
username: String,
diff --git a/crates/core/tedge/src/cli/config/cli.rs b/crates/core/tedge/src/cli/config/cli.rs
index bfe2caa4..dff15e47 100644
--- a/crates/core/tedge/src/cli/config/cli.rs
+++ b/crates/core/tedge/src/cli/config/cli.rs
@@ -1,10 +1,9 @@
use crate::cli::config::{commands::*, config_key::*};
use crate::command::*;
use crate::ConfigError;
-use structopt::StructOpt;
use tedge_config::ConfigRepository;
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum ConfigCmd {
/// Get the value of the provided configuration key
Get {
@@ -30,11 +29,11 @@ pub enum ConfigCmd {
/// Print the configuration keys and their values
List {
/// Prints all the configuration keys, even those without a configured value
- #[structopt(long = "all")]
+ #[clap(long = "all")]
is_all: bool,
/// Prints all keys and descriptions with example values
- #[structopt(long = "doc")]
+ #[clap(long = "doc")]
is_doc: bool,
},
}
diff --git a/crates/core/tedge/src/cli/connect/cli.rs b/crates/core/tedge/src/cli/connect/cli.rs
index 64a351f4..654af945 100644
--- a/crates/core/tedge/src/cli/connect/cli.rs
+++ b/crates/core/tedge/src/cli/connect/cli.rs
@@ -1,16 +1,15 @@
use crate::cli::connect::*;
use crate::command::{BuildCommand, BuildContext, Command};
use crate::system_services::service_manager;
-use structopt::StructOpt;
-#[derive(StructOpt, Debug, PartialEq)]
+#[derive(clap::Subcommand, Debug, PartialEq)]
pub enum TEdgeConnectOpt {
/// Create connection to Cumulocity
///
/// The command will create config and start edge relay from the device to c8y instance
C8y {
/// Test connection to Cumulocity
- #[structopt(long = "test")]
+ #[clap(long = "test")]
is_test_connection: bool,
},
@@ -19,7 +18,7 @@ pub enum TEdgeConnectOpt {
/// The command will create config and start edge relay from the device to az instance
Az {
/// Test connection to Azure
- #[structopt(long = "test")]
+ #[clap(long = "test")]
is_test_connection: bool,
},
}
diff --git a/crates/core/tedge/src/cli/disconnect/cli.rs b/crates/core/tedge/src/cli/disconnect/cli.rs
index 1b77aff6..e13a9250 100644
--- a/crates/core/tedge/src/cli/disconnect/cli.rs
+++ b/crates/core/tedge/src/cli/disconnect/cli.rs
@@ -1,12 +1,11 @@
use crate::cli::disconnect::disconnect_bridge::*;
use crate::command::*;
use crate::system_services::service_manager;
-use structopt::StructOpt;
const C8Y_CONFIG_FILENAME: &str = "c8y-bridge.conf";
const AZURE_CONFIG_FILENAME: &str = "az-bridge.conf";
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum TEdgeDisconnectBridgeCli {
/// Remove bridge connection to Cumulocity.
C8y,
diff --git a/crates/core/tedge/src/cli/mod.rs b/crates/core/tedge/src/cli/mod.rs
index d54dacee..236b718f 100644
--- a/crates/core/tedge/src/cli/mod.rs
+++ b/crates/core/tedge/src/cli/mod.rs
@@ -1,6 +1,5 @@
use crate::command::{BuildCommand, BuildContext, Command};
-use structopt::clap;
-use structopt::StructOpt;
+use clap;
mod certificate;
mod config;
@@ -8,32 +7,37 @@ mod connect;
mod disconnect;
mod mqtt;
-#[derive(StructOpt, Debug)]
-#[structopt(
+#[derive(clap::Parser, Debug)]
+#[clap(
name = clap::crate_name!(),
version = clap::crate_version!(),
about = clap::crate_description!()
)]
pub struct Opt {
- #[structopt(subcommand)]
+ #[clap(subcommand)]
pub tedge: TEdgeOpt,
}
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum TEdgeOpt {
/// Create and manage device certificate
+ #[clap(subcommand)]
Cert(certificate::TEdgeCertCli),
/// Configure Thin Edge.
+ #[clap(subcommand)]
Config(config::ConfigCmd),
/// Connect to connector provider
+ #[clap(subcommand)]
Connect(connect::TEdgeConnectOpt),
/// Remove bridge connection for a provider
+ #[clap(subcommand)]
Disconnect(disconnect::TEdgeDisconnectBridgeCli),
/// Publish a message on a topic and subscribe a topic.
+ #[clap(subcommand)]
Mqtt(mqtt::TEdgeMqttCli),
}
diff --git a/crates/core/tedge/src/cli/mqtt/cli.rs b/crates/core/tedge/src/cli/mqtt/cli.rs
index 32f4906f..f6878a78 100644
--- a/crates/core/tedge/src/cli/mqtt/cli.rs
+++ b/crates/core/tedge/src/cli/mqtt/cli.rs
@@ -2,7 +2,6 @@ use crate::cli::mqtt::{publish::MqttPublishCommand, subscribe::MqttSubscribeComm
use crate::command::{BuildCommand, BuildContext, Command};
use rumqttc::QoS;
use std::time::Duration;
-use structopt::StructOpt;
use tedge_config::*;
const DEFAULT_HOST: &str = "localhost";
@@ -10,7 +9,7 @@ const PUB_CLIENT_PREFIX: &str = "tedge-pub";
const SUB_CLIENT_PREFIX: &str = "tedge-sub";
const DISCONNECT_TIMEOUT: Duration = Duration::from_secs(2);
-#[derive(StructOpt, Debug)]
+#[derive(clap::Subcommand, Debug)]
pub enum TEdgeMqttCli {
/// Publish a MQTT message on a topic.
Pub {
@@ -19,10 +18,10 @@ pub enum TEdgeMqttCli {
/// Message to publish
message: String,
/// QoS level (0, 1, 2)
- #[structopt(short, long, parse(try_from_str = parse_qos), default_value = "0")]
+ #[clap(short, long, parse(try_from_str = parse_qos), default_value = "0")]
qos: QoS,
/// Retain flag
- #[structopt(short, long = "retain")]
+ #[clap(short, long = "retain")]
retain: bool,
},
@@ -31,10 +30,10 @@ pub enum TEdgeMqttCli {
/// Topic to subscribe to
topic: String,
/// QoS level (0, 1, 2)
- #[structopt(short, long, parse(try_from_str = parse_qos), default_value = "0")]
+ #[clap(short, long, parse(try_from_str = parse_qos), default_value = "0")]
qos: QoS,
/// Avoid printing the message topics on the console
- #[structopt(long = "no-topic")]
+ #[clap(long = "no-topic")]
hide_topic: bool,
},
}
diff --git a/crates/core/tedge/src/command.rs b/crates/core/tedge/src/command.rs
index 6637d0da..0ad255f5 100644
--- a/crates/core/tedge/src/command.rs
+++ b/crates/core/tedge/src/command.rs
@@ -115,7 +115,7 @@ pub trait Command {
/// In practice, an implementation will also derives the `Structopt` trait.
///
/// ```
-/// #[derive(StructOpt, Debug)]
+/// #[derive(clap::Parser, Debug)]
/// enum ConfigCmd {
/// /// Add new value (overwrite the value if the key exists).
/// Set { key: String, value: String },
diff --git a/crates/core/tedge/src/main.rs b/crates/core/tedge/src/main.rs
index e6313ab3..375debab 100644
--- a/crates/core/tedge/src/main.rs
+++ b/crates/core/tedge/src/main.rs
@@ -2,7 +2,7 @@
#![deny(clippy::mem_forget)]
use anyhow::Context;
-use structopt::StructOpt;
+use clap::Parser;
use tedge_users::UserManager;
use tedge_utils::paths::{home_dir, PathsError};
@@ -20,7 +20,7 @@ fn main() -> anyhow::Result<()> {
let _user_guard = user_manager.become_user(tedge_users::TEDGE_USER)?;
- let opt = cli::Opt::from_args();
+ let opt = cli::Opt::parse();
let tedge_config_location = if tedge_users::UserManager::running_as_root() {
tedge_config::TEdgeConfigLocation::from_default_system_location()
diff --git a/crates/core/tedge_agent/Cargo.toml b/crates/core/tedge_agent/Cargo.toml
index b36e26f7..30dafb71 100644
--- a/crates/core/tedge_agent/Cargo.toml
+++ b/crates/core/tedge_agent/Cargo.toml
@@ -25,6 +25,7 @@ stop-on-upgrade = false
agent_interface = { path = "../agent_interface" }
anyhow = "1.0"
async-trait = "0.1"
+clap = { version = "3.0", features = ["cargo", "derive"] }
flockfile = { path = "../../common/flockfile" }
futures = "0.3"
mockall = "0.10"
@@ -32,7 +33,6 @@ mqtt_channel = { path = "../../common/mqtt_channel" }
plugin_sm = { path = "../plugin_sm" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
-structopt = "0.3"
tedge_config = { path = "../../common/tedge_config" }
tedge_utils = { path = "../../common/tedge_utils", features = ["logging"] }
thiserror = "1.0"
diff --git a/crates/core/tedge_agent/src/main.rs b/crates/core/tedge_agent/src/main.rs
index abe34344..e6492d2c 100644
--- a/crates/core/tedge_agent/src/main.rs
+++ b/crates/core/tedge_agent/src/main.rs
@@ -1,5 +1,5 @@
use agent::SmAgentConfig;
-use structopt::*;
+use clap::Parser;
mod agent;
mod error;
@@ -7,8 +7,8 @@ mod operation_logs;
mod restart_operation_handler;
mod state;
-#[derive(Debug, StructOpt)]
-#[structopt(
+#[derive(Debug, clap::Parser)]
+#[clap(
name = clap::crate_name!(),
version = clap::crate_version!(),
about = clap::crate_description!()
@@ -18,23 +18,23 @@ pub struct AgentOpt {
///
/// If off only reports ERROR, WARN, and INFO
/// If on also reports DEBUG and TRACE
- #[structopt(long)]
+ #[clap(long)]
pub debug: bool,
/// Start the agent with clean session off, subscribe to the topics, so that no messages are lost
- #[structopt(short, long)]
+ #[clap(short, long)]
pub init: bool,
/// Start the agent with clean session on, drop the previous session and subscriptions
///
/// WARNING: All pending messages will be lost.
- #[structopt(short, long)]
+ #[clap(short, long)]
pub clear: bool,
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
- let agent_opt = AgentOpt::from_args();
+ let agent_opt = AgentOpt::parse();
tedge_utils::logging::initialise_tracing_subscriber(agent_opt.debug);
let tedge_config_location = tedge_config::TEdgeConfigLocation::from_default_system_location();
let mut agent = agent::SmAgent::try_new(
diff --git a/crates/core/tedge_mapper/Cargo.toml b/crates/core/tedge_mapper/Cargo.toml
index 91c18d07..ffc8d6d3 100644
--- a/crates/core/tedge_mapper/Cargo.toml
+++ b/crates/core/tedge_mapper/Cargo.toml
@@ -42,7 +42,7 @@ mqtt_channel = { path = "../../common/mqtt_channel" }
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
-structopt = "0.3"
+clap = { version = "3.0", features = ["cargo", "derive"] }
tedge_config = { path = "../../common/tedge_config" }
tedge_users = { path = "../../common/tedge_users" }
tedge_utils = { path = "../../common/tedge_utils", features = ["logging"] }
diff --git a/crates/core/tedge_mapper/src/main.rs b/crates/core/tedge_mapper/src/main.rs
index 5da3d0da..b9c5ef69 100644
--- a/crates/core/tedge_mapper/src/main.rs
+++ b/crates/core/tedge_mapper/src/main.rs
@@ -6,9 +6,8 @@ use crate::{
collectd::mapper::CollectdMapper,
core::{component::TEdgeComponent, error::MapperError},
};
-
+use clap::Parser;
use flockfile::check_another_instance_is_not_running;
-use structopt::*;
use tedge_config::*;
use tedge_utils::paths::home_dir;
@@ -25,35 +24,35 @@ fn lookup_component(component_name: &MapperName) -> Box<dyn TEdgeComponent> {
}
}
-#[derive(Debug, StructOpt)]
-#[structopt(
+#[derive(Debug, Parser)]
+#[clap(
name = clap::crate_name!(),
version = clap::crate_version!(),
about = clap::crate_description!()
)]
pub struct MapperOpt {
- #[structopt(subcommand)]
+ #[clap(subcommand)]
pub name: MapperName,
/// Turn-on the debug log level.
///
/// If off only reports ERROR, WARN, and INFO
/// If on also reports DEBUG and TRACE
- #[structopt(long, global = true)]
+ #[clap(long, global = true)]
pub debug: bool,
/// Start the mapper with clean session off, subscribe to the topics, so that no messages are lost
- #[structopt(short, long)]
+ #[clap(short, long)]
pub init: bool,
/// Start the agent with clean session on, drop the previous session and subscriptions
///
/// WARNING: All pending messages will be lost.
- #[structopt(short, long)]
+ #[clap(short, long)]
pub clear: bool,
}
-#[derive(Debug, StructOpt)]
+#[derive(Debug, clap::Subcommand)]
pub enum MapperName {
Az,
C8y,
@@ -72,7 +71,7 @@ impl fmt::Display for MapperName {
#[tokio::main]
async fn main() -> anyhow::Result<()> {
- let mapper = MapperOpt::from_args();
+ let mapper = MapperOpt::parse();
tedge_utils::logging::initialise_tracing_subscriber(mapper.debug);
let component = lookup_component(&mapper.name);