Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Getopt-Long-Descriptive CPAN distribution.

Report information
The Basics
Id: 79600
Status: resolved
Priority: 0/
Queue: Getopt-Long-Descriptive

People
Owner: Nobody in particular
Requestors: blacky+perl [...] fluffbunny.de
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.092
Fixed in: (no value)



Subject: Automatically show default values in usage?
I think it would be really nice if G::L::D could be configured to automatically print an option's default if it is defined. Definition: [ 'port|p=i', "the port to connect to", { default => 79 } ], So instead of -p --port the port to connect to it would print -p --port the port to connect to (default: 79) It's probably a good idea to make this configureable so you have to manually enable this feature. (Keep current behaviour as default.)
Sounds cool, I'd love a patch for that.
Subject: Re: [rt.cpan.org #79600] Automatically show default values in usage?
Date: Sat, 15 Sep 2012 22:53:03 +0200
To: bug-Getopt-Long-Descriptive [...] rt.cpan.org
From: "Thomas Neumann" <blacky+perl [...] fluffbunny.de>
Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=79600 > > > Sounds cool, I'd love a patch for that.
[low hanging fruit] Unconditionally add the default to the output: diff --git a/Getopt-Long-Descriptive/lib/Getopt/Long/Descriptive/Usage.pm b/Getopt-Long-Descriptive/lib/Getopt/Long/Descriptive/Usage.pm index 063527d..8e99e50 100644 --- a/Getopt-Long-Descriptive/lib/Getopt/Long/Descriptive/Usage.pm +++ b/Getopt-Long-Descriptive/lib/Getopt/Long/Descriptive/Usage.pm @@ -58,6 +58,12 @@ sub option_text { my @desc = $self->_split_description($length, $desc); + # add default value if it exists + if ( $opt->{constraint}->{default} ) { + my $dflt = $opt->{constraint}->{default}; + push @desc, "(default value: $dflt)"; + } + $string .= sprintf "$spec_fmt %s\n", $spec, shift @desc; for my $line (@desc) { $string .= "\t"; Let's see if I can add the conditional too.
Subject: Re: [rt.cpan.org #79600] Automatically show default values in usage?
Date: Sat, 15 Sep 2012 23:34:41 +0200
To: bug-Getopt-Long-Descriptive [...] rt.cpan.org
From: "Thomas Neumann" <blacky+perl [...] fluffbunny.de>
"show_defaults - a [yes|no] value which controls whether an option's default value (if applicable) is shown as part of the usage message (for backward compatibility this defaults to 'no')" 'show_defaults' = undef or 'no' ------------------------------------------------------------------ setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> -s --show-testcases show all available testcases ------------------------------------------------------------------ 'show_defaults' = 'yes' ------------------------------------------------------------------ setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> -s --show-testcases show all available testcases ------------------------------------------------------------------ 'show_defaults' = 'YesSIR' (usage error) ------------------------------------------------------------------ ERROR: 'show_defaults' is neither 'yes' nor 'no'. Assuming 'no'. at ./setup-storage_test.pl line 67 setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> -s --show-testcases show all available testcases ------------------------------------------------------------------ Attached: diff against 0.92 <http://search.cpan.org/CPAN/authors/id/R/RJ/RJBS/Getopt-Long-Descriptive-0.092.tar.gz> so long and thanks for the fish^Wmodule

Message body is not shown because sender requested not to inline it.

Subject: Re: [rt.cpan.org #79600] Automatically show default values in usage?
Date: Sat, 15 Sep 2012 23:42:23 +0200
To: bug-Getopt-Long-Descriptive [...] rt.cpan.org
From: "Thomas Neumann" <blacky+perl [...] fluffbunny.de>
*erm* I botched copying the examples properly. Let me try again. 'show_defaults' = undef or 'no' ------------------------------------------------------------------ setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> [...] -t --testcase the testcases which should be run -r --repeat the number of repetitions [...] ------------------------------------------------------------------ 'show_defaults' = 'yes' ------------------------------------------------------------------ setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> [...] -t --testcase the testcases which should be run (default value: :all) -r --repeat the number of repetitions [...] ------------------------------------------------------------------ 'show_defaults' = 'YesSIR' (usage error) ------------------------------------------------------------------ ERROR: 'show_defaults' is neither 'yes' nor 'no'. Assuming 'no'. at ./setup-storage_test.pl line 67 setup-storage_test.pl [-chlqrstVv] [long options...] <some-arg> [...] -t --testcase the testcases which should be run -r --repeat the number of repetitions [...] ------------------------------------------------------------------
Thanks, I've applied this, but I've made show_defaults a boolean rather than a yes/no enum. -- rjbs