hapi-server / uri-templates

Repository of tools for URI templates
Apache License 2.0
2 stars 0 forks source link

Bob suggests command line API #5

Closed jbfaden closed 1 year ago

jbfaden commented 4 years ago

Bob suggested adding a command line API, and I've added and extended this. This can parse and format time ranges, like so:

unix> java -jar UriTemplatesJava.jar --formatRange --timeRange='1999-01-01/1999-01-03' --template='http://example.com/data_$(d;pad=none).dat'
http://example.com/data_1.dat
http://example.com/data_2.dat

and

unix> java -jar UriTemplatesJava.jar --parse --template='http://example.com/data_$(d;pad=none;Y=1999; m=5).dat' --name='http://example.com/data_1.dat'
1999-05-01T00:00:00.000000000Z/1999-05-02T00:00:00.000000000Z

Also the name and timeRange parameters should allow for -, meaning that stdin will be used to feed in a list of names or timeRanges.

jbfaden commented 4 years ago

I've change it so that --range is used instead of --timeRange. This shortens the name and avoids camel case. I've added support for --range=- and --name=- .

rweigel commented 4 years ago

It seems formatRange is implied if timeRange is given and parse is implied if not and so --parse and --formatRange are redundant.

Does your code support the now keyword that is not a part of the standard?

rweigel commented 4 years ago

I followed README and it worked. But README uses camel case for formatRange and timeRange.

jbfaden commented 4 years ago

Maybe you need to refresh, I changed it around the same time you post. As for "now", I can put that in. It's not a standard thing, but it's very useful...

rweigel commented 4 years ago

I see what happened. You have a camelCase formatRange but changed timeRange to be just range. I was thinking you got rid of all camelCase.

Any thoughts on the redundancy issue?

jbfaden commented 4 years ago

Yes, I don't like the "formatRange" name either. Maybe I should just call it "format" and not worry about the format/parse asymmetry. (Parse always returns one thing, while formatRange returns 1 or more.)

I don't agree with you on the redundancy issue, or at least it seems harmless to me. Whether you are parsing or formatting is a huge difference, and I would want this to be explicit.