Skip to content

Commit

Permalink
Upgrade clap to v4 (#3209)
Browse files Browse the repository at this point in the history
  • Loading branch information
gautamprikshit1 committed May 17, 2023
1 parent ea6d4fc commit 86f74cc
Show file tree
Hide file tree
Showing 15 changed files with 381 additions and 287 deletions.
92 changes: 86 additions & 6 deletions quickwit/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion quickwit/Cargo.toml
Expand Up @@ -52,7 +52,7 @@ byte-unit = { version = "4", default-features = false, features = ["serde"] }
bytes = "1"
chitchat = { git = "https://github.com/quickwit-oss/chitchat", rev = "4973853" }
chrono = "0.4.23"
clap = { version = "=3.1", features = ["env"] }
clap = { version = "4.2.4", features = ["env", "string"] }
colored = "2.0.0"
console-subscriber = "0.1.8"
criterion = { version = "0.4", features = ["async_tokio"] }
Expand Down
20 changes: 11 additions & 9 deletions quickwit/quickwit-cli/src/cli.rs
Expand Up @@ -18,7 +18,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use anyhow::bail;
use clap::{arg, Arg, ArgMatches, Command};
use clap::{arg, Arg, ArgAction, ArgMatches, Command};
use tracing::Level;

use crate::index::{build_index_command, IndexCliCommand};
Expand All @@ -27,7 +27,7 @@ use crate::source::{build_source_command, SourceCliCommand};
use crate::split::{build_split_command, SplitCliCommand};
use crate::tool::{build_tool_command, ToolCliCommand};

pub fn build_cli<'a>() -> Command<'a> {
pub fn build_cli() -> Command {
Command::new("Quickwit")
.arg(
Arg::new("no-color")
Expand All @@ -38,7 +38,7 @@ pub fn build_cli<'a>() -> Command<'a> {
)
.env("NO_COLOR")
.global(true)
.takes_value(false),
.action(ArgAction::SetFalse),
)
.arg(arg!(-y --"yes" "Assume \"yes\" as an answer to all prompts and run non-interactively.")
.global(true)
Expand Down Expand Up @@ -74,16 +74,18 @@ impl CliCommand {
}
}

pub fn parse_cli_args(matches: &ArgMatches) -> anyhow::Result<Self> {
pub fn parse_cli_args(matches: ArgMatches) -> anyhow::Result<Self> {
let (subcommand, submatches) = matches
.subcommand()
.ok_or_else(|| anyhow::anyhow!("Failed to parse command arguments."))?;
match subcommand {
"index" => IndexCliCommand::parse_cli_args(submatches).map(CliCommand::Index),
"run" => RunCliCommand::parse_cli_args(submatches).map(CliCommand::Run),
"source" => SourceCliCommand::parse_cli_args(submatches).map(CliCommand::Source),
"split" => SplitCliCommand::parse_cli_args(submatches).map(CliCommand::Split),
"tool" => ToolCliCommand::parse_cli_args(submatches).map(CliCommand::Tool),
"index" => IndexCliCommand::parse_cli_args(submatches.clone()).map(CliCommand::Index),
"run" => RunCliCommand::parse_cli_args(submatches.clone()).map(CliCommand::Run),
"source" => {
SourceCliCommand::parse_cli_args(submatches.clone()).map(CliCommand::Source)
}
"split" => SplitCliCommand::parse_cli_args(submatches.clone()).map(CliCommand::Split),
"tool" => ToolCliCommand::parse_cli_args(submatches.clone()).map(CliCommand::Tool),
_ => bail!("Subcommand `{}` is not implemented.", subcommand),
}
}
Expand Down
8 changes: 4 additions & 4 deletions quickwit/quickwit-cli/src/generate_markdown.rs
Expand Up @@ -31,7 +31,7 @@ async fn main() -> anyhow::Result<()> {
);

let app = build_cli()
.version(version_text.as_str())
.version(version_text)
.disable_help_subcommand(true);

generate_markdown_from_clap(&app);
Expand Down Expand Up @@ -91,7 +91,7 @@ fn markdown_for_command_helper(
println!("{about} ");
}
} else if let Some(about) = subcommand.get_about() {
if !about.trim().is_empty() {
if !about.to_string().trim().is_empty() {
println!("{about} ");
}
}
Expand Down Expand Up @@ -122,7 +122,7 @@ fn markdown_for_command_helper(
println!("quickwit {command_name}");
for arg in &arguments {
let is_required = arg.is_required_set();
let is_bool = !arg.is_takes_value_set();
let is_bool = !arg.get_action().takes_values();

let mut commando = format!("--{}", arg.get_id());
if !is_bool {
Expand Down Expand Up @@ -172,7 +172,7 @@ fn generate_markdown_from_clap(command: &Command) {
let command_name = command.get_name(); // index, split, source
println!("## {command_name}");
if let Some(about) = command.get_long_about().or_else(|| command.get_about()) {
if !about.trim().is_empty() {
if !about.to_string().trim().is_empty() {
println!("{about}\n");
}
}
Expand Down

0 comments on commit 86f74cc

Please sign in to comment.