Skip to content

Commit d72ce98

Browse files
authored
Switch from structopt to clap (#141)
Related to #140
1 parent 48579d8 commit d72ce98

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

server/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "parseable"
33
version = "0.0.3"
44
authors = [
5-
"NitishTiwari <[email protected]>",
5+
"NitishTiwari <[email protected]>",
66
"AdheipSingh <[email protected]>",
77
]
88
edition = "2021"
@@ -20,6 +20,7 @@ aws-smithy-async = { version = "0.49.0", features = ["rt-tokio"] }
2020
bytes = "1"
2121
chrono = "0.4.19"
2222
chrono-humanize = "0.2.2"
23+
clap = { version = "4.0.8", features = ["derive", "env"] }
2324
crossterm = "0.23.2"
2425
datafusion = "11.0"
2526
object_store = { version = "0.4", features=["aws"] }
@@ -41,7 +42,6 @@ semver = "1.0.14"
4142
serde = "^1.0.8"
4243
serde_derive = "^1.0.8"
4344
serde_json = "^1.0.8"
44-
structopt = { version = "0.3.25" }
4545
sysinfo = "0.20.5"
4646
thiserror = "1"
4747
thread-priority = "0.9.2"

server/src/option.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
*
1717
*/
1818

19+
use clap::Parser;
1920
use crossterm::style::Stylize;
2021
use std::path::PathBuf;
2122
use std::sync::Arc;
22-
use structopt::StructOpt;
2323

2424
use crate::banner;
2525
use crate::s3::S3Config;
@@ -28,7 +28,7 @@ use crate::storage::{ObjectStorage, ObjectStorageError, LOCAL_SYNC_INTERVAL};
2828
lazy_static::lazy_static! {
2929
#[derive(Debug)]
3030
pub static ref CONFIG: Arc<Config> = {
31-
let storage = Box::new(S3Config::from_args());
31+
let storage = Box::new(S3Config::parse());
3232
Arc::new(Config::new(storage))
3333
};
3434
}
@@ -53,7 +53,7 @@ pub struct Config {
5353
impl Config {
5454
fn new(storage: Box<dyn StorageOpt>) -> Config {
5555
Config {
56-
parseable: Opt::from_args(),
56+
parseable: Opt::parse(),
5757
storage,
5858
}
5959
}
@@ -91,7 +91,7 @@ impl Config {
9191
"Failed to authenticate. Please ensure credentials are valid\n Caused by: {cause}",
9292
cause = inner
9393
),
94-
Err(error) => { panic!("{error}") }
94+
Err(error) => { panic!("{error}") }
9595
}
9696
}
9797

@@ -164,41 +164,41 @@ impl Config {
164164
}
165165
}
166166

167-
#[derive(Debug, Clone, StructOpt)]
168-
#[structopt(
167+
#[derive(Debug, Clone, Parser)]
168+
#[command(
169169
name = "Parseable config",
170170
about = "configuration for Parseable server"
171171
)]
172172
pub struct Opt {
173173
/// The location of TLS Cert file
174-
#[structopt(long, env = "P_TLS_CERT_PATH")]
174+
#[arg(long, env = "P_TLS_CERT_PATH")]
175175
pub tls_cert_path: Option<PathBuf>,
176176

177177
/// The location of TLS Private Key file
178-
#[structopt(long, env = "P_TLS_KEY_PATH")]
178+
#[arg(long, env = "P_TLS_KEY_PATH")]
179179
pub tls_key_path: Option<PathBuf>,
180180

181181
/// The address on which the http server will listen.
182-
#[structopt(long, env = "P_ADDR", default_value = "0.0.0.0:8000")]
182+
#[arg(long, env = "P_ADDR", default_value = "0.0.0.0:8000")]
183183
pub address: String,
184184

185185
/// The local storage path is used as temporary landing point
186186
/// for incoming events and local cache while querying data pulled
187187
/// from object storage backend
188-
#[structopt(long, env = "P_LOCAL_STORAGE", default_value = "./data")]
188+
#[arg(long, env = "P_LOCAL_STORAGE", default_value = "./data")]
189189
pub local_disk_path: PathBuf,
190190

191191
/// Optional interval after which server would upload uncommited data to
192192
/// remote object storage platform. Defaults to 1min.
193-
#[structopt(long, env = "P_STORAGE_UPLOAD_INTERVAL", default_value = "60")]
193+
#[arg(long, env = "P_STORAGE_UPLOAD_INTERVAL", default_value = "60")]
194194
pub upload_interval: u64,
195195

196196
/// Optional username to enable basic auth on the server
197-
#[structopt(long, env = USERNAME_ENV, default_value = DEFAULT_USERNAME)]
197+
#[arg(long, env = USERNAME_ENV, default_value = DEFAULT_USERNAME)]
198198
pub username: String,
199199

200200
/// Optional password to enable basic auth on the server
201-
#[structopt(long, env = PASSOWRD_ENV, default_value = DEFAULT_PASSWORD)]
201+
#[arg(long, env = PASSOWRD_ENV, default_value = DEFAULT_PASSWORD)]
202202
pub password: String,
203203
}
204204

