Skip to content
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

Add option to print machine readable output to stdout #39

Closed
wants to merge 4 commits into from

Conversation

vortec
Copy link

@vortec vortec commented Feb 5, 2014

When you run bumpversion --verbose, its output gets sent to stderr. This prevents a user to pipe the output into Linux commands like grep without having to redirect stderr to stdout. I don't see a reason why the verbose output should be treated as an error, therefore I'm issuing this pull request.

Furthermore this commit uses False instead of 0 as default value for --verbose, because it's a boolean value and all other options use it too.

@peritus
Copy link
Owner

peritus commented Feb 5, 2014

I think bumpversion behaves like other unix tools out there in this respect.

Compare curl -v with muted stdout:

curl -v https://github.com/peritus/bumpversion/pull/39 > /dev/null 2>&1 | head
* Adding handle: conn: 0x7f9e33003a00
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x7f9e33003a00) send_pipe: 1, recv_pipe: 0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0* About to connect() to github.com port 443 (#0)
*   Trying 192.30.252.131...
* Connected to github.com (192.30.252.131) port 443 (#0)

and with muted stderr:

curl -v https://github.com/peritus/bumpversion/pull/39 2> /dev/null | head





<!DOCTYPE html>
<html>
  <head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# object: http://ogp.me/ns/object# article: http://ogp.me/ns/article# profile: http://ogp.me/ns/profile#">
    <meta charset='utf-8'>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

I don't consider verbose logging an error, merely "human readable useful information besides the main output" and that should go to "the other channel that is not stdout" (that is stderr in this case).

What are you trying to accomplish ? I certainly want bumpversion to be unixy the way that it prints useful information for other programs to consume, I'm interested in your usecase.

@peritus
Copy link
Owner

peritus commented Feb 5, 2014

Also I want bumpversion to support multiple verbosity levels in the future, so that's why it's a count.
At the moment there's only one level because I couldn't decide yet.

@vortec
Copy link
Author

vortec commented Feb 5, 2014

Hi Filip, thanks for the quick response.

My usecase is indeed a wrapper script that takes a generated version number from bumpversion (using -n --verbose) and checks if the version exists as a tag on a git remote. If it doesn't exist, it calls bumpversion again to let it actually change files and commit the changes. Actually It does a little more than that, but this is my basic requirement.

Under the current implementation I need to redirect the output of the --verbose call to stdout and then use grep+cut or sed to get the generated version number. To improve that solution, I was actually about to submit another pull request which added a new option, --short-output or something similar, which would, combined with -n, just print a.b.c -> x.y.z to stdout. For me, parsing that would be much easier (| cut -d " " -f 3) than a multiline string in stderr.

Apart from that, bumpversion is a really nice tool which has been working perfectly so far.

@peritus
Copy link
Owner

peritus commented Feb 5, 2014

Yes, let's print machine readable information to stdout (also, maybe with something that would be somehow stable).

Maybe similar to what git config -l does ?

Should be another loglevel in the Python logging sense, but independent from --verbose IMO.

@vortec
Copy link
Author

vortec commented Feb 5, 2014

The output format of git config -l is indeed easy to parse. Shall we open an issue to discuss this further? It seems that my pull request is obsolete and can be closed.

@peritus
Copy link
Owner

peritus commented Feb 5, 2014

Please leave this open as a reminder, feel free to change the attached code on this PR or open another PR if you feel like it.

git config -l was only one idea from the top of my head, maybe there is another format that makes more sense.

Happy coding ;)

@vortec
Copy link
Author

vortec commented Feb 6, 2014

I suggest implementing a -mor --machine-readableoption:

$ bumpversion -m patch
current_version=1.2.3
new_version=1.2.4
files=setup.py version.txt

This is the minimum it should output. I'm not sure about stuffing all options in it aswell, because that would bloat things up and unless you've overwritten options in .bumpversion.cfg, you have to pass them to the bumpversion command anyway.

@peritus peritus added the v0.4.1 label Feb 10, 2014
@vortec
Copy link
Author

vortec commented Feb 17, 2014

I think 4546e37 should be a good starting point to add more information. I had some issues with the argument parsers so please review my changes and let me know if it's ok.

peritus added a commit that referenced this pull request Mar 2, 2014
@peritus
Copy link
Owner

peritus commented Mar 2, 2014

@vortec I took your code and improved it a bit, please let me know if 8b998c4 fits your use case. If there are no objections, this is the last commit that needs to get in v0.4.1 which I'd like to release soon.

@vortec
Copy link
Author

vortec commented Mar 2, 2014

Perfect!

Two things I've noticed:

  • The -n option seems to be broken, --dry-run works.
  • Github doesn't render the newline in the README.rst example.

Apart from that, I have no objections. Thanks!

peritus added a commit that referenced this pull request Mar 4, 2014
@peritus
Copy link
Owner

peritus commented Mar 4, 2014

released in v0.4.1

@peritus peritus closed this Mar 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants