ramanshah / bread

Scale recipes at the command line
BSD 3-Clause "New" or "Revised" License
5 stars 0 forks source link

Scale and re-emit YAML #3

Open ramanshah opened 7 years ago

ramanshah commented 7 years ago

bread is already nice in scaling published recipes at bake time, but it would be nice to re-use the machinery as a utility in developing recipes. Say I nail a recipe in the course of recipe development and want to bring the quantities back to round numbers (say 100 g of flour, reading out a baker's percentage) and then publish that recipe as YAML.

Often this task will involve multiplying by a fraction x/y. It would be nice to support such a workload ergonomically.

ramanshah commented 6 years ago

Current usage:

bread ciabatta.yml 1.2

Current feature set:

  1. YAML, scale factor in. Recipe on console out.

Desired feature set:

  1. YAML, scale factor in. Recipe on console out.
  2. YAML, scale factor in. YAML out.
  3. YAML, scale factor numerator and denominator in. Recipe on console out.
  4. YAML, scale factor numerator and denominator in. YAML out.
ramanshah commented 6 years ago

Seems like two optional command line flags would do it:

  1. -y to request YAML output.
  2. -d to divide by another scalar.

Usage like this for the desired feature set?

bread ciabatta.yml 1.2
bread ciabatta.yml 1.2 -y
bread ciabatta.yml 100 -d 123
bread ciabatta.yml 100 -d 123 -y
ramanshah commented 6 years ago

Perhaps we could auto-detect the denominator if the command line takes the correct format:

bread ciabatta.yml 1.2
bread ciabatta.yml 1.2 -y
bread ciabatta.yml 100 123
bread ciabatta.yml 100 123 -y
ramanshah commented 6 years ago

The Alternative feature of optparse-applicative seems to be a way to do the latter.

In terms of work I did at the recent hackathon, a good order of work would be:

ramanshah commented 5 years ago

One idea is to use hascal and migrate the scale factor to a quoted string.

Unfortunately this seems to have been scrubbed from the web by its maintainer, and it didn't make it into a Stack LTS. Alternatives:

In any case, these would be the kinds of commands envisioned:

bread ciabatta.yml 1.2
bread ciabatta.yml 1.2 -y
bread ciabatta.yml "100 / 123"
bread ciabatta.yml "100 / 123" -y

Whether one can get away without quoting the 1.2 is negotiable.