server/src/s3.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use aws_sdk_s3::RetryConfig;
77
use aws_sdk_s3::{Client, Credentials, Endpoint, Region};
88
use aws_smithy_async::rt::sleep::default_async_sleep;
99
use bytes::Bytes;
10+
use clap::Parser;
1011
use crossterm::style::Stylize;
1112
use datafusion::arrow::datatypes::Schema;
1213
use datafusion::arrow::record_batch::RecordBatch;
@@ -24,7 +25,6 @@ use object_store::limit::LimitStore;
2425
use std::fs;
2526
use std::iter::Iterator;
2627
use std::sync::Arc;
27-
use structopt::StructOpt;
2828

2929
use crate::alerts::Alerts;
3030
use crate::metadata::Stats;
@@ -48,7 +48,7 @@ const MAX_OBJECT_STORE_REQUESTS: usize = 1000;
4848

4949
lazy_static::lazy_static! {
5050
#[derive(Debug)]
51-
pub static ref S3_CONFIG: Arc<S3Config> = Arc::new(S3Config::from_args());
51+
pub static ref S3_CONFIG: Arc<S3Config> = Arc::new(S3Config::parse());
5252

5353
// runtime to be used in query session
5454
pub static ref STORAGE_RUNTIME: Arc<RuntimeEnv> = {
@@ -79,27 +79,27 @@ lazy_static::lazy_static! {
7979
};
8080
}
8181

82-
#[derive(Debug, Clone, StructOpt)]
83-
#[structopt(name = "S3 config", about = "configuration for AWS S3 SDK")]
82+
#[derive(Debug, Clone, Parser)]
83+
#[command(name = "S3 config", about = "configuration for AWS S3 SDK")]
8484
pub struct S3Config {
8585
/// The endpoint to AWS S3 or compatible object storage platform
86-
#[structopt(long, env = S3_URL_ENV_VAR, default_value = DEFAULT_S3_URL )]
86+
#[arg(long, env = S3_URL_ENV_VAR, default_value = DEFAULT_S3_URL )]
8787
pub s3_endpoint_url: String,
8888

8989
/// The access key for AWS S3 or compatible object storage platform
90-
#[structopt(long, env = "P_S3_ACCESS_KEY", default_value = DEFAULT_S3_ACCESS_KEY)]
90+
#[arg(long, env = "P_S3_ACCESS_KEY", default_value = DEFAULT_S3_ACCESS_KEY)]
9191
pub s3_access_key_id: String,
9292

9393
/// The secret key for AWS S3 or compatible object storage platform
94-
#[structopt(long, env = "P_S3_SECRET_KEY", default_value = DEFAULT_S3_SECRET_KEY)]
94+
#[arg(long, env = "P_S3_SECRET_KEY", default_value = DEFAULT_S3_SECRET_KEY)]
9595
pub s3_secret_key: String,
9696

9797
/// The region for AWS S3 or compatible object storage platform
98-
#[structopt(long, env = "P_S3_REGION", default_value = DEFAULT_S3_REGION)]
98+
#[arg(long, env = "P_S3_REGION", default_value = DEFAULT_S3_REGION)]
9999
pub s3_default_region: String,
100100

101101
/// The AWS S3 or compatible object storage bucket to be used for storage
102-
#[structopt(long, env = "P_S3_BUCKET", default_value = DEFAULT_S3_BUCKET)]
102+
#[arg(long, env = "P_S3_BUCKET", default_value = DEFAULT_S3_BUCKET)]
103103
pub s3_bucket_name: String,
104104
}
105105

0 commit comments

Comments
 (0)