CLI for processing files using Elm functions

I toyed around with a command line interface to run Elm functions directly, including support for files as inputs and outputs.

Following is the current state of the interface:

  • Required argument on the CLI command is a path to an Elm module containing the function, or even further a specific declaration (syntax using slash inside Elm module or line number)
  • --input option to add an additional argument value inline (parsed as Elm expression / structural typing also for choice types)
  • --input-file option to add an additional argument from a file content.
  • --output-file to save the return value from the Elm function.
  • --watch: Live update when input files change.

When connected to a terminal, it shows an interactive prompt to select a function declaration (In case the given context only points to a whole Elm module):

After selecting a function declaration, it prompts for remaining argument values, if not all were given with --input options:

If no output file is specified, the CLI prints the return value in the terminal:

Watch Mode

This video shows the use of the --watch mode specifically, with one file as input and one file as output:

7 Likes

I added a more extensive exploration at https://github.com/Viir/explore-processing/blob/main/apply-svg-demos/README.md

This is really interesting!! Are you using it for anything or just exploring?

Just exploring so far. Its more been a recreational activity, I wanted to do something else for once.

One influence motivating me for this “apply” command was seeing how often GitHub copilot / Claude Code reach for python scripts, only to transform some files.
Using pure functions for in such tool calls would be much better.
For use cases like such file edits and bulk file edits, I am thinking of expanding the input/output model to support file trees / directories.

2 Likes