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

Support JSON output in report command #102

Merged
merged 2 commits into from
Apr 10, 2017

Conversation

timofurrer
Copy link
Member

Use --json switch to change report output from console output to JSON.

@jmaupetit
Copy link
Contributor

Thank you @timofurrer ! JSON output seems a relevant feature. Can you share a concrete use case with us? I mean to which program do you pipe this output to?

Side question: did you update commands.md with make docs?

@timofurrer
Copy link
Member Author

I don't have a specific tool at the moment. However, I plan to write an adapter for some company specific time tracking tools ;) .. and beside that I thought others might have the same idea so I just implemented it .

Yeah, I documented it -> See changeset. Is something wrong about it?

@jmaupetit
Copy link
Contributor

I plan to write an adapter for some company specific time tracking tools

I am glad that you prefer using Watson than the time tracker of your company ❤️

Yeah, I documented it -> See changeset. Is something wrong about it?

Yep, saw it. That is why I asked. Nothing wrong, just noise.

@jmaupetit jmaupetit changed the title Support JSON output in report command [WIP] Support JSON output in report command Mar 1, 2016
@@ -341,6 +366,7 @@ Flag | Help
`-t, --to DATE` | The date at which the report should stop (inclusive). Defaults to tomorrow.
`-p, --project TEXT` | Reports activity only for the given project. You can add other projects by using this option several times.
`-T, --tag TEXT` | Reports activity only for frames containing the given tag. You can add several tags by using this option multiple times
`-j, --json` | Outputs the report as JSON instead of writing to the console
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSON output still goes to the console, doesn't it? Just the format changes from formatted text with escape sequences to JSON. How can this be reworded to be more accurate?

@SpotlightKid
Copy link
Contributor

@timofurrer Do you still plan to update this PR according to the feedback?

@timofurrer
Copy link
Member Author

Completely forgot about this PR. I'll have a look at it asap.

apollo11 - 13h 22m 20s
[brakes 7h 53m 18s]
[module 7h 41m 41s]
[reactor 8h 35m 50s]
[steering 10h 33m 37s]
[wheels 10h 11m 35s]

$ watson report --format json

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you document --format json while the actual option is --json.
BTW, I think the --format is better since it leaves room to future other formats without adding lots of distinct options.

@timofurrer timofurrer force-pushed the feature/json-report branch from f1dce0f to 6512130 Compare April 4, 2017 11:36
@timofurrer
Copy link
Member Author

timofurrer commented Apr 4, 2017

It's definitely been a while - I apologize for that!

I've updated the PR and reworded the option description.
I've used --format [rich|json] instead of --json. I'm not quiet happy with the term rich though. Any suggestions?

We could also enhance the current implementation with the if output_format == 'json' by implementing some kind of formatter objects ...
However, I'd wait for that to implement until there is a need for other formats than just json (like CSV or whatever ...)

@timofurrer timofurrer changed the title [WIP] Support JSON output in report command Support JSON output in report command Apr 4, 2017
@SpotlightKid
Copy link
Contributor

I'm not quiet happy with the term rich though. Any suggestions?

Umm, not sure, how about formatted or plaintext or plain?

@willdurand
Copy link
Contributor

I would keep --json as it is short and useful. There is no need for other formats yet, so we can keep things simple. And it does not mean --format will not be implemented in the future.

@timofurrer
Copy link
Member Author

timofurrer commented Apr 4, 2017

Umm, not sure, how about formatted or plaintext or plain?

Well, the json output is formatted, too. And it's not really plaintext because of the colors.

I would keep --json as it is short and useful. There is no need for other formats yet, so we can keep things simple. And it does not mean --format will not be implemented in the future.

What about a shortcut to --format json? I agree, it does not make a lot of sense to expose an API (--format) which is not really used (well, at this point it is used for some extend, but since we only have to choices - we could consider it a flag)

I can do either one. Who makes the call?

@jmaupetit
Copy link
Contributor

Thanks for the update @timofurrer ! I would also keep the --json flag and we will add a shortcut later when the --format api will make sense.

@timofurrer timofurrer force-pushed the feature/json-report branch from e3e1fdf to f648349 Compare April 5, 2017 17:25
@timofurrer
Copy link
Member Author

@jmaupetit @willdurand I've updated the PR according to your suggestion to use --json instead of --format.

Copy link
Contributor

@jmaupetit jmaupetit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for this contribution! Can you please use double quotes for translatable strings only? I have mentioned this point in your tests, but I see that there are a few left in your code.

assert len(report["projects"]) == 1
assert report["projects"][0]["name"] == "foo"
assert len(report["projects"][0]["tags"]) == 1
assert report["projects"][0]["tags"][0]["name"] == "B"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use single quotes for non-translatable strings?

watson/cli.py Outdated
@@ -325,8 +325,11 @@ def status(watson):
help="Reports activity only for frames containing the given "
"tag. You can add several tags by using this option multiple "
"times")
@click.option('-j', '--json', 'format_json', is_flag=True,
help='Format the report in JSON instead of plaintext')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/plaintext/plain text/

watson/cli.py Outdated
@@ -346,6 +349,9 @@ def report(watson, current, from_, to, projects, tags, year, month, week, day):
`--tag` options. They can be specified several times each to add multiple
projects or tags to the report.

You can change the output format for the report from *plaintext* to *JSON*
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idem: s/plaintext/plain text/

@timofurrer timofurrer force-pushed the feature/json-report branch 2 times, most recently from ca5941c to 2505db8 Compare April 6, 2017 17:15
@timofurrer
Copy link
Member Author

timofurrer commented Apr 6, 2017

@jmaupetit okay.

I'm not quiet sure what you mean with translatable strings - I couldn't find a consistent pattern for the use of " and ' ...

But I guessed and pushed - Have a look at it 🍻

@jmaupetit
Copy link
Contributor

Thank you for these changes. I am sorry to insist, but there are some double quotes left in cli.py (l. 430-467). Once fixed, I'll merge this PR. 💪

@timofurrer timofurrer force-pushed the feature/json-report branch from 2505db8 to 66a3782 Compare April 10, 2017 10:15
@timofurrer
Copy link
Member Author

timofurrer commented Apr 10, 2017

Done.

I think some clear guide lines would really help people to contribute more efficiently ... ;)

@willdurand
Copy link
Contributor

I think some clear guide lines would really help people to contribute more efficiently ... ;)

I do agree with you, especially here since I do not know what translatable strings are either. Maybe @jmaupetit could give an explanation here, and we will update the CONTRIBUTING file/doc accordingly.

@jmaupetit jmaupetit merged commit 3c51020 into jazzband:master Apr 10, 2017
@jmaupetit
Copy link
Contributor

@timofurrer I am sorry if you felt frustrated after submitting code to this PR. This coding convention is implicit, but required to maintain consistency over the project. We need to work on this.

To briefly explain it, translatable strings are literal strings containing natural language messages that may be translated during the internationalization of the app. All other strings acting as "identifiers" are single quoted (dictionary keys, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants