Code Monkey home page Code Monkey logo

Comments (1)

kousu avatar kousu commented on July 28, 2024

I saw this too and was confused. For example if I'm trying to extract some disk details:

$ nvme list -o json | gron -v
panic: runtime error: index out of range [0] with length 0

goroutine 1 [running]:
main.gronValues({0xc000126070?, 0xc00012a010?}, {0xc000142170?, 0x7555d8?}, 0x1?)
	github.com/tomnomnom/gron/main.go:411 +0x27f
main.main()
	github.com/tomnomnom/gron/main.go:178 +0x6bc

The solution is to run gron twice in a row:

$ nvme list -o json | gron | gron -v
/dev/nvme0n1
        
0
0
                                        
1
0
Non-Volatile memory controller: Toshiba Corporation NVMe SSD Controller
1
                    
0
/dev/nvme1n1
        
1
0
                                        
1
0
Non-Volatile memory controller: Toshiba Corporation NVMe SSD Controller
1
                    
0

I think this was probably missed because in practice you'd never use gron by itself, it's meant to be combined with grep, so you'd do something like:

nvme list -o json | gron | grep SerialNumber | gron --values

This is alluded to in the comments:

gron/main.go

Lines 401 to 404 in badf401

// gronValues prints just the scalar values from some input gron statements
// without any quotes or anything of that sort; a bit like jq -r
// e.g. json[0].user.name = "Sam"; -> Sam
func gronValues(r io.Reader, w io.Writer, opts int) (int, error) {

but not in the docs and it threw me off too. Maybe it can be explained with an example, or mentioning "Print just the values of gron-format assignments"?

And also it would be better not to panic at all. If the input format is wrong maybe that can become an error message explaining that the format is wrong.

from gron.

Related Issues (20)

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.