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

            Bug ID: 43557
           Summary: Add declarative mutually-exclusive option support to
                    Koha::Script->describe_options
   Initiative type: ---
        Sponsorship ---
            status:
           Product: Koha
           Version: Main
          Hardware: All
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P5 - low
         Component: Command-line Utilities
          Assignee: [email protected]
          Reporter: [email protected]
        QA Contact: [email protected]
                CC: [email protected], [email protected]
  Target Milestone: ---

Bug 43546 added Koha::Script->describe_options, a thin wrapper round
Getopt::Long::Descriptive establishing a declarative convention for
command-line option parsing: options can be marked required, and a
positional-argument minimum can be declared, both enforced consistently
before script logic runs, instead of every script rolling its own
post-parse check and error text.

Several cron scripts have their own hand-rolled "these two options are
mutually exclusive" check, each with slightly different wording and
mechanism:

- misc/cronjobs/longoverdue.pl: --category/--skip-category,
  --library/--skip-library, --itemtype/--skip-itemtype (three separate
  pairs)
- misc/cronjobs/membership_expiry.pl: --active/--inactive
- misc/cronjobs/update_totalissues.pl: --since/--interval,
  --use-items/--incremental
- misc/cronjobs/process_message_queue.pl: --code/--exclude-code
  (already converted to describe_options on bug 43551, using a
  one-off $usage->die() check since this feature didn't exist yet)

That is seven pairs across four scripts, all reimplementing the same
check. Getopt::Long::Descriptive's own one_of constraint looks like a
fit at first glance, but testing shows it does not enforce exclusivity
at all when the sub-options are array/repeatable types (e.g. our
--code/--exclude-code, which both take multiple values): passing both
options together with values is silently accepted, which would be a
regression, not a fix.

This bug is to add a declarative "exclusive" key to the trailing
options hashref of Koha::Script->describe_options, alongside the
existing "args" key, e.g.:

    my $opt = Koha::Script->describe_options(
        '%c %o',
        [ 'category|c=s@',      'category codes to include' ],
        [ 'skip-category|C=s@', 'category codes to exclude' ],
        { exclusive => [ [qw(category skip_category)] ] },
    );

When more than one option in a declared exclusive group is supplied,
the script should die with a clear, consistent error and the usage
text, the same as a missing required option does today, instead of
each script writing its own pod2usage/die/$usage->die variant.

Test plan:
1. prove t/Koha/Script.t
2. Add regression tests covering: neither option given, one option
   given, both options given (dies with a clear message naming both
   options), and the fact that a bare optional-value flag with no
   value (see bug 37075) is not treated as "given" for this purpose.
3. koha-qa.pl passes for Koha/Script.pm

Sponsored-by: OpenFifth <https://openfifth.co.uk/>

-- 
You are receiving this mail because:
You are the assignee for the bug.
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