[Koha-devel] Conventions for CLI scripts

Robin Sheat robin at catalyst.net.nz
Thu Sep 18 03:51:17 CEST 2014


There's been talk of making a few conventions for the parameters to
command-line scripts.

The initial discussion was dealing with "test mode" where it runs
through all the actions but doesn't actually do anything, i.e. you know
if it'll complete successfully.

     1. There are two directions for this:
             I. By default the action will be performed, unless you add
                an argument (--dry-run for example.)
            II. By default the action will not be performed, unless you
                add an argument (--commit for example.)
     2. What do we want to call the options, whichever way is picked?
             I. Keeping in mind that some things (-c for example) can
                conflict with other conventions.
     3. Are there any other conventions we should deal with at the same
        time?

While I have your attention, we should be more careful about how the dry
run stuff is actually done. I've found one script that gives you a
different count if you're in dry run mode (e.g. it'll say "0 actions
done") which is strictly correct, but means you don't know if it's 0
because something's wrong, or because it's in dry run mode. Unless
there's a good reason, it's best to do everything in a commit, so
something like:

        $dbi->begin_work;
        ...do stuff...
        print "$count actions done.\n";
        if ($dry_run) {
        	$dbi->rollback;
        	print "Changes NOT committed.\n";
        } else {
        	$dbi->commit;
        }
        
This also has the side effect that if your program crashes in any mode,
you're not left with an inconsistent result. But mostly it means
that /everything/ will happen in exactly the same way no matter what,
except the results just won't be saved.
        
-- 
Robin Sheat
Catalyst IT Ltd.
✆ +64 4 803 2204
GPG: 5FA7 4B49 1E4D CAA4 4C38  8505 77F5 B724 F871 3BDF
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <http://lists.koha-community.org/pipermail/koha-devel/attachments/20140918/e6bc2310/attachment.pgp>


More information about the Koha-devel mailing list