summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-01-10 08:49:09 +0100
committerMatthias Beyer <matthias.beyer@ifm.com>2022-02-18 15:41:57 +0100
commitdf052450ba30e55b5dcd464bca5236e1e995a2b9 (patch)
tree11ec5465c22459808055744582b6554d9f4bc624 /crates/core/tedge
parentee2a1c14f338fe5e433d4d58a862994d60fb18f7 (diff)
Replace structopt with clap 3
This patch rewrites the CLI interfaces to be used with clap 3.0 instead of clap 2.x + structopt. The changes are as minimal as possible, although I did not verify that the CLI is the same as before. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge')
-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
9 files changed, 31 insertions, 31 deletions
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()