Vorpal, a framework for building CLIs
vorpal.js.org
vorpal.js.org
#!/usr/bin/env bash
export REMOTE_ADDR="$1"
export PATH="$(dirname $0)/commands:$PATH"
export PS1='service:\$ '
bash
Now you do something like: $ server-cli https://myservice.com
service:$ which upload
/path/to/server-cli/commands/upload
$ upload ./my-file.png
uploading.......
All you are doing here is adding all your custom commands (which are just command line applications), and starting up the CLI by giving it some context of some sort. All I have here is $REMOTE_ADDR (which by convention a command like upload would read), but you could have auth or whatever.Along with this, you get a pretty workable programming language (shell), access to the local environment, access to the "standard library" of commands you know, and so on.
Start from scratch just because you don't want to read the manual of the right technology, convince lots of people to adopt with a cool site, spend the next 5 years updating your project to get to 10% of the 20yr old projects you ignored.
disclaimer: mostly javascript developer nowadays. but salty.
My purpose in writing Vorpal is to make building CLIs accessible to a wider audience. While haters will hate JS, it nevertheless has a very broad use and accessibility.
Since every up-to-date Linux system is shipped with Python, and argparse is part of the stdlib, I don't need to worry about argparse not being available. NodeJs adoption is going up, but if someone is building a CLI for a Rust project using Vorpal, then I have to install another piece of software and bloat my local system. Imagine this goes into my docker container it means the overall size of my container will increase. Of course I typically also install a bunch of packages along with my Python project anyway, like requests library, but because these libraries are typically needed for my backend anyway, the CLI's dependency on requests library is debt free. But in the case of me writing a Rust / Go / Python project but shipping a NodeJS CLI version, that's pretty insane. But don't take this the wrong way, I will write NodeJs and I will look at your library. You have great work, but I want to offer you my opinion on why few people outside of NodeJs will use this to build CLI for their X-language project.
I'm yet to encounter those.
I don't really disagree with you, but just pointing out there is some benefit to writing one's own CLI.
For now I use vagrant all the time when I am on Windows.
If you have git installed on your machine you have grep ( windows users) and most of linux command tools.
It's a personal preference, but I'd much prefer my programs (node or otherwise) treat the shell like the first class citizen it is and use it to its fullest extent.
How are globals used in the vorpal codebase? Is it going to be easier to write my tests (and actually get code coverage with istanbul working)?
I like the site, and the API overview. The library looks nice!
Yeah, it's got stdout piping methods, etc. which make it easy. It's also got UI manipulation methods so you can simulate user action. I haven't particularly had any trouble writing tests, but really it depends on your use case, which I'm not familiar with.
Also, a question about piping: in your example the "say" command is hard-coded to use the argument called "words", and the "reverse" command is hard-coded to read from standard input. This seems very limited compared to piping in a real shell, shouldn't each command receive a string/array of input and return output so they can be piped to each other without having to know about it?
On piping, I hard coded those to keep it short. Every single command can receive "args.stdin", which is a stdin stream from previous commands. To pipe out, the "this.log" command does all of the heavy lifting.
So all you would need to do is expect both "args.stdin" and "args.words" - that would cover input both from a directly executed command as well as stdin. This works very well in practice.
Actually, a REPL Xerox style is awesome, a pure UNIX style CLI not much.