3 ms·
If I was making an interactive command line, I think I'd want to do it all in shell. Let's say it's a CLI that interacts with a remote server, then I might hav
by ianbicking 11y ago
If I was making an interactive command line, I think I'd want to do it all in shell. Let's say it's a CLI that interacts with a remote server, then I might have a "script" that "starts" a custom CLI by doing:
#!/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.
- dc2 11y agoTrue. Though in Node, you can make calls to standard programs, so it can act pretty seamlessly. And there's already a lot of direction towards supporting a lot of familiar methods and more. Like this: https://www.npmjs.com/package/cash https://www.npmjs.com/package/cash
- jorgecurio 11y agonpm install cash-ls -g doesn't work....would love to use this
- dc2 11y ago* Cash isn't released yet - that's why there's no GH repo. That's my next pjt :)
- viperscape 11y agocash looks great, but how does chmod work on Windows?
- Spiritus 11y agoPretty neat. Just need to remember to restore the environment variables afterwards, especially $PATH.
- xdissent 11y agoThey're only exported to the sub shell (bash on last line of cli script). Quitting the sub shell would restore them. Perhaps you were confused by the absence of `service:$` in the prompt for the upload command, which I believe was an oversight.