Owl: A toolkit for writing command-line user interfaces in Elixir
hexdocs.pm
hexdocs.pm
Regardless of technology, I think CLI's tend to maintain their original size, or get smaller over time. If you choose to use a CLI built with Elixir, I imagine it could gain a web-based GUI without a large increase, if each build already includes a runtime environment and system libraries. Or if a CLI is written in another language and advertised as very compact, I imagine its size will also stay consistent, but might not gain the same fancy features. And in any case, popular compilers or packaging tools tend gain optimization improvements over time.
Everything worked fine for me then.
If you're building CLI tooling in Elixir, you may also be interested in TableRex, my ASCII-table drawing library. [1]
Having said all of that that, something like this might be useful when writing custom Mix tasks inside Elixir projects!
For complex applications bash (or shellscript in general) is also rather ill-suited as it has a lot of footguns and can be hard to maintain.
These days I'd rather suffer through the verbosity of Go or strict memory semantics of Rust (which are no concern in most CLI applications) than write more than a dozen lines of Python. Personally, while I think the compiled world has settled onto a few very good languages, the scripting ecosystem still to this day leaves a lot to be desired.
https://engineering.fb.com/2022/07/27/developer-tools/progra...
So a web interface, an API interface, a CLI interface, etc are all treated the same way since the code doing the work isn’t tightly integrated to any of them.
From that perspective, Elixir can be great for CLI.
The equivalent approach in most other languages would be to create a single web API and have everything talk to it via REST, etc.
It’s closer to thinking of everything having an RPC interface by default I suppose.
The BEAM VM is unique (at least compared to mainstream languages) in that everything is run as a preempted, stackful coroutine. The result is an environment reminiscent of an operating system.
Things of interest for CLI stuff:
#!/usr/bin/env elixir
Use Mix.install like so Mix.install([
{:jason, "~> 1.4"},
])
Execute shell commands {output, status_code} = System.cmd("ls", ["-la"])
For handling files and paths: Path.join/2
__ENV__.file
Path.dirname/1
Path.expand/1
File.lstat/1
File.read/1
Parsing arguments argv = System.argv()
OptionParser.parse(argv, [strict: [switch: :boolean], aliases: [s: :switch]])
exit({:shutdown, status_code}) # for shutting down with an error
For printing colors (from docs) iex> IO.ANSI.format(["Hello, ", :red, :bright, "world!"], true)There are a number of applications(Erlang term) that start by default that may not be required, which can be disabled.
why? what factors lead you to this conclusion?
there's so mamy examples of low grade opinion sharing in the comments. going just a little further to say why you think something, what factoes are good or bad, can provide a real starting point where folks can learn & engage usefully, rather than just subject each other to utterly shallow opinion. another example from elsewhere:
> Elixir is ill-suited to command line apps out of the box.
we should have actual substance to our conversations; again, why?
(my own guess is that beam vm has to get started & is mind of heavyweight... i dunno if that cost even necessarily has to be paid for each program launch or no, maybe there's some trickery to quickly start new cli processes in existing vms. just guessing, not my scene. but what would be negative factors? no one says.)
I can think of three languages that I would use based on that: Go, Rust and if I was feeling adventurous or wanted to be able to execute scripts, Common Lisp (it's surprisingly fast, in the same league as Rust, for small programs).
Does Elixir compare positively to those in these categories?
EDIT: some people on this thread say it takes 200ms just to start an Elixir program. That's three times slower than Java, which is generally not considered a good language for CLIs.
Unless you're writing a CLI utility that natively interacts with BEAM VM services without having to de/serialize JSON via a REST API first
That said, there are also many situations where that is a tradeoff absolutely worth making!
> It can compile code more efficiently than the BEAM by stripping out dead code and compiling only what’s necessary for an application.
Though, they only mention faster compilation and smaller digital footprint, not faster startup.
[1] https://dockyard.com/blog/2022/09/01/dockyard-r-d-firefly-op...
Thank you for taking the time to respond.
That said, it's not all that uncommon to be searching for something like an implementation of a SaaS API and find a totally undocumented module. It's not the norm by any stretch though.
But...the issue is packaging/distributing a CLI built with Elixir. Comparatively to building a CLI in something like Rust, there is a lot of overhead that comes with a VM-based language and framework. Especially if you want to target multiple OS and processor architectures (or distributions). Not to say that it is impossible, just maybe not as simple. It is one thing to run Mix tasks, or access the Owl API from REPL, it is another to run an Owl-based app on macOS, Linux and Windows and get it there.
It still has limitations (the biggest one is the requirement for the os&architecture to match between the builder and the deployment target) — but the result is a standalone binary which not only embeds the VM and preloads the app's bytecode, but even "trims" the stdlib to only ship the required functions.
I wonder where WASM/container enters the discussion.
https://dockyard.com/blog/2022/09/01/dockyard-r-d-firefly-op...
Containers are already solved, its trivial to build and boot a mix release - but whether that's appropriate for a CLI tool depends on the complexity of the tool I guess, but not too far from flatpaks etc no?
I'm doubtful I'll see it used much outside the BEAM community, but then again it's been a "successful despite a lack of mass usage" community for awhile.
"Picocli is a one-file framework for creating Java command line applications with almost zero code. Picocli aims to be the easiest way to create rich command line applications that can run on and off the JVM.
Picocli supports a variety of command line syntax styles including POSIX, GNU, MS-DOS and more. It generates highly customizable usage help messages with ANSI colors and styles. Picocli-based applications can have command line TAB completion showing available options, option parameters and subcommands, for any level of nested subcommands. Picocli-based applications can be ahead-of-time compiled to a GraalVM native image, with extremely fast startup time and lower memory requirements, which can be distributed as a single executable file.
Picocli generates beautiful documentation for your application (HTML, PDF and Unix man pages)."