2023-01-20 23:53:28 -05:00
|
|
|
use super::Cmd;
|
2023-01-21 18:25:09 -05:00
|
|
|
use clap::{Arg, ArgMatches, Command};
|
2023-02-05 23:50:59 -05:00
|
|
|
use mode::Parser;
|
2023-02-21 00:07:16 -05:00
|
|
|
use shitbox::args;
|
2023-02-04 08:54:27 -05:00
|
|
|
use std::error::Error;
|
2023-01-20 23:53:28 -05:00
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct MkFifo;
|
|
|
|
|
|
|
|
impl Cmd for MkFifo {
|
|
|
|
fn cli(&self) -> clap::Command {
|
|
|
|
Command::new("mkfifo")
|
|
|
|
.about("make FIFO special files")
|
|
|
|
.author("Nathan Fisher")
|
|
|
|
.version(env!("CARGO_PKG_VERSION"))
|
|
|
|
.args([
|
|
|
|
Arg::new("mode")
|
|
|
|
.help(
|
|
|
|
"Set the file permission bits of the newly-created \
|
|
|
|
FIFO to the specified mode value.",
|
|
|
|
)
|
|
|
|
.long_help(
|
|
|
|
"Set the file permission bits of the newly-created \
|
|
|
|
FIFO to the specified mode value. The mode option-argument \
|
|
|
|
shall be the same as the mode operand defined for the \
|
|
|
|
chmod utility. In the symbolic_mode strings, the op \
|
|
|
|
characters '+' and '-' shall be interpreted relative to \
|
|
|
|
an assumed initial mode of a=rw.",
|
|
|
|
)
|
|
|
|
.short('m')
|
|
|
|
.long("mode")
|
|
|
|
.value_name("MODE")
|
|
|
|
.num_args(1),
|
2023-01-21 18:25:09 -05:00
|
|
|
args::verbose(),
|
2023-01-20 23:53:28 -05:00
|
|
|
Arg::new("file").num_args(1..).required(true),
|
|
|
|
])
|
|
|
|
}
|
|
|
|
|
2023-02-04 08:54:27 -05:00
|
|
|
fn run(&self, matches: &ArgMatches) -> Result<(), Box<dyn Error>> {
|
2023-01-20 23:53:28 -05:00
|
|
|
let mode = if let Some(m) = matches.get_one::<String>("mode") {
|
|
|
|
Parser::new(0o666).parse(m)?
|
|
|
|
} else {
|
|
|
|
0o666
|
|
|
|
};
|
|
|
|
if let Some(files) = matches.get_many::<String>("file") {
|
|
|
|
for f in files {
|
2023-02-02 23:34:37 -05:00
|
|
|
stat::mkfifo(f.as_str(), mode)?;
|
2023-01-20 23:53:28 -05:00
|
|
|
if matches.get_flag("verbose") {
|
|
|
|
println!(
|
|
|
|
"{}: created pipe '{f}' with mode {mode:o}",
|
|
|
|
self.cli().get_name()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2023-02-05 23:50:59 -05:00
|
|
|
fn path(&self) -> Option<shitbox::Path> {
|
|
|
|
Some(shitbox::Path::UsrBin)
|
2023-01-20 23:53:28 -05:00
|
|
|
}
|
|
|
|
}
|