From 212f96ccb118f393ed6d5141996e02ec3e3630d9 Mon Sep 17 00:00:00 2001 From: Jeff Dickey <216188+jdx@users.noreply.github.com> Date: Mon, 14 Oct 2024 13:57:01 -0500 Subject: [PATCH] fix: allow building without docs feature --- lib/Cargo.toml | 2 +- lib/src/parse.rs | 30 +++++++++++++++++++----------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/lib/Cargo.toml b/lib/Cargo.toml index c328e98..71deab5 100644 --- a/lib/Cargo.toml +++ b/lib/Cargo.toml @@ -37,7 +37,7 @@ xx = "1" regex = "1" [features] -default = [] +default = ["docs"] docs = ["tera"] [dev-dependencies] diff --git a/lib/src/parse.rs b/lib/src/parse.rs index e7ca0b4..010ce5b 100644 --- a/lib/src/parse.rs +++ b/lib/src/parse.rs @@ -7,8 +7,10 @@ use std::collections::{BTreeMap, VecDeque}; use std::fmt::{Debug, Display, Formatter}; use strum::EnumTryAs; +#[cfg(feature = "docs")] +use crate::docs; use crate::error::UsageErr; -use crate::{docs, Spec, SpecArg, SpecCommand, SpecFlag}; +use crate::{Spec, SpecArg, SpecCommand, SpecFlag}; pub struct ParseOutput { pub cmd: SpecCommand, @@ -108,9 +110,8 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result 2; out.errors - .push(UsageErr::Help(docs::cli::render_help(spec, &out.cmd, long))); + .push(render_help_err(spec, &out.cmd, w.len() > 2)); return Ok(out); } bail!( @@ -155,7 +156,7 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result 2)); return Ok(out); } } @@ -187,9 +188,8 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result 2)); return Ok(out); } } @@ -210,9 +210,8 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result 2; out.errors - .push(UsageErr::Help(docs::cli::render_help(spec, &out.cmd, long))); + .push(render_help_err(spec, &out.cmd, w.len() > 2)); return Ok(out); } bail!( @@ -228,9 +227,8 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result 2; out.errors - .push(UsageErr::Help(docs::cli::render_help(spec, &out.cmd, long))); + .push(render_help_err(spec, &out.cmd, w.len() > 2)); return Ok(out); } bail!("unexpected word: {w}"); @@ -251,6 +249,16 @@ pub fn parse_partial(spec: &Spec, input: &[String]) -> Result UsageErr { + UsageErr::Help(docs::cli::render_help(spec, cmd, long)) +} + +#[cfg(not(feature = "docs"))] +fn render_help_err(_spec: &Spec, _cmd: &SpecCommand, _long: bool) -> UsageErr { + UsageErr::Help("help".to_string()) +} + fn is_help_arg(spec: &Spec, w: &str) -> bool { spec.disable_help != Some(true) && (w == "--help"