Skip to content

Commit

Permalink
add hidden debug flag
Browse files Browse the repository at this point in the history
  • Loading branch information
brandonkal committed Jul 18, 2020
1 parent c271677 commit 01ac49d
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ fn main() {
if mdtxt.contains("inkjet_import:") {
mdtxt = execute_merge_command();
}
if opts.print_all {
print!("{}", mdtxt);
std::process::exit(0);
}
// By default subcommands in the help output are listed in the same order
// they are defined in the markdown file. Users can define this directive
// for alphabetical sort.
Expand All @@ -56,7 +60,7 @@ fn main() {

let root_command = inkjet::parser::build_command_structure(mdtxt.clone());
let about_txt = format!(
"Generated from the {} file.\nInkjet parser created by Brandon Kalinowski\n\n{}",
"Generated from {}.\nInkjet parser created by Brandon Kalinowski\n\n{}",
inkfile_path, root_command.desc
);
cli_app = cli_app.about(about_txt.trim());
Expand Down Expand Up @@ -195,12 +199,13 @@ struct CustomOpts {
interactive: bool,
preview: bool,
inkfile_opt: String,
print_all: bool,
}

// We must parse flags first to handle global flags and implicit defaults
fn pre_parse(mut args: Vec<String>) -> (CustomOpts, Vec<String>) {
let mut opts = CustomOpts::default();
let early_exit_modifiers = sset!["-h", "--help", "-V", "--version"];
let early_exit_modifiers = sset!["-h", "--help", "-V", "--version", "--inkjet-print-all"];
// Loop through all args and parse
let mut inkfile_index = 1000;
// If the first argument is a markdown file or '-' assume it is a inkfile arg
Expand Down Expand Up @@ -238,6 +243,9 @@ fn pre_parse(mut args: Vec<String>) -> (CustomOpts, Vec<String>) {
} else if arg == "--preview" || arg == "-p" {
opts.preview = true;
} else if !arg.starts_with('-') || early_exit_modifiers.contains(arg) {
if arg == "--inkjet-print-all" {
opts.print_all = true;
}
break; // no more parsing to do as a subcommand has been called
} else if arg == "-" {
continue; // stdin file input
Expand Down

0 comments on commit 01ac49d

Please sign in to comment.