Commit graph

84 commits

Author SHA1 Message Date
Juerd Waalboer
d1c8c509f5 v5.0.0 2023-12-26 18:48:47 +01:00
Juerd Waalboer
bdd92748ab Add some backtracking control
Not terribly necessary here, because inputs are short, but it's a
good practice. I wish there was a way to just disable backtracking for
the entire regex since this kind of pattern doesn't need any of it.
2023-12-26 05:47:29 +01:00
Juerd Waalboer
0d3866a881 Use new split_input() for -c 2023-12-26 04:39:21 +01:00
Juerd Waalboer
abe0f21c6a input: allow "abort" as input to a plugin
I can't imagine this to be important but throughout the years it's been
expected by users that "abort" can be quoted and passed to a plugin like
one that prints barcodes.

It's still not possible to pass a literal string `abort` to a follow-up
prompt, leaving this feature only available to advanced users who (hope
to) know what they're doing.
2023-12-26 04:31:08 +01:00
Juerd Waalboer
45f7ccbe28 Improve error message 2023-12-26 04:06:22 +01:00
Juerd Waalboer
a1e5d310a9 prompt: support "quoted" terms and \-escapes
With fancy retry, of course :)
2023-12-26 03:51:57 +01:00
Juerd Waalboer
3c622ab6d4 Soft-require ';' after command arguments
Also: `next WORD if $word eq "\0SEPARATOR";` was in the wrong loop
(harmless until this change)
2023-12-26 01:01:04 +01:00
Juerd Waalboer
daf0077d0d Introduce ';' as command/transaction separator
There's a slight mismatch between what users experience as a command,
and how commands are defined in RevBank. Specifically, the common input
"<productid> <username>" is two separate commands: the first adds the
product to the cart, the second finalizes the transaction. This also
means that "<productid> <username> <productid> <username>" was four
separate commands, resulting in TWO transactions.

That's all fine and useful, but when using this advanced input method,
where input is split on whitespace, it lead to unexpected results if
there are insufficient arguments for the follow-up questions of a
command. For example, "take jantje 10 take pietje 10" will interpret the
second "take" as the description, then "pietje" als the first command of
a new transaction, and finally, "10" which is typically not a valid
command. It is much more likely that the user intended two separate
"take" commands and just forgot to provide the description argument, but
RevBank had no way of inferring that intent.

From this commit on, whenever the user intends to enter further input
words beyond the one that finalizes a transaction ($cart->checkout), a
';' is required. If trailing input is present, the checkout is refused
and the user gets a retry prompt.

Similarly, if the user indicates the intention of having finished a
command by inserting a ';' while there are insufficient words in the
command line to satisfy all follow-up prompts (command arguments), the
rest of the command line is rejected with a retry prompt.

There is, however, still no specific requirement for a ';' separator
after a command that does not finalize a transaction (e.g. "<productid>
<username>" or even "<productid> x2 <productid> <username>" remains
valid), or for a command that precedes a ';' to finalize a transaction
(e.g. "<productid>; <username>;" is also valid).

This change catches many, but not all, mistakes.
2023-12-26 00:21:01 +01:00
Juerd Waalboer
3dab71fdbf support simple arithmetic (only + and -) for monetary amounts 2023-12-25 00:33:46 +01:00
Juerd Waalboer
3470ebeb1c Explicitly use Perl 5.32
Was already implicitly required (since 59387ddb) because RevBank::Amount
uses the "isa" feature, which was introduced in Perl 5.32 (but no longer
experimental since 5.36, not 5.32 as the old comment said).

Perl 5.32 was released in June 2020, and ships with Debian bullseye
("oldstable") which was released in August 2021.
2023-12-12 00:28:17 +01:00
Juerd Waalboer
ff819c25e2 No space before first word when it is REJECTed
Cosmetic bug fix
2023-11-24 06:20:34 +01:00
Juerd Waalboer
52749df5f3 Ignore all hook exceptions except in hook_checkout_prepare
A space had a custom plugin that died during hook_checkout, which caused
the CHECKOUT lines to be logged without the corresponding BALANCE, and
indeed no account balances were updated. While the plugin had a bug, it
should not cause a half transaction in RevBank.

After some hesitation, I went with ON ERROR RESUME NEXT because if a
hook throws an exception, that should not interfere with other plugins
(the hook can return ABORT if this it was intentional), including the
calling plugin. An error message is printed (but not logged... TODO: add
hook_plugin_fail to plugins/log) but the show must go on.

During hook_checkout_prepare, however, nothing is set in stone yet, so
this could be used for something that might die, and this instance of
call_hooks() is now the one place where a failing hook should result in
the transaction getting aborted. For this, call_hooks() now returns a
success status boolean. Maybe it would make sense in more places, but I
didn't identify any such calls yet.

