-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Introduce bundle list --format=json
#8728
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
87f6e03 to
e0e5f69
Compare
1221548 to
9474c94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea a lot.
What about --format=json as an alternate syntax? It opens the door for other formats like csv or json lines etc. I'm not sure if there's a most-common name for that option, I've also seen --output json off the top of my head.
3af66cf to
abbad0e
Compare
Short: Seems good. I updated in a new commit. Longer: For some numbers, I searched on GitHub:
Seems that |
811e3f7 to
d8896be
Compare
bundle list --jsonbundle list --format=json
ef593b0 to
485a892
Compare
As another couple of datapoints, |
|
I'm interested in any feedback that could help advance or close this out. Baring strong blockers or actionable requests: a temperature reading of the feature is helpful too. Does this seem reasonable (warm) or does something about it make you say "ick" (ice cold)? |
|
I like this and I'm happy to introduce it, just did not find time to review it. Naming seems also fine, some commands already have a |
|
I'm unsure on timeline, but it would be nice to get this in before bundler 4 (if possible). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I commented some super minor nitpicks, but this PR looks good!
0bb8b24 to
f52314e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me! Do you mind squashing all commits to a single one?
f52314e to
14dfefe
Compare
The `bundle list` command is a convenient way for human to know what gems and versions are available. By introducing a `--format=json` option, we can provide the same information to machines in a stable format that is robust to UI additions or modifications. It indirectly supports `Gemfile.lock` modifications by discouraging external tools from attempting to parse that format.
This addition allows for the scripting of installation tools, such as buildpacks, that wish to branch logic based on gem versions. For example:
```ruby
require "json"
command = "bundle list --format=json"
output = `#{command}`
raise "Command `#{command}` errored: #{output}" unless $?.success?
railties = JSON.parse(output).find {|gem| gem["name"] == railties }
if railties && Gem::Version.new(railties["version"]) >= Gem::Version.new("7")
puts "Using Rails greater than 7!"
end
```
The top level is an object with a single key, "gems", this structure allows us to add other information in the future (should we desire) without having to change the json schema.
14dfefe to
9e081b0
Compare
|
Squashed and rebased, waiting for tests to run. Going to resolve prior comments. |
|
CI is all green. Thanks for the review and your work 🙏 |
|
No problem, I'll merge on Monday just to leave other maintainers some more time in case they have feedback. |
|
Thank you! |
What was the end-user or developer problem that led to this PR?
I need to know what versions of gems are installed for a given application programmatically. I'm currently parsing the
bundle listoutput, but I'm worried that the format may change in the future.What is your fix for the problem, implemented in this PR?
Introduce a stable, machine-readable formatting output to this command via adding a
--format=jsonflag.More
The
bundle listcommand is a convenient way for human to know what gems and versions are available. By introducing a--format=jsonoption, we can provide the same information to machines in a stable format that is robust to UI additions or modifications. It indirectly supportsGemfile.lockmodifications by discouraging external tools from attempting to parse that format.This addition allows for the scripting of installation tools, such as buildpacks, that wish to branch logic based on gem versions. For example:
The top level is an object with a single key, "gems", this structure allows us to add other information in the future (should we desire) without having to change the json schema.
This JSON format is also useful in a bash scripting context, where command-line tools such as
jqare commonly available to manipulate and extract information.Make sure the following tasks are checked