-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcopy_with_defaults.rs
More file actions
28 lines (24 loc) · 846 Bytes
/
copy_with_defaults.rs
File metadata and controls
28 lines (24 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! A simple program using `kommand` that copies from an
//! `InputByteStream` into an `OutputByteStream`.
use clap::{ambient_authority, TryFromOsArg};
use nameless::{InputByteStream, OutputByteStream};
use std::io::copy;
/// # Arguments
///
/// * `input` - Input source, stdin if not present
/// * `output` - Output sink, stdout if not present
#[kommand::main]
fn main(input: Option<InputByteStream>, output: Option<OutputByteStream>) -> anyhow::Result<()> {
let mut input = if let Some(input) = input {
input
} else {
InputByteStream::try_from_os_str_arg("-".as_ref(), ambient_authority())?
};
let mut output = if let Some(output) = output {
output
} else {
OutputByteStream::try_from_os_str_arg("-".as_ref(), ambient_authority())?
};
copy(&mut input, &mut output)?;
Ok(())
}