https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43546

--- Comment #1 from Martin Renvoize (ashimema) 
<[email protected]> ---
Created attachment 206078
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=206078&action=edit
Bug 43546: Add Getopt::Long::Descriptive and convert cart_to_shelf.pl

Koha's command-line scripts use plain Getopt::Long, which has no way to
declare an option as genuinely mandatory -- scripts that need one bolt
on their own ad hoc post-parse check, each with its own bespoke error
text and none of it understood by Getopt::Long itself.

This adds Getopt::Long::Descriptive to cpanfile and a thin
Koha::Script->describe_options wrapper that establishes the convention
for new/converted scripts: declare options (including required ones)
declaratively, get a consistent --help and a consistent, fail-fast
error for missing required options for free.

Getopt::Long::Descriptive's usage_desc format string always renders the
per-option description list immediately after itself, so there is no
built-in slot for trailing "Examples:" text. describe_options accepts
an optional trailing hashref with an 'epilog' key, printed after the
option list, so more complex scripts than this proof of concept can
still document usage examples. %c/%% are expanded in the epilog for
consistency with the main format string.

cart_to_shelf.pl is converted as a proof of concept, since its -h/--hours
option is genuinely mandatory today and was enforced only by a manual
"unless ($hours) { ... die }" check after parsing. Its short description
and example, previously in a hand-rolled usage heredoc, are preserved
via the new format string and epilog.

This is a small, staged first step, not a mass conversion. The other
cronjobs scripts are left on plain Getopt::Long for now.

Test plan:
1. Update Perl dependencies (Getopt::Long::Descriptive is a new
   cpanfile requirement, already present on most systems as a
   transitive dependency, but confirm it's importable):
     perl -MGetopt::Long::Descriptive -e 1
2. Run:
     misc/cronjobs/cart_to_shelf.pl --help
   Confirm it prints a short description, the --hours/--help options,
   and a worked example -- and exits 0.
3. Run the script with no options:
     misc/cronjobs/cart_to_shelf.pl
   Confirm it fails immediately with a clear "Mandatory parameter
   'hours' missing" error and the usage text, without querying the
   database, and exits non-zero.
4. Set an item's location to CART (e.g. via the staff interface or
   directly in the items table), then run:
     misc/cronjobs/cart_to_shelf.pl --hours 0
   Confirm the item's location is reverted to its original shelving
   location, same as before this patch.
5. Confirm koha-qa.pl passes for the changed files.

Co-Authored-By: Claude Sonnet 5 <[email protected]>

-- 
You are receiving this mail because:
You are watching all bug changes.
_______________________________________________
Koha-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]
website : http://www.koha-community.org/
git : http://git.koha-community.org/
bugs : http://bugs.koha-community.org/

Reply via email to