Giter VIP home page Giter VIP logo

gq's Introduction

gq

License Download ![Linux Build Status](https://img.shields.io/circleci/project/ceilfors/gq/master.svg?label=Linux Build) ![Windows Build Status](https://img.shields.io/appveyor/ci/ceilfors/gq/master.svg?label=Windows Build) Groovy 2.4.5 Java 1.7.0_79

Quick and dirty debugging output for Groovy.

Quick Start

Source code

@Grab(group='com.ceilfors.groovy', module='gq', version='0.1.2') // 1. Get dependency!
import gq.Gq as q // 2. Import q and get ready
def me() { 'world' }
def greet() { 'hello' }

// 3. Use q(), q|, q/  to print values without temporary variable. Check the differences from the output below.
println([greet(), q(me() + ' !')].join(' '))
println([greet(), q/me() + ' !'].join(' '))
println(q|[greet(), me() + ' !'].join(' '))

@q // 4. Annotate a method to get trace of method calls
def greeter(args) { args << '!'; args.join(' ') }

println(greeter([greet(), me()]))

Run the program and you'll discover the output below. Remember to remove all these debugging notations before you publish your software to production.

Output

tail -f /tmp/gq

run: me() + ' !'='world !'
run: me()='world'
run: [greet(), me() + ' !'].join(' ')='hello world !'
greeter(['hello', 'world'])
-> 'hello world !'

The colored output can be seen here!

Configuration

These configurations are set via Java System Properties e.g. groovy -Dgq.tmp=/elsewhere test.groovy

  • gq.tmp

    Default: /tmp

    Configures where gq should be putting gq files. By default gq file will go to /tmp/gq. This will go to C:/tmp in Windows. You can't change the file name generated.

  • gq.color

    Default: true Set true to print ANSI color to make /tmp/gq console friendly. If you prefer to view gq file from text editor, you can of course install a plugin for your favourite text editor to render ANSI escape codes.

Features

More detailed behaviors can be found at gq acceptance tests

  • Use any import alias you want

    If you can't use import gq.Gq as q as you have declared q variable or method already in your project, you can change it to whatever alias you want. Gq will also work without alias e.g. import gq.Gq. When using without alias, just replace everything to Gq: @Gq, Gq|, Gq/, Gq().

  • Store long values to a file

    When you do q(new File('long-xml').text), then tail /tmp/gq, you will find:

    0.2s run: new File('long-xml').text='<xml><root><chi..ren></root></xml>' (file:///tmp/gq0615b779-20dc-4a7e-bcca-8e2b63c7c8a8.txt)
    

    Notice the printed value above that the xml file content has been shortened with .. in the middle. You will also see the link to the file where the actual value will be stored i.e. file:///tmp/gq0615b779-20dc-4a7e-bcca-8e2b63c7c8a8.txt. A new randomly generated file will be created every time there is a long value found.

  • @CompileStatic

    You will be able to use gq in conjunction with @CompileStatic.

  • /tmp/gq formatting

    0.0s hello() // timestamp as a prefix on every line. This helps differentiating multiple time of execution.
    0.1s   oops() // Indentation when you have nested @q call
    0.1s   !> RuntimeException('Hello') at visualizeColor.groovy:43 // Handles and prints exception with line number
    ...
    0.1s -> 'HELLO world!!!'

Release steps

  1. Create a new tag for the next release: git tag <version>
  2. Check if axion-plugin is successfully picking up the intended version ./gradlew currentVersion
  3. Upload to jcenter: ./gradlew bintrayUpload -PbintrayUser=<> -PbintrayApiKey=<> -PgpgPassphrase='<>' -PmavenCentralPassword=<>
  4. Push tags to github: git push --tags

Credits

Heavily inspired by https://github.com/zestyping/q

gq's People

Contributors

ceilfors avatar yihtserns avatar

Watchers

James Cloos avatar  avatar

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.