bwplotka / bingo

Like `go get` but for Go tools! CI Automating versioning of Go binaries in a nested, isolated Go modules.
Apache License 2.0
342 stars 29 forks source link

add -json flag for json output #130

Closed collinforsyth closed 5 months ago

collinforsyth commented 1 year ago

This is a great tool for helping manage developer environments. One thing that would increase the usability for our team is being able to check the binaries from list and ensure that they are installed from a script.

Rather than having to parse the tab output with bash, I think a json output makes this much easier. My proposal is to add a -json flag for output.

Usage

❯ ./bingo list -json
[
        {
                "name": "copyright",
                "binary_name": "copyright-v0.0.0-20210112004814-138d5e5695fe",
                "package_version": "github.com/efficientgo/tools/copyright@v0.0.0-20210112004814-138d5e5695fe",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "embedmd",
                "binary_name": "embedmd-v1.0.0",
                "package_version": "github.com/campoy/embedmd@v1.0.0",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "faillint",
                "binary_name": "faillint-v1.8.0",
                "package_version": "github.com/fatih/faillint@v1.8.0",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "goimports",
                "binary_name": "goimports-v0.0.0-20210112230658-8b4aab62c064",
                "package_version": "golang.org/x/tools/cmd/goimports@v0.0.0-20210112230658-8b4aab62c064",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "golangci-lint",
                "binary_name": "golangci-lint-v1.50.0",
                "package_version": "github.com/golangci/golangci-lint/cmd/golangci-lint@v1.50.0",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "mdox",
                "binary_name": "mdox-v0.9.0",
                "package_version": "github.com/bwplotka/mdox@v0.9.0",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "misspell",
                "binary_name": "misspell-v0.3.4",
                "package_version": "github.com/client9/misspell/cmd/misspell@v0.3.4",
                "build_env_vars": null,
                "build_flags": null
        },
        {
                "name": "proxy",
                "binary_name": "proxy-v0.10.0",
                "package_version": "github.com/gomods/athens/cmd/proxy@v0.10.0",
                "build_env_vars": null,
                "build_flags": null
        }
]

For example, this is a small script that checks if we have a binary installed:

for b in $(./bingo list -json | jq -r '.[] | .binary_name'); do
        if ! command -v $b;
                then echo "$b not found";
        else
                echo "$b found"
        fi
done

Output:

copyright-v0.0.0-20210112004814-138d5e5695fe not found
/Users/collinforsyth/bin/embedmd-v1.0.0
embedmd-v1.0.0 found
faillint-v1.8.0 not found
goimports-v0.0.0-20210112230658-8b4aab62c064 not found
golangci-lint-v1.50.0 not found
mdox-v0.9.0 not found
misspell-v0.3.4 not found
proxy-v0.10.0 not found

Hopefully not too big of a PR! Let me know if there's anything else needed for this.

collinforsyth commented 1 year ago

I realized I didn't update the Usage functions.

Will get to that on Monday.

bwplotka commented 1 year ago

Sorry for missing, this is great addition!

I'm afraid we we need to add another commit to get fresh results from CI.

bwplotka commented 5 months ago

Looks like no interest to pursue this, so closing for now. We can always reopen! Thanks!