4 ms·
If you find this article interesting and are curious about Nim then you would probably also be curious about https://github.com/c-blake/cligen https://github.co
by cb321 3y ago
If you find this article interesting and are curious about Nim then you would probably also be curious about https://github.com/c-blake/cligen https://github.com/c-blake/cligen
That allows adding just 1-line to a module to add a pretty complete CLI and then a string per parameter to properly document options (assuming an existing API using keyword arguments).
It's also not hard to compile & link a static ELF binary with Nim.. I do it with MUSL libc on Linux all the time. I just toss into my ~/.config/nim/nim.cfg:
@if musl: # make nim c -d:musl .. foo static-link `foo` with musl
cc = gcc # --opt:size trades more speed
gcc.exe = "musl-gcc" # NOTE: This also works as a ..
gcc.linkerexe = "musl-gcc" #..per-module foo.nim.cfg
passL = "-static -s"
@end
Lisp is often cited as one of Nim's inspirations.
EDIT: https://nim-lang.org/ https://nim-lang.org/ has much more detail and there are over 50 small CLI programs at https://github.com/c-blake/bu https://github.com/c-blake/bu as rather extended examples. Using that musl approach I get tiny little 100 kB ELF executables that would work on practically any Linux you can `scp` them to with none of the boilerplate/language limits/hassles or speed-limits of, say, Go and run-time start-up times on the order of 100 microseconds. There are all kinds of great libs in Nim, too like @V1ndaar's https://github.com/SciNim/Measuremancer https://github.com/SciNim/Measuremancer or all sorts of goodies over at https://nimble.directory/ https://nimble.directory/
- paradox460 3y agoI've used cligen before, and it's very elegant. But if you are used to more declarative ways of writing your cli, it can be a bit of a learning curve. Best advice I can give is look at what you are actually trying to do, not "how do I make it work like <other tool>"