Crates.io | qu |
lib.rs | qu |
version | 0.6.0 |
source | src |
created_at | 2020-02-07 15:03:54.865954 |
updated_at | 2022-10-22 19:51:50.300898 |
description | quick command line programs |
homepage | |
repository | https://github.com/derekdreery/qu |
max_upload_size | |
id | 205822 |
size | 23,240 |
qu
has opinions on CLI programs so you don't have to! It uses...
clap
for argument parsing,tracing
for logging infra,tokio
for async.Both tokio
and clap
usage are optional. If you don't want to use tracing
either than you
don't need this crate - just do fn main() { .. }
.
use qu::ick_use::*;
use std::path::PathBuf;
// This struct must not contain fields called `verbose` or `quiet` as these are used by `qu`.
#[derive(Debug, Clap)] // can use `clap::Parser` instead of `Clap`.
struct Opt {
file_name: Option<PathBuf>,
}
// This function must contain exactly one argument that implements `clap::Parser`, and should return
// `qu::ick_use::Result` (although in reality your selected return type is ignored and
// `qu::ick_use::Result` is always used). The body of th method is copied verbatim.
#[qu::ick]
fn main(opt: Opt) -> Result {
log::warn!("you'll see this unless you do -q");
log::info!(
"(use -v to get info) selected file: {:?}",
opt.file_name
);
Ok(())
}
Having arguments is optional - if you don't use them you'll still get -h
, -v
, and -q
.
use qu::ick_use::Result;
#[qu::ick]
fn main() -> Result {
log::info!("wooooo");
Ok(())
}
This crate contains the macro qu::ick
that sets up argument parsing, logging and error
handling with minimal boilerplate. It can do this because it decides for you what your
configuration should be. If you need a different configuration I'd recommend copying out
the generated code from the derive macro and tweaking it according to your needs.
This crate is based on quicli
and most of the ideas are directly copied from that crate.
quicli
may be an alternative if you don't like the opinions this crate has.
License: MIT/Apache-2.0