geelen / shellac

Coat your shell scripts in something a bit more beautiful
MIT License
156 stars 4 forks source link

Thoughts on stdin for interactive prompts? #3

Open ericclemmons opened 3 years ago

ericclemmons commented 3 years ago

This is a really cool project!

I was looking at it to see if it could help make @aws-amplify/cli testable.

The problem I see with the Amplify CLI is that it's interactive with prompts.

Before I found shellac, I was working on a tool that did the following:

  1. Read a markdown file (e.g. README.md) and extracted the shell code fences.
  2. Create a /tmp directory and execute these shell scripts sequentially.
  3. Finally, a test assertion validates if the resulting output matched expectations.

The problem I ran into was trying to document the commands in a scriptable way:

$ amplify init
Enter a name for the project: nextamplified

# All AWS services you provision for your app are grouped into an "environment"
# A common naming convention is dev, staging, and production
Enter a name for the environment: dev

Then, following this block would be a comment:

<!-- shell:input
nextamplified[ENTER]
dev[ENTER]
-->

Did you have any thoughts on how shellac could support testing interactive CLIs?

geelen commented 3 years ago

No but that's exactly where I want to take this project!

Have you seen any of these projects?

Of these, Expect seemed the most geared towards interactivity, but almost too much so. Once I realised I could use function callbacks inside a JS tagged template DSL I felt it was worth inventing something new.

I do love the idea of a README test file but in the end I find Jest files readable enough so didn't pursue it. And I guess that's the biggest concept I'm exploring right now—if you use all of JS's tooling & a DSL, how good can you make the API?

One thing I've tried to do so far is avoid any inherent testing concerns inside Shellac, even though that's the whole point. But being able to drop into JS land in order to call expect for me feels really powerful.

Happy to toss around suggestions, so far I think Shellac has proved itself to be a great idea, keen to see it expand to cover more use cases.