|
18 | 18 | */
|
19 | 19 | package org.apache.groovy.groovysh
|
20 | 20 |
|
| 21 | +import groovy.cli.internal.CliBuilderInternal |
| 22 | +import groovy.cli.internal.OptionAccessor |
21 | 23 | import org.apache.groovy.groovysh.jline.GroovyBuiltins
|
22 | 24 | import org.apache.groovy.groovysh.jline.GroovyCommands
|
23 | 25 | import org.apache.groovy.groovysh.jline.GroovyConsoleEngine
|
@@ -180,6 +182,39 @@ class Main {
|
180 | 182 | }
|
181 | 183 |
|
182 | 184 | static void main(String[] args) {
|
| 185 | + def cli = new CliBuilderInternal(usage: 'groovysh [options] [...]', stopAtNonOption: false, |
| 186 | + header: messages['cli.option.header']) |
| 187 | + cli.with { |
| 188 | + _(names: ['-cp', '-classpath', '--classpath'], messages['cli.option.classpath.description']) |
| 189 | + h(longOpt: 'help', messages['cli.option.help.description']) |
| 190 | + V(longOpt: 'version', messages['cli.option.version.description']) |
| 191 | + v(longOpt: 'verbose', messages['cli.option.verbose.description']) |
| 192 | + q(longOpt: 'quiet', messages['cli.option.quiet.description']) |
| 193 | + d(longOpt: 'debug', messages['cli.option.debug.description']) |
| 194 | + e(longOpt: 'evaluate', args: 1, argName: 'CODE', optionalArg: false, messages['cli.option.evaluate.description']) |
| 195 | + C(longOpt: 'color', args: 1, argName: 'FLAG', optionalArg: true, messages['cli.option.color.description']) |
| 196 | + D(longOpt: 'define', type: Map, argName: 'name=value', messages['cli.option.define.description']) |
| 197 | + T(longOpt: 'terminal', args: 1, argName: 'TYPE', messages['cli.option.terminal.description']) |
| 198 | + pa(longOpt: 'parameters', messages['cli.option.parameters.description']) |
| 199 | + pr(longOpt: 'enable-preview', messages['cli.option.enable.preview.description']) |
| 200 | + } |
| 201 | + OptionAccessor options = cli.parse(args) |
| 202 | + |
| 203 | + if (options == null) { |
| 204 | + // CliBuilder prints error, but does not exit |
| 205 | + System.exit(22) // Invalid Args |
| 206 | + } |
| 207 | + |
| 208 | + if (options.h) { |
| 209 | + cli.usage() |
| 210 | + System.exit(0) |
| 211 | + } |
| 212 | + |
| 213 | + if (options.V) { |
| 214 | + println render(messages.format('cli.info.version', GroovySystem.version)) |
| 215 | + System.exit(0) |
| 216 | + } |
| 217 | + |
183 | 218 | try {
|
184 | 219 | Supplier<Path> workDir = () -> Paths.get(System.getProperty('user.dir'))
|
185 | 220 | DefaultParser parser = new DefaultParser(
|
@@ -284,11 +319,16 @@ class Main {
|
284 | 319 | keyMap.bind(new Reference(Widgets.AUTOSUGGEST_TOGGLE), KeyMap.alt("v"))
|
285 | 320 | def init = configPath.getUserConfig('groovysh_init')
|
286 | 321 | if (init) {
|
287 |
| - systemRegistry.initialize(configPath.getUserConfig('groovysh_init').toFile()) |
| 322 | + systemRegistry.setConsoleOption() // initialize(configPath.getUserConfig('groovysh_init').toFile()) |
288 | 323 | }
|
289 | 324 |
|
290 |
| - println render(messages.format('startup_banner.0', GroovySystem.version, System.properties['java.version'], terminal.type)) |
291 |
| - println render(messages['startup_banner.1']) |
| 325 | + if (options.q) { |
| 326 | + println render(messages.format('cli.info.version', GroovySystem.version)) |
| 327 | + } else { |
| 328 | + println render(messages.format('startup_banner.0', GroovySystem.version, System.properties['java.version'], terminal.type)) |
| 329 | + println render(messages['startup_banner.1']) |
| 330 | + println render(messages['startup_banner.2']) |
| 331 | + } |
292 | 332 | println '-' * (terminal.width - 1)
|
293 | 333 | // for debugging
|
294 | 334 | // def index = 0
|
|
0 commit comments