RevBank::Cart->checkout used to return a success status boolean, but it
could just as well just die (indirectly, to abort the transaction) since
it can't be called a second time within the same transaction anyway
(because ->set_user must be called exactly once), so continuing with the
same transaction can't result in anything useful anyway.

In some places, error messages were slightly improved to contain a bit
more information.
2023-11-24 05:15:22 +01:00
Juerd Waalboer
7dd94eda9b Add assertions
There should already be external checks to prevent double entries in
revbank.accounts, but better safe than sorry.
2023-11-05 21:19:17 +01:00
Juerd Waalboer
d54428b092 Add support for user-accessible accounts that are excluded from grandtotal 2023-11-02 05:33:33 +01:00
Juerd Waalboer
df8c84672d tail/users: fix warning when used with old log files 2023-11-02 04:45:03 +01:00
Juerd Waalboer
1156864fd2 v4.1.0
- New internal feature: $plugin->Tab($method)
- `adduser` has an additional check
- Tiny bug fixes
2023-11-02 04:39:57 +01:00
Juerd Waalboer
8956d8a483 Move :Tab introspection from main:: to RevBank::Plugin
- Exposes the introspection as a public method.
- Removes undocumented support for NOABORT special-case.
2023-11-02 03:16:55 +01:00
Juerd Waalboer
560242a4bc Bump version to 4.0.0; change transaction ID scheme 2023-09-20 20:15:43 +02:00
Juerd Waalboer
fbb178d5ac Formal mechanism for retrying input
This allows for alias plugins with better error messages and better
logging than with the $_[2] =~ s/// hack.
2023-09-18 01:31:13 +02:00
Juerd Waalboer
6f110ee783 Update shebang to use /usr/bin/env 2023-08-21 03:43:52 +02:00
Juerd Waalboer
459e5619a7 Place cursor at start of rejected input instead of end
The cursor was placed after the rejected input, both to indicate where
the mistake was, and to make it easy to <backspace> it out. But since
"retry" is only used when there are trailing words, that means the
cursor would be placed on the space between the mistake and the trailing
input. By putting it at the first character of the rejected input, it
is less visually ambiguous. The user can now use <delete> instead of
<backspace>.
2023-07-12 22:12:30 +02:00
Juerd Waalboer
06d4591e8a Fix tab completion bug
When there were several matches that shared the same common prefix, but
with a different case, readline would eat the input from the case
sensitive longest common prefix up to where the case began to differ.

e.g. when "ibutton" and "iButton-touwtje" were available, typing
"ibu<tab>" would truncate the input to just "i" and on second tab show
both matches, but without ever completing beyond the "i".
2023-02-22 01:39:13 +01:00
Juerd Waalboer
fffb2d72e9 Fix deduplication bug, refactor deduplication to own plugin
(Bumps version to 3.8 because admins should update the plugin list.)

Deduplication didn't work on quantified additions, i.e. if you added
"20x clubmate" when there was already clubmate in the cart, it would add
just ONE item, and have a lingering message that the next thing would be
multiplied by 20.

This old bug was especially annoying if there is a barcode "20x
clubmate" to scan 20 bottles (which is the size of a crate), and this is
repeated.

The fix also uncovered another bug: newly added entries were selected
too early. There are two hooks, hook_add_entry and hook_added_entry, and
of course the selection should happen in between, not before the former.
No entry in UPGRADING.md, because I think it is extremely unlikely that
any plugin author will have used the selection feature yet, which is
very new.
2023-02-12 17:53:14 +01:00
Juerd Waalboer
9045eb7ff4 Don't tab complete invalid input
Products and users that begin with `+` are internal, as are users that
begin with `-`. These should be excluded from tab completion.
2023-01-30 17:19:50 +01:00
Juerd Waalboer
382940bfc9 Show unmodified input in error message 2023-01-30 06:12:23 +01:00
Juerd Waalboer
16d530ae16 Allow hook_prompt to mutate the prompt, like before, and use that
This functionality was accidentally broken by eed0db78

Also: ignore readline terminal sequence (\x01...\x02) in detection of ">"
2023-01-19 03:04:35 +01:00
Juerd Waalboer
50d93b3f6e v3.7
New core functionality (commit 11ca0a86) warrants new version number.
2023-01-16 03:18:06 +01:00
Juerd Waalboer
6089e212dc Release locks on abort
Fixes deadlock if hook_checkout returns ABORT.

One of these days I want to implement the abort mechanism through
exceptions, even though that means handling it explicitly in more
places. Or maybe *because* that means handling it explicitly in more
places.
2023-01-16 01:17:33 +01:00
Juerd Waalboer
da523f8daa v3.6: products overhaul
New features, new documentation.
2022-12-25 05:32:00 +01:00
Juerd Waalboer
4c380a8ac4 Fix bug in REJECT handling
Next input would not be split.

    > withdraw 1
    Pending:
	1.00 Withdrawal
    Enter username to deduct 1.00 from your account; type 'abort' to abort.

    > undo
    Undo is not available mid-transaction. Enter 'abort' to abort.
    > undo 123
    undo 123: No such product, user, or command.

