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

new cli syntax #23

Closed
perrygeo opened this issue Apr 26, 2016 · 3 comments · Fixed by #24
Closed

new cli syntax #23

perrygeo opened this issue Apr 26, 2016 · 3 comments · Fixed by #24
Milestone

Comments

@perrygeo
Copy link
Contributor

perrygeo commented Apr 26, 2016

As discussed in #5, We ditched the idea of click command options (--saturation, etc) because they are unordered. As an alternative, we developed a little domain specific language where each additional argument was an operation to applied in order.

e.g. this would apply gamma to red and green then a saturation to the whole image

rio color in.tif out.tif "gamma r,g 1.05" "saturation 125"

This works until you start passing around the the operations as shell variables. You quickly get into quote escape and delimeter hell. Consider this

$ color_formula="\"gamma r,g 1.05\" \"saturation 125\""
$ set -x
$ echo $color_formula
+ echo '"gamma' r,g '1.05"' '"saturation' '125"'

Ugh. broken by spaces. It gets even nastier when you try to read operations from files or sed streams.

In short, our DSL has issues.

❓ Potential Solutions:

  • Use a different delimiter: gamma_r,g_1.05 saturation_125 a bit yicky but functional. By using _ and avoiding the space, we avoid the need to use quotes. And we could make it compatible with the existing language.
  • Use something that would be an entire departure
    • a single quoted series of S-expressions: "(gamma r,g 1.05) (saturation 125)"
    • override click.Command.parse_args to keep ordered options: --gamma r,g 1.05 --saturation 125
    • unquoted DSL: gamma r,g 1.05 saturation 125

/cc @sgillies @celoyd

@perrygeo
Copy link
Contributor Author

soliciting some advice over at pallets/click#567

@celoyd
Copy link
Contributor

celoyd commented Apr 29, 2016

What about commas?

rio color in.tif out.tif gamma rg 1.05, saturation 125

Con: It makes color selectors less readable, and it means that long-form selectors like red,green have to go. It’s also not particularly standard syntax.

Pro: it’s easy to type, and it expresses the idea of sequence clearly.

@perrygeo
Copy link
Contributor Author

perrygeo commented May 2, 2016

So I've gone ahead with the "unquoted DSL" route with optional commas to separate the operations.

These are equivalent commands. Commas are effectively treated like an empty string, use them if they make it more clear but they have no syntactic meaning.

$ rio color in.tif out.tif gamma rgb 0.95 sigmoidal rgb 35 0.13
$ rio color in.tif out.tif gamma rgb 0.95, sigmoidal rgb 35 0.13

PR coming soon.

@perrygeo perrygeo mentioned this issue May 2, 2016
@perrygeo perrygeo modified the milestone: 0.1 May 7, 2016
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 a pull request may close this issue.

2 participants