quicli
quicli copied to clipboard
Meta: Collect relevant use cases from the cookbook
The Rust Cookbook has a bunch of
simple examples that demonstrate good practices to accomplish common programming tasks, using the crates of the Rust ecosystem.
Many of these examples can work as CLI apps. We should go through them and see if there are some common patterns that we want to offer abstractions for.
My first try: I implemented this script to resize JPGs in #23
It uses glob, rayon, and image. I think of these three, glob and rayon are general purpose for CLI tools but dealing with image is more special purpose.
I can try implementing a simple archiver app based on the decompress a tarball & compress directory into tarball cookbooks.
This will use the flate2
and tar
crates.
Sure, go ahead! Feel free to post a link to a repo here. I'd love to hear what surprised you with quicli and what was missing :)
I can write a simple nc
-like tool emulating Listen on unused port TCP/IP cookbook example :)
Go right ahead! I'd to get feedback on this :) Even just a gist with a few lines of Rust code and a Cargo.toml work!
Here's the main.rs and the Cargo.toml
Looks good, @deg4uss3r!
This waits for the connection to close before printing, right? I think you could wrap tcp_listener
in a std::io::BufReader
and then use for line in buffered_tcp_listener.line()
to print the lines as they come it. Might be a nice experiment (and a cool example for a tutorial), haven't tested that, though!
By the way: You put these files into the same gist – and have it compile – by telling cargo the explicit path to your main.rs
. If you do this:
[[bin]]
path = "main.rs"
you can just drop the two files into the same directory.
I'm pretty sure you can specify the Ipv4Addr
type directly in your Cli struct, by the way.
I updated the main.rs gist per your suggestions. I like it a lot more now, but it does deviate a bit from the Cookbook example now.
@killercup feel free to steal ideas from the ergo cookbook examples.
I just pushed all of the major "core crates" and am going to start working on getting the ergo cookbook started.
I've been writing a simple cli tool using quicli for zip and tar files packing and unpacking:
My thoughts so far:
- Supporting the use
?
inmain!
is heaven sent! ✅ - The wildcard import
use quicli::prelude::*;
IMO hides information. I'm never sure what is available (in scope) and tracking imports is a bit hard. I had to consult the docs a lot! I'd prefer encouraging the use of explicit imports. - I hadn't used
StructOpt
before and it slowed me down figuring how it fits withclap
, more so when adding extra argument options e.g. argumentx
conflicts with argumenty
. But I'm happyclap
3 will be adopting whatStructOpt
has done. - The getting started guide uses
struct Cli
to define the arguments and uses it asargs
inmain!
. I fumbled a bit before I realisedargs
refers tostruct Cli
. Maybe renamingstruct Cli
tostruct Args
? 🤷♂️ (In hindsight this seems so trivial)
Thanks for the great feedback, @mattgathu!
I've been writing a simple cli tool using quicli for zip and tar files packing and unpacking
Cool! Do you have a public repo? I'd love to collect some "quicli in the wild" links… and opened #62 for that :)
The wildcard import use quicli::prelude::*; IMO hides information.
Very good point. This because of two things:
- I'm lazy (we can fix that)
- Exporting (proc-)macros is AFAIK only possible with
pub foo::*
syntax (we can't easily fix that)
I hadn't used StructOpt before and it slowed me down figuring how it fits with clap
Ah, interesting! Do you think it'd make sense to cover more advanced structopt usage in a guide? (How to do subcommands was requested, too.)
The getting started guide uses struct Cli to define the arguments and uses it as args in main!. I fumbled a bit before I realised args refers to struct Cli.
Yeah, sorry, that's not explicitly mentioned I believe. The closure-like syntax in main!(|args: Cli| { … });
was used to suggest that args
is of type Cli
, but that may not be obvious, especially because you usually don't need type annotations in Rust's closures.