1

I'm creating a console calculator-application of Roman numbers, as a practice, and using Java, Spring Shell 3.1.2. Right now it works correctly with Roman numbers like:

calc "V + V"
result: X
calc "V * V"
result: XXV

Since Roman numbers have no such thing as negative values, I would like to show the user a notification about this if he tries to enter a command:

calc "-V * V"
result: Roman numerals must be positive.

I've already created all the necessary logic in the code, through parsing and exceptions. However, I faced with another problem when checking how it works. I'm trying to write something like to the console myself, and the problem is:

calc "-V * V"
result: 
2001E:(pos 0): Unrecognised option '-V * V'
2000E:(pos 0): Missing mandatory option, longnames='expression', shortnames=''

I've tried various input options in the console, such as using the characters '-V*V' instead of '-V*V', missing characters and all that, but it doesn't help. The only thing that changes the situation at least a little is a similar input option: calc "V * -V"

Can you recommend me something? Is it possible somehow to turn-off flags option in the Spring Shell application?

  • In my opinion, the problem is with the command-line parsing. What is the code for parsing the command-line? – DevilsHnd - 退職した Jul 08 '23 at 18:41
  • 1
    What happens if you try `calc -- "-V * V"`? `--` is a common convention (established by POSIX) which says `--` is the last option argument; all arguments which follow are non-option arguments. Whatever argument parser you are using might support that. – Kaz Jul 08 '23 at 21:06
  • @DevilsHnd no, this is definitely not the problem, since according to the debug, the program does not even reach the entry point to the program via `@ShellMethod(value = "Calculate a numeral expression.", key = "calc")` – Mikhail Krasikov Jul 09 '23 at 07:16
  • @Kaz, it works after this, thanks! I think it's better than nothing in my case. Any other suggestions? – Mikhail Krasikov Jul 09 '23 at 07:21
  • 1
    @MikhailKrasikov The other suggestion would be not to worry about it. The minus signs are incorrect input. The only issue is that you don't have a perfectly consistent diagonstic for an incorrect input case. This is something that can be "documented away". The program does its best to diagnose the non-existence of the unary minus, except when command line option processing sees it first. It matters most to new users who are experimenting rather than reading documentation. Users who know that there is no minus don't benefit from perfect diagnosis any more. – Kaz Jul 09 '23 at 07:35
  • @Kaz, that's true, thanks! – Mikhail Krasikov Jul 09 '23 at 07:48

0 Answers0