From c58c29156e6ec351bed035bcba7af5ced822f6b2 Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Fri, 14 Oct 2022 12:02:14 +0530 Subject: [PATCH 1/2] Add a top level server command to Parseable This ensures there is scope to add more commands later and also adheres to the standard practice. --- server/src/option.rs | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/server/src/option.rs b/server/src/option.rs index fd5a2aef6..682da81d8 100644 --- a/server/src/option.rs +++ b/server/src/option.rs @@ -45,7 +45,7 @@ pub struct Config where S: Clone + clap::Args + StorageOpt, { - pub parseable: Opt, + pub parseable: Server, } impl Config @@ -53,14 +53,13 @@ where S: Clone + clap::Args + StorageOpt, { fn new() -> Self { - let parseable = match Opt::::try_parse() { + let Cli::Server::(args) = match Cli::::try_parse() { Ok(s) => s, Err(e) => { - eprintln!("You can also use the --demo flag to run Parseable with default object storage. For testing purposes only"); e.exit(); } }; - Config { parseable } + Config { parseable: args } } pub fn storage(&self) -> &S { @@ -148,13 +147,26 @@ where } } -#[derive(Debug, Clone, Parser)] +#[derive(Parser)] // requires `derive` feature #[command( name = "Parseable", - about = "Configuration for Parseable server", + bin_name = "parseable", + about = "Parseable is a log storage and observability platform.", version )] -pub struct Opt +enum Cli +where + S: Clone + clap::Args + StorageOpt, +{ + Server(Server), +} + +#[derive(clap::Args, Debug, Clone)] +#[clap( + name = "server", + about = "Start the Parseable server", +)] +pub struct Server where S: Clone + clap::Args + StorageOpt, { @@ -222,7 +234,7 @@ where pub demo: bool, } -impl Opt +impl Server where S: Clone + clap::Args + StorageOpt, { From 9cd73b29ca7f571950177566adbe32bc87e13147 Mon Sep 17 00:00:00 2001 From: Nitish Tiwari Date: Fri, 14 Oct 2022 12:06:57 +0530 Subject: [PATCH 2/2] fix fmt --- server/src/option.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/server/src/option.rs b/server/src/option.rs index 682da81d8..c1ea351b0 100644 --- a/server/src/option.rs +++ b/server/src/option.rs @@ -162,10 +162,7 @@ where } #[derive(clap::Args, Debug, Clone)] -#[clap( - name = "server", - about = "Start the Parseable server", -)] +#[clap(name = "server", about = "Start the Parseable server")] pub struct Server where S: Clone + clap::Args + StorageOpt,