Commit Graph

119 Commits

Author SHA1 Message Date
Janne Valkealahti
f5d6bae117 Handle option void type
- There's been no explicit support having argument void type
  as you would not be able to use with annotation model but
  surely can be wrapped as Type with CommandRegistration.
- For now change CommandInfoModel so that it uses empty string
  which is i.e. expected in help options which are just
  used as flags.
- It's outside of this commit to change parser to fail if
  user gives an argument value for this type of options.
- Fixes #586
2022-12-05 09:30:06 +00:00
Janne Valkealahti
ef191e66f3 Add support for global help options
- Essentially this commit registeres on default `--help` and
  `-h` options to every command and execution short circuits
  in presense of help options to help command.
- Add Supplier<CommandRegistration.Builder> as a bean which
  can be autowired registration beans.
- Make this common bean customisable via CommandRegistrationCustomizer.
- Change StandardMethodTargetRegistrar to use supplier so that
  annotated commands gets common customizations.
- Change sample commands to use supplier.
- Add new group, spring.shell.help to config props.
- Docs changes
- Fixes #582
- Fixes #585
2022-12-04 17:23:25 +00:00
Janne Valkealahti
61ae11bf94 Method execution should not error without value
- Do npe check when getting class type out from
  incoming value.
- Fix #572
2022-11-22 07:47:52 +00:00
Janne Valkealahti
ee7a9da4aa Fix warnings
- Fix some potential NPE cases.
- Fix warnings for missing @Nullable
2022-11-19 15:08:49 +00:00
Janne Valkealahti
83fb5f71fc Re-quote whitespace
- NonInteractiveShellRunner has a trouble where incoming
  argument loses info about "quoted" string which is handled
  by OS terminal.
- Add re-quoting in presense of a whitespace so that
  jline parser can detect it correctly.
- Fixes #567
2022-11-18 07:26:37 +00:00
Janne Valkealahti
46505e8b72 Polish 2022-10-22 06:17:24 +01:00
Janne Valkealahti
092a169fce Polish 2022-10-21 12:29:47 +01:00
Janne Valkealahti
b215705d49 Fix line split logic
- Fix issues where shows patsh were not correctly truncated
- Relates #556
2022-10-21 11:59:23 +01:00
Janne Valkealahti
4bab975ecf Add PathSearch component
- New PatchSearch component
- Allow user to define base directory for search
- Show (using single select list) search results
- Allow user to define search string
- Implement algorithms(start with exact-match and fuzzy-match) from fuzzy search tool (fzf)
- Sample "component path search" and change "component path" to "component path input"
- Fixes #556
2022-10-19 06:44:11 +01:00
Janne Valkealahti
3021704c29 Support hidden commands
- CommandRegistration now has a structure to define
  it beind hidden
- Modify relevant parts to filter out hidden commands
- Essentially command is hidden from all other than
  command execution
- Sample in e2e tests
- Fixes #416
2022-10-18 14:51:44 +01:00
Janne Valkealahti
feba345f00 Component text can be truncated
- BaseComponentContext has new field terminalWidth.
- StringToStyleExpressionRenderer contains new format
  for "truncate-" prefixes and this is something
  what template can use to instruct max length based
  on terminal width.
- Change single/multi selectors to use this feature.
- Fixes #543
2022-10-14 17:16:51 +01:00
Janne Valkealahti
4c48017a97 Implement more flexible error handling
- Add exception handling around new interface CommandExceptionResolver
  which allows to define a chain of resolvers to process errors before
  exception is bubbled up to result handlers.
- Will be foundation to add more sophisticated error handling features
  compared to what spring itself have for rest layer.
- Resolver returns CommandHandlingResult holder which further can be
  used to make a choice what to print into console and if spesific exit
  code should be used in non-interactive mode.
- Exception handling can be defined globally and per command giving
  a change for user to customise i.e. error thrown by parser.
- CommandParserExceptionResolver replaces CommandParserExceptionsExceptionResultHandler
  and provides more meaninful message for missing options.
- Fixes #503
2022-10-14 10:55:05 +01:00
Janne Valkealahti
3fe26025cd Process given values is a parser
- Modify CommandParser to convert given option value if its type is defined
- This change makes option default value to behave same as given value
  what comes for the actual value in a CommandContext.
- Fixes #548
2022-10-14 06:33:44 +01:00
Janne Valkealahti
6f220e2ea4 Fix deprecation in aot hints 2022-09-14 15:11:01 +01:00
guang384
37b0578c5d Wraps ExtendedArgumentList into CompletingParsedLine prevent WARNING during startup.
- Idea/hack copied from jline LineReaderImpl
- Fixes #526
2022-09-12 09:22:48 +01:00
Janne Valkealahti
68af0bb804 Move runtime hints from sample to core
- Relates #490
2022-09-07 09:58:25 +01:00
Janne Valkealahti
7c4700b7b5 Fix next handling in ComponentFlow
- This fixes a bug where returning null from a next()
  didn't stop a flow.
