16 releases
0.2.7 | Nov 15, 2022 |
---|---|
0.2.4 | Oct 3, 2022 |
0.2.3 | Jun 22, 2022 |
0.2.1 | Mar 25, 2022 |
0.1.1 | Jul 15, 2020 |
#446 in Filesystem
3,630 downloads per month
Used in 3 crates
49KB
1K
SLoC
clio
clio is a rust library for parsing CLI file names.
It implements the standard unix conventions of when the file name is -
then
sending the data to stdin/stdout
// a cat replacement
fn main() -> clio::Result<()> {
let args: Vec<_> = std::env::args_os().collect();
let mut input = clio::Input::new(&args[1])?;
std::io::copy(&mut input, &mut std::io::stdout())?;
Ok(())
}
lib.rs
:
clio is a library for parsing CLI file names.
It implemts the standard unix convetions of when the file name is "-" then sending the data to stdin/stdout as apropriate
Usage
Input
s and Output
s can be created directly from args in args_os
.
They will error if the file cannot be opened for any reason
// a cat replacement
fn main() -> clio::Result<()> {
for arg in std::env::args_os() {
let mut input = clio::Input::new(&arg)?;
std::io::copy(&mut input, &mut std::io::stdout())?;
}
Ok(())
}
With the clap-parse
feature they are also desgined to be used with clap 3.2.
See the older docs for examples of older clap/structopt
# #[cfg(feature="clap-parse")]{
use clap::Parser;
use clio::*;
#[derive(Parser)]
#[clap(name = "cat")]
struct Opt {
/// Input file, use '-' for stdin
#[clap(value_parser, default_value="-")]
input: Input,
/// Output file '-' for stdout
#[clap(long, short, value_parser, default_value="-")]
output: Output,
}
fn main() {
let mut opt = Opt::parse();
std::io::copy(&mut opt.input, &mut opt.output).unwrap();
}
# }
Features
clap-parse
Implements ValueParserFactory
for all the types and
adds a bad implmentation of [Clone
] to all types as well to keep clap
happy.
HTTP Client
If a url is passed to Input::new
then it will perform and HTTP GET
.
If a url is passed to Output::new
then it will perform and HTTP PUT
.
You can use SizedOutput
to set the size before the upload starts e.g.
needed if you are sending a file to S3.
http-ureq
bundles in ureq as a HTTP client.
http-curl
bundles in curl as a HTTP client.
Dependencies
~0–10MB
~178K SLoC