Commit Graph

174 Commits

Author SHA1 Message Date
Janne Valkealahti
08515a2bdf ScriptShellRunner should have correct run detection
- Fix run detection so that @ has to be first character in a first
  argument and it also has additional content, like @path-to-file.
- This fixes issue where `--arg @` would blow up as an normal
  option argument.
- Backport #996
- Fixes #1003
2024-02-15 15:05:46 +00:00
Janne Valkealahti
65f0b317b7 Use CommandContext as method parameter
- With annotation(@Command) model it's now possible to just
  add CommandContext and it will get resolved and doesn't
  cause it to appear as an option.
- Backport #779
- Fixes #990
2024-01-26 13:52:46 +00:00
Janne Valkealahti
134af2dbd2 Fix alias handling with @Command annotation
- Revisit how alias commands are added using
  @Command annotation when using if/or on class
  and/or method level.
- With this change alias handling is more logical
  and there's better tests and docs.
- Backport #945
- Fixes #973
2024-01-13 12:35:35 +00:00
Janne Valkealahti
fc4a731f57 Restore cursor using normal capability
- Looks like some infocmp capabilities for making cursor visible
  using cvvis doesn't always work. So change to use cnorm instead.
- Terminal instruction of making cursor very visible with cvvis
  doesn't mean cursor should be visible, afaik, so i.e. screen
  or tmux didn't work.
- Backport #970
- Fixes #972
2024-01-12 15:44:58 +00:00
Janne Valkealahti
7be4920a47 Fix exception mapping with exit codes
- Migitates changed behaviour in boot how exceptions are
  handled thus caused trouble with exit code mappings
  on a shell side.
- Backport #961
- Fixes #962
2023-12-24 08:50:54 +00:00
Janne Valkealahti
2f186e3144 Restore old sorting behaviour
- In #946 we added new ways to add items to single selector while still
  keeping Map<String, String>. Order to keep old sorting behaviour
  we try to pass incoming map via new HashMap as that was a way it
  worked. This should limit risks for breaking things in a patch release.
2023-12-23 10:03:56 +00:00
Janne Valkealahti
7cf73bc0fc Add SelectItem to flow single selector api
- This change makes single/multi same on an api level
  where single selector used key/value map and multi
  selector used list of SelectItem's.
- We still keep use of map on a single select but those
  essentially go directly via SelectItem's.
- Backport #946
- Fixes #957
2023-12-18 10:04:45 +00:00
Janne Valkealahti
b024b3db3f Fix wrong parser message
- Parser error message gave wrong lower level arity value
  if option didn't have enough arguments
- Backport #930
- Fixes #939
2023-11-27 14:31:51 +00:00
MJ Gallego
649cb68c14 Completion proposal support for complete jline parameter
- to allow completing single argument with multiple tab clicks,
  for example file paths.
- Backport #512
- Fixes #836
2023-07-25 09:58:22 +01:00
Janne Valkealahti
9531504261 Polish error messages
- Polish mandatory option message by using
  same format as in 3.0.x. (old parser)
- Remove prefixed code/position parts from
  all messages coming from a parser. (new parser)
- Backport #815
- Fixes #816
2023-07-19 08:12:54 +01:00
Janne Valkealahti
051f7da5dc Add primary command feature
- NonInteractiveShellRunner can now shortcircuit into primary command
  just running it and passing args.
- Add hooks into autoconfig so that this is easy to configure.
- Backport #755
- Relates #799
2023-07-07 14:05:05 +01:00
Janne Valkealahti
ff60039c85 Fix alias usage with Command annotation
- Fix alias command extraction from existing @Command
  annotations so that we actually get multiple aliases
  defined if more than one defined on a method level.
- Fix rendering issue in a help stg template when
  multiple aliases exists.
- Backport #796
- Fixes #798
2023-06-22 16:37:06 +01:00
Janne Valkealahti
0edf4eb450 Fix parser handling of positional args
- Change to have better support for args like:

    "--arg1 a --arg2 b"
    "--arg1 a --arg2 b c"
    "--arg1 a c --arg2 b c"
    "c --arg1 a --arg2 b"

  where option can have default values and position of
  positional args doesn't matter that much.
- Make parser to be aware of if it's handling last option
  so that we can differentiate if error can be given i.e.
  with too many args, etc.
- Backport #795
- Fixes #797
2023-06-22 09:53:59 +01:00
Janne Valkealahti
d1592456a5 Make command not found configurable
- New CommandNotFoundResultHandler which handles
  CommandNotFound to be able to customize error shown.
- New CommandNotFoundMessageProvider which is a plain
  function given a "context" and returns a string.
  Context contains common info to provide better
  error messages.