Of course, "undo 123" as top-level input should have been split on
whitespace.

Top-level input is handled by the 'command' method, so that should be a
reliable way to detect that the prompt is a top-level prompt, rather
than a follow-up prompt. Keeping an additional global boolean was a dumb
approach anyway.
2022-08-30 22:50:04 +02:00
Juerd Waalboer
43a1990974 bump to v3.5; add built-in editor 2022-08-30 20:45:01 +02:00
Juerd Waalboer
441bf05fde Bump to v3.4; make all transactions balanced using hidden accounts
See UPGRADING.md for details.
2022-06-11 18:51:26 +02:00
Juerd Waalboer
f262bce57c Split "help" into "help" and "help2"; ditch pager 2022-06-11 16:31:44 +02:00
Juerd Waalboer
a7a5f14e0c Introduce 'withdraw', remove "withdrawal or unlisted" feature.
This should have been done much earlier, but wasn't done for nostalgic reasons.
To new users, it didn't make sense that you could just enter an amount, and
revbank would just accept that as "withdrawal or unlisted product". It existed
for backwards compatibility with the very first revbank version, which didn't
have a product list, and which was not yet used with a barcode scanner. You
would simply enter the amount and your name, and there were no further
statistics.

Nowadays, there are statistics that are messed up if you don't use the product
codes. And some people were looking for a withdrawal command, and try 'take' as
that seems closest to it, but which instead transfers money to another account.

Additionally, some texts were changed for improved clarity. ("Enter username to
pay", when withdrawing, was confusing: one expects money back, not to pay more.)
2022-06-04 02:41:17 +02:00
Juerd Waalboer
eed0db7897 Cleanup: use subroutine signatures, remove deprecated methods.
The signatures feature has been "experimental" since Perl 5.20 (May 2014), but
expected to stay. After 8 years I'm ready to take the risk :)

Have added Perl v5.28 (June 2018) as the minimum requirement, even though the
current revbank should work with 5.20, to see if this bothers any users. Perl
v5.28 is in Debian "buster", which is now oldstable.
2021-12-03 18:00:34 +01:00
Juerd Waalboer
38a0229899 Ditch floating point numbers, use cents instead; bump version to 3.2 2021-12-02 22:18:06 +01:00
Juerd Waalboer
df771e22fd Fix bug where follow-up prompt of second command would split on whitespace
Bug:

    > 2x unlisted 6
    Please provide a short description: bar foo
    foo: No such product, user, or command.

Fixed:

    > 2x unlisted 6
    Please provide a short description: bar foo
    Pending:
    2x {
        6.00 bar foo
    }
    Enter username to pay 12.00; type 'abort' to abort.
2020-09-07 02:27:25 +02:00
Juerd Waalboer
f312b31576 Fix POD/markdown 2020-06-10 21:05:20 +02:00
Juerd Waalboer
c3b0b86c97 No tab-completion for empty input
Old terminal takes about 1 minute to scroll the >9000 options...
2019-11-08 03:44:19 +01:00
Juerd Waalboer
da043ba2df New plugin: beep on error
If you computer beeps, that is. Most revbank setups run on raspberry pi's,
which don't beep...
2019-11-08 03:41:49 +01:00
Juerd Waalboer
5840b7bbac Tiny refactor 2019-11-06 19:23:44 +01:00
Juerd Waalboer
464a6db78c Whitespace tweaks (newlines)
Consistency: empty line before each prompt, but not after.
2019-11-06 19:13:12 +01:00
Juerd Waalboer
bb8c52b593 Do provide final cart when no pending cart was ever shown... 2019-11-06 06:13:18 +01:00
Juerd Waalboer
c9b704adca Make ">" prompt green 2019-11-05 06:16:54 +01:00
Juerd Waalboer
60f413eb73 Change main prompt to "> ".
This shifts the reader's focus to the messages from plugins, such as the
instruction to enter your username to pay.

It also looks nicer next to the new cleaner transaction overviews.
2019-11-05 03:14:41 +01:00
Juerd Waalboer
a16348055f Bump version to 3 :) 2019-11-05 02:04:12 +01:00
Juerd Waalboer
9e5ac6eb06 Update documentation on deprecations 2019-11-05 01:36:21 +01:00
Juerd Waalboer
735009a02d Remove deprecated plugins 'nyan' and 'game' 2019-11-04 19:43:51 +01:00
Juerd Waalboer
d8dfc2cde2 Retry after REJECT: edit bad input instead of aborting 2019-11-03 00:13:43 +01:00
Juerd Waalboer
0baa40b910 Ditch minor part of version number 2019-07-02 04:40:08 +02:00