- Fixes #510
2022-08-22 16:30:08 +01:00
Janne Valkealahti
eb82af42ed Polish javadocs 2022-08-18 08:34:13 +01:00
Janne Valkealahti
891e1e17ef Polish 2022-08-16 15:08:31 +01:00
Janne Valkealahti
a143d25ffc Apply correct completion
- This commit fixes two issues.
- Firstly complete with correct option as existing bug was
  to wrongly always complete with first option which used
  wrong provider.
- Secondly filter out duplicate option proposals giving better
  result when options is already in place.
- Fixes #495
2022-08-04 09:08:11 +01:00
Thibaut Gautier
23194d05e2 Fix ShellMethod not using context validator 2022-08-02 09:50:46 +01:00
Janne Valkealahti
e193ca1d24 Upgrade to Boot 3.x
- For now port spring-native to framework config.
- 3rd party configs should go somewhere else.
- Fix changes from javax to jakarta.
- Change java settings as we now require jdk 17.
- Fixes #385
2022-07-24 08:07:14 +01:00
Janne Valkealahti
153f9e70a2 Fix tests
- Take2
- Relates to changes in #476
2022-07-20 10:10:58 +01:00
Janne Valkealahti
0fd67f2fad Fix tests
- Relates to changes in #476
2022-07-20 09:29:32 +01:00
Janne Valkealahti
d81e2614e3 Fix styling issue
- For title styling change from bold,fg:bright-white
  to bold which should work better with different
  terminal color settings as forcing it into bright white
  is a bad idea.
- Fixes #476
2022-07-20 09:01:05 +01:00
Drevsh
2862cc855e Add default selection to MultiItemSelector
- Added default selection to items
- Added correct styling for disabled but default selected item
- Added missing license header
- Added missing javadoc
- Added default selection to sample/doc code
2022-07-20 08:17:24 +01:00
Janne Valkealahti
5ba8e185bc Fix method argument without ShellOption
- For annotated methods with arguments, change default arity
  to zero with booleans and one everything else regardless
  if @ShellOption is defined or not.
- OptionArity.ZERO_OR_ONE had wrong upperbound value, change
  from MAX to 1.
- These modification should take us a bit closer to old
  shell functionality and what ShellOption documents for arity.
- For old functionality I'm referring to method
  `add(int a, int b)` and/or having @ShellOption and/or without
  arity setting.
- Fixes #446
2022-07-14 20:21:52 +01:00
Janne Valkealahti
32f77c1917 Rework completion interfaces
- Use same interface type in a generic interactive completions
  in a method level and option value level.
- Change CompletionResolver to have same function signature
  as with options and use CompletionContext to keep
  relevant information.
- Fixes #449
2022-07-06 09:02:06 +01:00
Janne Valkealahti
5eaa5dd093 Implement interactive completion
- This is a re-implementation of a interactive completion
  with breaking changes as it moves away from a direct use
  of a MethodParameter in favour of a CommandRegistration
  and its option definitions.
- Fixes #449
2022-06-28 14:10:23 +03:00
Janne Valkealahti
195d1d00ab Components can't use interactive mode without tty
- Adding a concept of no-tty which in this commit simply
  tracks DumbTerminal as jline creates that if there nothing
  better.
- For components without tty don't go to interaction loop.
- For new sample show that we can at least manually handle
  required option with a flow while command option is not
  required.
- Fixes #444
2022-06-15 09:56:14 +01:00
Janne Valkealahti
39c01fe00b Fix availability feature
- Bring back some missing functionality which got missing
  during the rework to new command model.
- Polish some classes.
- Restore origin sample.
- Add availability things into help templates and its
  representation model.
- Fixes #423
2022-06-14 11:51:50 +01:00
Janne Valkealahti
25721dd63d ConfirmationInput should have resultValue
- Add flow hooks to ConfirmationInput so that user
  is able to pass a flag from an options so that
  component can bypass interactive mode.
- Fixes #445
2022-06-13 09:27:16 +01:00
Janne Valkealahti
073cd8562c Rework themes support
- Add theme settings for figures.
- Settings for styles are now in it own class and
  ThemeSettings are wrapping those.
- Prefixed formatting string to have `style-` prefix.
- Templates can now use added `figures` dictionary which
  is resolved per activated theme.
