Skip to content

Commit

Permalink
[WIP] Improve CLI usage output
Browse files Browse the repository at this point in the history
  • Loading branch information
Zollerboy1 committed Jun 20, 2024
1 parent 4fb76b7 commit 96805a6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions driver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ color-print = "0.3.6"
derive_more = { workspace = true }
juice-core = { workspace = true }
juice-frontend = { workspace = true }
replace_with = "0.1.7"
tempfile = "3.10.1"
tokio = { version = "1.36.0", features = ["full"] }
which = "6.0.0"
Expand Down
10 changes: 10 additions & 0 deletions driver/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
use clap::{error::ErrorKind, Args, CommandFactory, Parser, Subcommand};
use juice_core::OutputStream;
use juice_frontend::{RunnerAction as FrontendAction, RunnerArgs as FrontendArgs};
use replace_with::replace_with_or_abort;

use crate::driver::{Error as DriverError, MainAction, MainArgs, Result as DriverResult};

Expand Down Expand Up @@ -85,6 +86,15 @@ mod private {
impl FrontendArgs {
pub fn validate(&self, mut cmd: clap::Command) {
if self.json && !(self.dump_parse || self.dump_ast) {
// This is an ugly hack to get the usage output to look kinda like it does for errors generated by clap
let bin_name = cmd.get_bin_name().unwrap_or("juice").to_string();
let cmd = if let Some(cmd) = cmd.find_subcommand_mut("frontend") {
replace_with_or_abort(cmd, |cmd| cmd.bin_name(format!("{} frontend", bin_name)));
cmd
} else {
&mut cmd
};

const MESSAGE: &str = color_print::cstr!(
"<bold>--json</bold> can only be used together with \
<bold>--dump-parse</bold> or <bold>--dump-ast</bold>"
Expand Down

0 comments on commit 96805a6

Please sign in to comment.