- Default provider gives same message but
  removes long stacktrace(which previously originated
  from a common ThrowableResultHandler.
- Backport #778
- Relates #793
2023-06-20 12:33:54 +01:00
Janne Valkealahti
ee94ba37ef Add better support for modified option names
- Longnames in a command option if modified via
  name modifier didn't provide enough backmapping
  info for command execution experience being accurate.
- Add new getLongNamesModified() into CommandOption
  which is populated if name modifier is used.
- Add more hints in CommandExecution for modified
  option names.
- This should bring annotation, legacy annotation
  and programmatic commands up to date.
- Backport #777
- Fixes #783
2023-06-19 12:38:51 +01:00
Janne Valkealahti
7e634bb80e Polish 2023-06-13 15:45:38 +01:00
Janne Valkealahti
3d39ef3518 Discard empty args
- Take 2 of #763
- Revert changes in 06e89dcca3
  what comes for `ExtendedDefaultParser`.
- Discard empty args in a `Shell` coming from `ExtendedDefaultParser`
- `ExtendedDefaultParserTests` has more tests, some commented out, to
  see some differences for jline default parser impl. Something
  to get handled in #517
2023-06-12 10:12:52 +01:00
Janne Valkealahti
042d56e7e3 Add HandlerMethodArgumentResolver for @Option
- New OptionMethodArgumentResolver which is similar
  than ShellOptionMethodArgumentResolver for @ShellOption.
- Add missing annotation commands for e2e test command.
- Fixes #767
2023-06-07 15:28:57 +01:00
Janne Valkealahti
afacf86ac5 Add jna native hints for linux
- Need for libjnidispatch.so, CLibrary$termios
  and CLibrary$winsize.
- Fixes #762
2023-06-07 14:13:35 +01:00
Janne Valkealahti
06e89dcca3 ExtendedDefaultParser should not add empty arguments
- Fixes issue when last "word" is within quotes and
  cursor is at the end of a line which caused empty
  "word" string in an argument list.
- This then caused i.e. string option to have a collection
  as an input(if no arity settings used) and via
  spring conversions a comma were added.
- Fixes #763
2023-06-07 08:28:17 +01:00
Janne Valkealahti
af34526e82 Add hints for Availability targets
- Annotate ShellComponent with @Reflective and use custom
  AvailabilityReflectiveProcessor to find possible method
  targets returning Availability.
- Fixes #747
2023-06-01 21:17:29 +01:00
Janne Valkealahti
c125c46010 Add short options into valid tokens
- Add short options as valid tokens in a `CommandModel` so that Lexer
  create tokens with accurate info and doesn't then cascade this issue
  in Ast and Parser.
- Previously with a command `command -a aaa -b bbb` tokenisation resulted
  `COMMAND OPTION ARGUMENT ARGUMENT ARGUMENT` with multiple short options
  while it should have been `COMMAND OPTION ARGUMENT OPTION ARGUMENT`.
- Relates #757
2023-05-31 17:28:21 +01:00
Janne Valkealahti
b63aab08a9 Add input into ConfirmationInput
- Now displaying what user actually inputs
- Fixes #740
2023-05-20 17:20:46 +01:00
Janne Valkealahti
8bed75ad77 Support plain boolean without option annotations
- Fix so that we can have `boolean arg` without using
  `@Option` or `@ShellOption` defaulting to false.
- Fixes #744
2023-05-20 14:49:21 +01:00
Janne Valkealahti
a0ad3ad797 Support label with @Option
- Add `label` field into `@Option`. This sets option label if
  `label` field has any text.
- Fixes #732
2023-05-01 17:11:03 +01:00
Janne Valkealahti
9d27466c6a Support explicit arity min max with @Option
- @Option now has arityMin/arityMax which if defined,
  non-negative, are used instead of arity.
- Fixes #731
2023-05-01 08:36:41 +01:00
Janne Valkealahti
2e19929a32 Fix option type parsing
- In `CommandRegistration` add `ResolvableType` for `OptionSpec` giving
  more spesific handling of a type.
- In `CommandParser` handle source and target types so that we
  have generics with `List`, `Set` and arrays working better.
- In `HandlerMethodArgumentResolver` add better handling for
  `ConversionService` for generic types.
- In `StandardMethodTargetRegistrar` add better types via `ResolvableType`
  now that `CommandRegistration` support it.
- In `OptionConversionCommands` remove converter from `String` to `Set` as
  now things should work as is if generic in a `Set` has a converter.
- Backport #694 #699
- Fixes #700
2023-04-05 18:56:09 +01:00
Janne Valkealahti
64abc1da22 Fix positional args with new parser
- Better alignment for use of positional args without using
  an option.
- Should work similarly with old parsing framework.
- Change position where missing options are checked.
- Fixes #701
2023-04-05 13:42:22 +01:00
Janne Valkealahti
cfd2b7f72e Fix ConfirmationInput template message
- Fix confirmation-input-default.stg to use correct style
  names in format.
- Fixes #690
2023-03-17 08:40:41 +00:00
Janne Valkealahti
0363b38204 Polish 2023-03-13 08:56:42 +00:00
Janne Valkealahti
93f2cf00de Rename name to provider
- Align naming in CommandAvailability
- Relates #663
2023-03-13 08:54:23 +00:00
Simon Verhoeven
60126b9c47 Rename setMaskCharater to setMaskCharacter 2023-03-12 16:08:54 +00:00
Janne Valkealahti
eaa3e5caf9 OptionValues supports multiple resolvers
- Change ref field in OptionValues to providers
  takin an array.
- Relates #637
2023-03-05 16:38:01 +00:00
Janne Valkealahti
c46bf91dae Wrong arity for default boolean type
- Set boolean type arity zero or more as default.
- Fixes #675
2023-02-27 10:12:09 +00:00
Janne Valkealahti
9f16ccd57e Polish 2023-02-19 09:32:28 +00:00
Janne Valkealahti
cf1a6f7839 Add support defining Availability with annotated method
- This is for new annotation model
- @CommandAvailability which takes names of
  AvailabilityProvider beans supplying Availability info.
- Relates #663
2023-02-09 21:18:22 +00:00
Janne Valkealahti
75b8a0c90e Rework command parser
- Previously CommandParser contained parser which was
  scannerless type of brute force parsing of command
  line args.
- Contract in that old parser wasn't super clear what
  is its role with caller as it was given options
  and registration was parsed in a Shell class.
- Add completely new parser package which has better
  model and which will be much easier to modify for
  future needs.
- Change some interfaces around parsing so that we do
  as much in this new parsing model instead of pre-parsing
  something in a Shell class.
- We also try to move away from using exceptions as
  a message delivery which had its own problems. Instead
  introducing parser messages which gives better info
  when errors are detected.
- Add ParserConfig class which allows to expose settings
  to change some parser features. Later this will be
  exposed to user so that some features can be turned on/off
  for an actual shell needs.
- Fixes #646
2023-02-08 15:47:08 +00:00
Janne Valkealahti
e8d5d70792 Make annotated command visible to native
- Use @Reflective with @Command
- This should automatically register reflection hints
  and make native work again
- Relates #638
2023-02-08 14:04:42 +00:00
Janne Valkealahti
809e296e55 Handle arg looking options better
- Now lexing better with valid options
- Only report unrecognised option with double dash
  as current parser don't have structure to do
  deeper analysis.
- Fixes #651
2023-02-01 09:29:20 +00:00
Janne Valkealahti
3ce7afac6b CommandRegistration should return same options
- Cache created CommandOption(s) to return same instance.
- Fixes #648
2023-01-28 17:13:29 +00:00
Janne Valkealahti
de1a3baf18 New annotation model
- This is a first commit to add new annotation model
  which eventually will replace old legacy annotations
  like ShellComponent, ShellMethod, @ShellOption, etc.
- Adds subset of features needed for parity with manual
  use of CommandRegistration.
- Relates #637
- Relates #638
- Relates #639
- Relates #640
- Relates #641
2023-01-27 12:04:21 +00:00
Janne Valkealahti
d1c482cd49 OptionArity NONE value
- Fixes #644
2023-01-27 09:41:03 +00:00
Janne Valkealahti
2f298ccb6a Define CommandExceptionResolver bean order
- CommandParserExceptionResolver uses default bean
  order -100.
- Fixes #634
2023-01-25 17:57:13 +00:00
Janne Valkealahti
fb1616e0c6 Polish 2023-01-20 16:09:21 +00:00
Janne Valkealahti
624343ace2 Handle collection types in a parser
- Handle any option collection type so that list is generated for
  values, this then works well when actual type conversions happen.
- Fixes #630
2023-01-19 17:33:18 +00:00
Janne Valkealahti
25d249c28d Exclude ExitRequest from error handling
- Don't try to handle ExitRequest exception with error handling
  so that we're able to break out from a run loop with
  interactive shell.
- Fixes #624
2023-01-18 09:03:03 +00:00
Janne Valkealahti
6e1ca089d7 Replace parser string joining with list
- Issue in #622 is that its command type is `String` and internally
  some incoming arguments(it's List) were converted to String by
  joining with space. This caused one case with help command to get
  conversion via spring's ConversionService(CollectionToStringConverter)
  which joins by commas. That was we saw in failed example.
- Remove needed joins in CommandParser and let it just pass List which
  then works better with ConversionService.
- This then needs a `command` option type change from String to String[]
  which it really is as you should be able to give whole command as
  an argument.
- Fixes #622
2023-01-16 17:47:21 +00:00
Janne Valkealahti
a04091c08f Support modify option names
- New OptionNameModifier which is just a Function<String,String> to
  modify a name.
- Can be defined per option in CommandRegistration.
- Can be defined as global default as bean.
- Default implementation for common case types is enabled via boot's
  config props under spring.shell.option.naming.case-type
- Support facilities for camel, kebab, snake and pascal conversions.
- Fixes #621
2023-01-15 10:02:55 +00:00
Christian Niessner
448c507ce9 Allow Shell.input() to be overridden in subclasses
- the ssh-shell-spring-boot extensions needs to extend to override the Shell.input()
  method to handle the input provided via the SSH session properly
2023-01-13 18:05:35 +00:00
Janne Valkealahti
95e2829dc3 Revisit positional arguments
- Add better mapping logic
- Add better type conversion
- More docs for arity and positional option configuration
- Fixes #616
2023-01-13 15:11:38 +00:00