- Create `dump` theme.
- New `ThemeActive` interface where default impl uses dump
  theme if `CI` or `NO_COLOR` env is set.
- Rework existing templates.
- Fixes #442
2022-06-10 13:56:21 +01:00
Janne Valkealahti
fa65a2308e Support option label
- This adds `label` to `CommandOption` which is then used
  in a Help instead of type.
- Fixes #424
2022-06-08 07:39:44 +01:00
Janne Valkealahti
8548828873 Polish contribution 2022-06-07 18:23:41 +01:00
Yubi Lee
38ce78434a Capturing CTRL+D EOF to exit the shell
* Capturing CTRL+D (EOF) to exit the shell
* replace junit to assertj
* fix hang on testing
2022-06-07 18:20:52 +01:00
Janne Valkealahti
7201a25567 Make ConversionService customisable
- Add ShellConversionServiceSupplier interface to define
  shell spesific ConversionService so that we don't
  get trouble with other services in boot.
- Fixes #435
2022-05-31 12:58:10 +01:00
Janne Valkealahti
3891a8b375 Add support for exit codes
- New configurations to CommandRegistration
- Re-using exit code concepts from boot
- Handling exit codes only in non-interactive mode
- Adding e2e commands and tests for better coverage
- Fixes #431
2022-05-31 07:49:50 +01:00
Janne Valkealahti
9779b5c729 Better errors with non-interactive mode
- Change how errors are printed for interactive
  vs non-interactive mode.
- This now changes behaviour so that stacktrace is printed
  if non-interactive mode is active so that user has a change
  to see the full error.
- Fixes #427
2022-05-27 09:09:21 +01:00
Janne Valkealahti
bd9ab62013 Rework help command
- Change help command output to get templated using
  model classes.
- Remove things around ParameterDescription as those are
  replaced with template classes.
- Fixes for native configs.
- For now availability and aliases are removed from
  help to get back in better form.
- Aliases has been partly introduced to structure.
- Fixes #422
2022-05-26 07:45:35 +01:00
Janne Valkealahti
baf8346063 Change help to description in command registration
- Fixes #421
2022-05-18 08:59:57 +01:00
Janne Valkealahti
c7d3eb15b4 Expose CommandRegistration in CommandContext
- Fixes #420
2022-05-18 08:18:38 +01:00
Janne Valkealahti
57f6cff7c6 Convert default value
- Change parser to user conversion service to attempt
  conversion from a default value to an expected type.
- Make more use of shellConversionService bean so that
  we use the one which can be customized.
2022-05-18 08:00:49 +01:00
Janne Valkealahti
6a1158dc12 Make history file path configurable
- UserConfigPathProvider interface to provid "user-level"
  config directory which can be used within a shell.
- New options which can be used to configure behaviour.
  spring.shell.history.enabled
  spring.shell.history.name
  spring.shell.config.location
  spring.shell.config.env
- Fixes #417
2022-05-17 18:29:58 +01:00
Janne Valkealahti
d49429975d Expose default option in SingleItemSelector
- Tweak flow framework so that single item selector
  can be configured with a default item which is then
  "exposed" automatically so that user can just hit enter.
- Fixes #414
2022-05-13 15:38:37 +01:00
Janne Valkealahti
75ff6e976f Fix use of default values
- Change parsing to extract and use option default value
  and also hook it with @ShellOption.
- Fixes #409
2022-05-11 07:23:11 +01:00
Janne Valkealahti
8a23518b84 Rework command subsystem
- Focus of these changes are to introduce a new command system based on
  real registrations (new way) instead of continuously (old way) resolve
  methods and its parameters via reflection.
- There's a lot of changes as this resolution via reflection had its
  hooks almost everywhere and thus most changes are just refactorings.
- Order to understand real changes I'd start to look classes under
  `org.springframework.shell.command` package as it defines new registration,
  catalog and parser classes. Also samples contain new classes to demonstrate
  new functionality.
- Fixes #380
2022-05-06 08:32:53 +01:00
Janne Valkealahti
30e7c4d370 Add auto-config for ComponentFlow
- ComponentFlowAutoConfiguration which creates a builder bean
  and configures ComponentFlowCustomizer to set needed
  defaults for terminal, resource loader and template executor.
- Fixes #387
2022-03-05 09:37:27 +00:00
Janne Valkealahti
85976cff48 Native support for JCommander
- Fixes #340
2022-03-05 08:18:28 +00:00
Janne Valkealahti
c532dc227e Flow system for UI components
- Implement basic flow system with builder patterns
  to easily use components and hook those together
  as a flow.
- Fixes #364
2022-03-03 15:45:02 +00:00