Skip to content

Commit df40cfe

Browse files
committed
New option -d/--debug to print debug messages
For now prints parsed option definition.
1 parent 1859850 commit df40cfe

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

doc/parseargs.1.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ The calling script must provide the function `show_version` that displays the ve
6363
Produce code for named shell. Supported: `bash`, `ksh`, `zsh` and `sh`.
6464
Default: `sh`
6565

66+
*-d, --debug*::
67+
Enable debug output to STDERR.
68+
6669
*--help*::
6770
Print Parseargs help.
6871

src/main.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ const PARSEARGS_SHELL_VAR: &str = "PARSEARGS_SHELL";
4343
)]
4444
#[command(version)]
4545
struct CmdLineArgs {
46-
/// Definition of supported shell options
46+
/// Definition of supported shell options.
47+
/// Can be given multiple times.
4748
#[arg(short = 'o', long = "options", value_name = "OPT-DEFs")]
4849
options_list: Option<Vec<String>>,
4950

@@ -65,7 +66,7 @@ struct CmdLineArgs {
6566
#[arg(short = 'r', long = "remainder", value_name = "SHELL-VAR", value_parser = parse_shell_name, verbatim_doc_comment)]
6667
remainder: Option<String>,
6768

68-
/// Stop option processing on first none-option
69+
/// Stop option processing on first none-option.
6970
#[arg(short = 'p', long = "posix")]
7071
posix: bool,
7172

@@ -87,18 +88,18 @@ struct CmdLineArgs {
8788
#[arg(short = 's', long = "shell", value_name = "SHELL")]
8889
shell: Option<String>,
8990

90-
/// Print help
91+
/// Enable debug output to STDERR.
92+
#[arg(short = 'd', long = "debug")]
93+
debug: bool,
94+
95+
/// Print help.
9196
#[arg(long)]
9297
help: bool,
9398

94-
/// Print version
99+
/// Print version.
95100
#[arg(long)]
96101
version: bool,
97102

98-
// Disabled for now
99-
// /// enable debug output to STDERR.
100-
// #[arg(short = 'd', long = "debug")]
101-
// debug: bool,
102103
/// Shell script options
103104
#[arg(value_name = "SCRIPT-ARGS")]
104105
script_args: Vec<OsString>,
@@ -555,12 +556,22 @@ fn parseargs(cmd_line_args: CmdLineArgs) -> ! {
555556
});
556557
}
557558

559+
if cmd_line_args.debug {
560+
for oc in &opt_cfg_list {
561+
eprintln!("{:?}", oc);
562+
}
563+
}
564+
558565
// Determine shell. Either from option, environment var or the default.
559566
let shell = cmd_line_args
560567
.shell
561568
.clone()
562569
.unwrap_or(std::env::var(PARSEARGS_SHELL_VAR).unwrap_or(DEFAULT_SHELL.to_string()));
563570

571+
if cmd_line_args.debug {
572+
eprintln!("Shell: {}", shell);
573+
}
574+
564575
// get the shell templates
565576
let shell_tmpl = shell_code::get_shell_template(shell.as_str());
566577
if shell_tmpl.is_none() {

0 commit comments

Comments
 (0)