pub struct Output { /* private fields */ }
Expand description
A struct that represents a command line output stream,
either Stdout
or a File
along with it’s path
It is designed to be used with the clap
crate when taking a file name as an
argument to CLI app
use clap::Parser;
use clio::Output;
#[derive(Parser)]
struct Opt {
/// path to file, use '-' for stdout
#[clap(value_parser)]
output_file: Output,
/// default name for file is user passes in a directory
#[clap(value_parser = clap::value_parser!(Output).default_name("run.log"))]
log_file: Output,
/// Write output atomically using temp file and atomic rename
#[clap(value_parser = clap::value_parser!(Output).atomic())]
config_file: Output,
}
Implementations§
source§impl Output
impl Output
sourcepub fn new<S: TryInto<ClioPath>>(path: S) -> Result<Self>
pub fn new<S: TryInto<ClioPath>>(path: S) -> Result<Self>
Constructs a new output either by opening/creating the file or for ‘-’ returning stdout
sourcepub fn is_local(&self) -> bool
pub fn is_local(&self) -> bool
Returns true if this Output is on the local file system, as opposed to point to stdin/stout or a URL
sourcepub fn try_from_os_str(path: &OsStr) -> Result<Self, OsString>
pub fn try_from_os_str(path: &OsStr) -> Result<Self, OsString>
Constructs a new output either by opening/creating the file or for ‘-’ returning stdout
The error is converted to a OsString
so that stuctopt can show it to the user.
It is recommended that you use TryFrom::try_from
and clap 3.0 instead.
sourcepub fn finish(self) -> Result<()>
pub fn finish(self) -> Result<()>
Syncs the file to disk or closes any HTTP connections and returns any errors or on the file if a regular file For atomic files this must be called to perform the final atomic swap
Trait Implementations§
source§impl Clone for Output
Available on crate feature clap-parse
only.
impl Clone for Output
clap-parse
only.Opens a new handle on the file from the path that was used to create it Probably a bad idea to have two write handles to the same file or to std in There is no effort done to make the clone be at the same position as the original
This will panic if the file has been deleted
Only included when using the clap-parse
feature as it is needed for value_parser
source§impl Seek for Output
impl Seek for Output
source§fn seek(&mut self, pos: SeekFrom) -> IoResult<u64>
fn seek(&mut self, pos: SeekFrom) -> IoResult<u64>
1.55.0 · source§fn rewind(&mut self) -> Result<(), Error>
fn rewind(&mut self) -> Result<(), Error>
source§fn stream_len(&mut self) -> Result<u64, Error>
fn stream_len(&mut self) -> Result<u64, Error>
seek_stream_len
)source§impl ValueParserFactory for Output
Available on crate feature clap-parse
only.
impl ValueParserFactory for Output
clap-parse
only.§type Parser = OsStrParser<Output>
type Parser = OsStrParser<Output>
ValueParser
]. Read moresource§fn value_parser() -> Self::Parser
fn value_parser() -> Self::Parser
Self::Parser
]source§impl Write for Output
impl Write for Output
source§fn flush(&mut self) -> IoResult<()>
fn flush(&mut self) -> IoResult<()>
source§fn write(&mut self, buf: &[u8]) -> IoResult<usize>
fn write(&mut self, buf: &[u8]) -> IoResult<usize>
source§fn is_write_vectored(&self) -> bool
fn is_write_vectored(&self) -> bool
can_vector
)1.0.0 · source§fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
source§fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>
write_all_vectored
)