Skip to content

Commit

Permalink
feat: Add env_logger backend
Browse files Browse the repository at this point in the history
  • Loading branch information
ysthakur committed Aug 8, 2023
1 parent 77471e4 commit 9c9633c
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
60 changes: 60 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
clap = { version = "4.3", features = ["derive"] }
env_logger = "0.10"
flate2 = "1.0"
log = "0.4"
regex = "1.9"
Expand Down
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ fn gen_shell(
}

fn main() -> Result<()> {
env_logger::init();

let args = CLI::parse();

let mut cfg = ManParseConfig::new()
.exclude_dirs(args.dirs_exclude.unwrap_or_default())
.exclude_sections(args.sections_exclude)
.exclude_commands(args.exclude_cmds);
.exclude_commands(args.exclude_cmds)
.search_subcommands(args.search_subcommands);
if let Some(cmds) = args.cmds {
cfg = cfg.restrict_to_commands(cmds);
}
if args.search_subcommands {
cfg = cfg.search_subcommands();
}

let res = cfg.parse()?;
gen_shell(args.shell, res, &args.out)?;
Expand Down
11 changes: 6 additions & 5 deletions src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ mod type1;

use anyhow::{anyhow, Result};
use flate2::bufread::GzDecoder;
use log::{debug, error, warn};
use log::{debug, error, trace, warn};
use regex::Regex;
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -85,9 +85,9 @@ impl ManParseConfig {
Ok(self)
}

/// Search for subcommands (off by default)
pub fn search_subcommands(mut self) -> Self {
self.search_subcommands = true;
/// Whether to search for subcommands (false by default)
pub fn search_subcommands(mut self, search: bool) -> Self {
self.search_subcommands = search;
self
}

Expand Down Expand Up @@ -191,9 +191,10 @@ fn parse_all_manpages(

for (cmd, manpage) in manpages {
if let Ok(text) = read_manpage(&manpage) {
let cmd_name = get_cmd_name(manpage.as_ref());
let cmd_name = get_cmd_name(&manpage);
match parse_manpage_text(&cmd_name, &text) {
Some(parsed) => {
trace!("Parsing man page for {} at {}", cmd_name, manpage.display());
// todo merge subcommands later instead
res.insert(
cmd_name,
Expand Down
6 changes: 5 additions & 1 deletion src/parse/type1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ fn make_arg(options: &str, desc: &str) -> Option<Arg> {
}

if forms.is_empty() {
debug!("No options found in {}", options);
debug!(
"No options found in '{}', desc: {}",
options.trim(),
&desc.trim()[..40]
);
return None;
}

Expand Down

0 comments on commit 9c9633c

Please sign in to comment.