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

Adding JSON output #3

Closed
erica opened this issue Jun 2, 2020 · 8 comments
Closed

Adding JSON output #3

erica opened this issue Jun 2, 2020 · 8 comments

Comments

@erica
Copy link
Owner

erica commented Jun 2, 2020

Provide a lightweight JSON output to support scripting.

cc @Impedimenta, @taquitos

@erica
Copy link
Owner Author

erica commented Jun 2, 2020

now provides three modes of output:

  • current time
  • adjusted remote time
  • adjusted local time

My first pass at this produces the following output:

% now bath uk --remote 4p -j
{
  "place" : "Local",
  "zone_name" : "Mountain Time",
  "provider" : "https:\/\/github.com\/erica\/now",
  "time_zone" : "MDT",
  "time" : "2020-06-02T15:00:00Z",
  "version" : "1.0.0"
}
% now bath uk --local 9a -j
{
  "place" : "Bath",
  "zone_name" : "United Kingdom Time",
  "provider" : "https:\/\/github.com\/erica\/now",
  "time_zone" : "GMT+1",
  "time" : "2020-06-02T15:00:00Z",
  "version" : "1.0.0"
}
% now bath uk -j
{
  "place" : "Bath",
  "zone_name" : "United Kingdom Time",
  "provider" : "https:\/\/github.com\/erica\/now",
  "time_zone" : "GMT+1",
  "time" : "2020-06-02T16:20:41Z",
  "version" : "1.0.0"
}

Update: Added json branch to test.

I need concrete feedback as to what would be appropriate and useful output

@rjstelling
Copy link

rjstelling commented Jun 3, 2020

This actually looks pretty good.

I'm not sure of the need for a provider key, especially if it's always going to be "https:\/\/github.com\/erica\/now"?

I do have a feature request, adding a --pretty @Flag. So we can get unformatted JSON out.

@Flag(default: true, inversion: .prefixedNo)
var pretty: Bool

This will turn on prettification by default and passing --no-pretty will turn it off, that seems like the best default to me.

@erica
Copy link
Owner Author

erica commented Jun 3, 2020

I'm hesitant to add more exposed features to a utility I want to keep simple. Can you argue against pretty JSON for me? As far as I know, decoders can ignore the pretty printing.

I want to introduce only one format (non-pretty or pretty) and a single option (--json / -j) to keep that exposed surface area small.

I think there's value to having a version in case the output changes but agree the provider is marginally pointless.

Update: Pushed version to json removing provider.

@rjstelling
Copy link

No, you are correct. I don't have a good argument against pretty JSON being the only option.

I agree with the version, I'm assuming it's going to follow Semantic Versioning?

@rjstelling
Copy link

I just posted my Semantic Versioning code to a gist, it might be useful: https://richardstelling.com/Swift-Gists/#semantic-versioning

@erica
Copy link
Owner Author

erica commented Jun 4, 2020

@rjstelling How about a single digit: version 1, 2, 3...? I don't anticipate changing the JSON output but I'd like to have a version there just in case.

@rjstelling
Copy link

Personally I prefer to have the option of Semantic Versioning, but 1, 2 etc are still valid semantic versions. So, everyone is a winner.

@erica
Copy link
Owner Author

erica commented Jun 4, 2020

I'm going to go with that, then, with the understanding that I expect the JSON to not change much (if at all over time). Closing this issue and pushing the version with JSON support.

@erica erica closed this as completed Jun 4, 2020
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

No branches or pull requests

2 participants