Skip to content

Conversation

@lread
Copy link
Contributor

@lread lread commented Aug 13, 2025

Bumped babashka.cli to get fix for table formatting.

Squint has a couple of cli oddities:

  • compile command does not have to be specified for compile
  • -e acts like a command but looks like an option

I added upfront processing so these oddities become normal commands for babashka.cli.

Changes:

  • Any unrecognized option is a validation error
  • Any missing required option is a validation error
  • An invalid number of args is a validation error
  • On validation error squint exits with code 1
  • nrepl-server is now described/exposed
  • compile :copy-resources option is now described/exposed
  • -e --repl option is now described/exposed
  • run now exposes/describes options, same as compile but without --paths and copy-resources
  • Usage for watch is same as compile except :paths is required
  • Added a few cli sanity tests

Closes #691

Please answer the following questions and leave the below in as part of your PR.

lread added 3 commits August 13, 2025 15:06
Bumped babashka.cli to get fix for table formatting.

Squint has a couple of cli oddities:
- `compile` command does not have to be specified for compile
- `-e` acts like a command but looks like an option

I added upfront processing so these oddities become normal commands for
babashka.cli.

Changes:
- Any unrecognized option is a validation error
- Any missing required option is a validation error
- An invalid number of args is a validation error
- On validation error squint exits with code 1
- `nrepl-server` is now described/exposed
- `compile` `:copy-resources` option is now described/exposed
- `-e` `--repl` option is now described/exposed
- `run` now exposes/describes options, same as `compile` but without
`--paths` and `copy-resources`
- Usage for `watch` is same as `compile` except `:paths` is required
- Added a few cli sanity tests

Closes squint-cljs#691
@lread
Copy link
Contributor Author

lread commented Aug 13, 2025

I think this change is finally ready for your review @borkdude!

It is on the larger side, so, as usual, when you find time/interest.

Happy to answer questions and refine if needed.

@lread
Copy link
Contributor Author

lread commented Aug 14, 2025

Oh yeah, also:

  • When compile does no work, it is now considered an error.

@borkdude
Copy link
Member

One thought about the ANSI output. When you pipe the output to a text file you see this:

�[31mERROR�[0m: Unrecognized option: --xrepl

Is that a problem? ANSI output only makes sense on the terminal.

I have an open issue about detecting "terminal" here:

babashka/babashka#1299

In jet I detect terminal in a reliable way here:

https://github.com/borkdude/jet/blob/master/src-java/org/babashka/CLibrary.java

but it can also be done using (System/console). The only downside to (System/console) is that when you pipe stdin from a non-terminal, it returns nil:

bb -e '(System/console)' <<< 1

but perhaps that's just good enough.

@lread
Copy link
Contributor Author

lread commented Aug 15, 2025

Good point on ANSI escapes. Node itself outputs color. Let's see what it does for comparison:

node lib/cli.js compile missing.cljs
image

This is written to stderr, if we redirect:

node lib/cli.js compile missing.cljs &> foo

The ansi codes are not there.

Does it respect NO_COLOR?

NO_COLOR=true node lib/cli.js compile missing.cljs

It does. Maybe supporting NO_COLOR env var is good enough?

@borkdude
Copy link
Member

Oh yeah, we're on Node.js, I forgot, this is not babashka, duh!

In Node.js you can use this:

process.stdout.isTTY

It will only return true when you're connected to a terminal.

@lread
Copy link
Contributor Author

lread commented Aug 15, 2025

Ah. Great, I'll make use of process.stdout.isTTY then.

lread added 3 commits August 15, 2025 08:22
Mimic node. Don't use ANSI colour codes if any true:
1) `NO_COLOR` env var is set
2) not in an interactive terminal (ex. redirecting output)
I remembered incorrectly, ANSI colour codes do work on Cmd and
Powershell on Windows.
This was only expressed internally, but needs to be also expressed in
the cli so that:
- the user can learn what the default is
- the cli uses paths itself for compile, so those defaults need to be
applied earlier for it.

This means squint no longer has any required opts.
Supporting code turfed.

This also means we no longer have our failure check for both `<files>`
and `--paths` being specified for `compile`. Updated usage note to
explain how `<files>` overrides `--paths` and `:paths`.

This allowed me to turf post-validate supporting code.
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 this pull request may close these issues.

Consider exiting with non-zero on invalid cli usage

2 participants