Giter VIP home page Giter VIP logo

rendr-sdk-groovy's Introduction

Rendr SDK for Groovy

Library to enable scripting in Rendr blueprints

Usage

Running a script

Check out the help text for details on usage:

❯ rendr-sdk-groovy --help

Usage: rendr-sdk-groovy [-hsV] [-v=<key=value>]... <script>
A Groovy script runner for rendr
      <script>              The script file to run.
  -h, --help                Show this help message and exit.
  -s, --stacktrace          Print stacktrace on error.
  -v, --value=<key=value>   Value used in script (flag may be repeated).
  -V, --version             Print version information and exit.

Running a script looks like this:

rendr-sdk-groovy upgrade-v3.groovy --value name=foo --value version=42

Writing a script

Blueprint authors can use this library to simplify creating scripts, especially for blueprint upgrades from one version to the next. The library provides a number of DSL commands:

  • create files or directories
  • move files or directories
  • write text to file
  • append text to file
  • prepend text to file
  • insert text in file
  • replace text in file
  • git commands
  • script for generic Groovy code

Here is a sample script using these DSL commands:

insert 'echo "hi!"' into 'hello.sh' after '#!sh\n'
replace 'hello, world!' with "hello, $name!" inside 'hello.sh'  // references 'name' variable from values flag
git "mv hello.sh ${values.name}.sh"  // this also references 'name', but this time from the 'values' map

create 'hello.log'
git 'add hello.log'

script {
    files = []
    dir('src').eachFileRecurse(FileType.FILES) { file ->
        files << file
    }
    println "All files in src:"
    files.sort().each { println it.path }
}

Available functions

Function Example
file(String path) file('hello.sh')
dir(String path) dir('foo')
create(String file) create 'hello.sh'
create(File file) create file('hello.sh')
create(Dir dir) create dir('app')
create(String file).write(String text) create 'hello.sh' write 'echo hi'
move(String file).to(String path) move 'hello.sh' to 'foo/hello.sh'
append(String text).to(String file) append 'echo "hi $1"' to 'hello.sh'
prepend(String text).to(String file) prepend 'echo "hi $1"' to 'hello.sh'
insert(String text).into(String file).after(String pattern) insert 'echo "hi!"' into 'hello.sh' after '#!sh\n'
replace(String text).with(String text).inside(String file) replace 'hello, world!' with 'hi, world!' inside 'hello.sh'
git(String command) git 'add hello.sh'
script(Closure block) script { println "System properties: ${args.split().findAll { it.startsWith('-D') }}"}

rendr-sdk-groovy's People

Contributors

thecodesmith avatar

Watchers

James Cloos avatar  avatar Tom (Rosco) Wile II avatar  avatar

Forkers

martintheweirdo

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.