GCLI

Easier scripting with Groovy

License

License

Categories

Categories

CLI User Interface
GroupId

GroupId

fr.marcwrobel
ArtifactId

ArtifactId

gcli
Last Version

Last Version

0.0.5
Release Date

Release Date

Type

Type

jar
Description

Description

GCLI
Easier scripting with Groovy
Project URL

Project URL

https://github.com/marcwrobel/gcli
Project Organization

Project Organization

Marc Wrobel
Source Code Management

Source Code Management

https://github.com/marcwrobel/gcli

Download gcli

How to add to project

<!-- https://jarcasting.com/artifacts/fr.marcwrobel/gcli/ -->
<dependency>
    <groupId>fr.marcwrobel</groupId>
    <artifactId>gcli</artifactId>
    <version>0.0.5</version>
</dependency>
// https://jarcasting.com/artifacts/fr.marcwrobel/gcli/
implementation 'fr.marcwrobel:gcli:0.0.5'
// https://jarcasting.com/artifacts/fr.marcwrobel/gcli/
implementation ("fr.marcwrobel:gcli:0.0.5")
'fr.marcwrobel:gcli:jar:0.0.5'
<dependency org="fr.marcwrobel" name="gcli" rev="0.0.5">
  <artifact name="gcli" type="jar" />
</dependency>
@Grapes(
@Grab(group='fr.marcwrobel', module='gcli', version='0.0.5')
)
libraryDependencies += "fr.marcwrobel" % "gcli" % "0.0.5"
[fr.marcwrobel/gcli "0.0.5"]

Dependencies

provided (3)

Group / Artifact Type Version
org.codehaus.groovy : groovy-cli-commons jar 2.5.14
org.codehaus.groovy : groovy-sql jar 2.5.14
ch.qos.logback : logback-classic jar 1.2.3

Project Modules

There are no modules declared in this project.

Build Sonarcloud Status SonarCloud Coverage SonarCloud Vulnerabilities SonarCloud Bugs Maven Central

GCLI aims to make scripting with Groovy easier by providing opinionated utilities related to common concerns like logging or database accesses.

Requirements

Any script that uses gcli must use Java 8 or later and Groovy 2.5 or later.

Use it !

Here is a sample script that makes use of logging and database access capabilities :

#!/usr/bin/env groovy

import fr.marcwrobel.gcli.ScriptCliTexts
import groovy.sql.Sql
import groovy.util.logging.Slf4j

@Grab(group = 'fr.marcwrobel', module = 'gcli', version = '0.0.5')
@Grab(group = 'ch.qos.logback', module = 'logback-classic', version = '1.2.3')

@GrabConfig(systemClassLoader = true)
@Grab(group = 'org.postgresql', module = 'postgresql', version = '42.2.20')

final class CommandConfiguration extends DatabaseConfiguration {
  CommandConfiguration(Class<?> scriptClass) {
    super(new ScriptCliTexts(scriptClass))
  }
}

@Slf4j
class Command {

  private final CommandConfiguration config

  Command(CommandConfiguration config) {
    this.config = config
  }

  int execute() {
    try {
      config.withSql { Sql sql ->
        // do something
        return 0
      }

    } catch (Exception e) {
      log.error('Command failed : {}', e.message, e)
      throw e
    }

    log.info('Command succeeded.')
    return 0
  }
}

CommandConfiguration config = new CommandConfiguration(this.class)
if (!config.parse(args)) {
  System.exit(1)
} else if (config.showHelp) {
  config.usage()
  System.exit(0)
}

System.exit(new Command(config).execute())

Releases

Take a look at the changelog on GitHub.

Need help ?

Read the javadoc.

Raise an issue.

Email me at [email protected].

Versions

Version
0.0.5