My team maintains a number of increasingly complex CLI tools, mostly written in Bash, though some is Scala in order to share code with other applications.
We’re looking at migrating these to a more testable, modern language.
Python is the de-facto language for this at Twitter, but I also wanted to explore how Rust would fit the bill. These are my notes.
What are we already doing with Bash?
- Figure out git root
- Parse args & print help
- Computed default values for arguments
- Shell out to other executables (including jars,
pantsand other CLI tools) and pipe their output to files
- Handle errors in sub-processes
- Log to
- Error messages
- Manipulate paths
- URL encode
- Read from
- Open URLs (shell out to
- Proxy args onto other tools
- GET/POST URLs (compressed)
jqor JSON parse
git— has to be CLI to use
These crates might be useful:
- Arg-parser — clap
- Serde — serde
- vitiral/path_abs: Absolute serializable path types and associated methods.
- killercup/assert_cli: Test CLI Applications in Rust.
- vitiral/termstyle: create and test the style and formatting of text in your terminal applications
- colin-kiegel/rust-pretty-assertions: Overwrite
assert_eq!with a drop-in replacement, adding a colorful diff.
- brson/stdx: The missing batteries of Rust
- vitiral/stdcli: (pre-alpha) rust meta library for cli applications, which contains the following (and more)…
- Stebalien/tempfile: Temporary file library for rust
- daboross/fern: Simple, efficient logging for Rust
We won’t actually be pushing Rust too hard: mostly the existing tools wrangle paths and shell out to other executables. For the most part, the code will be very imperative and will handle errors & exit immediately.
Pants currently has no support for rust although parts of its core are being rewritten in the language. There is appetite at Twitter for using Rust, but only a small community who already have experience.
The biggest con of the idea is requiring the GraphQL team to learn Rust when there is Python within the team already, and the risk of reverting this decision in the future as the team changes or if Rust moves to a negative standing on our tech radar.