usage: added control section

master
Avril 4 years ago
parent 4a1a6171a1
commit 5482ee6d82
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -28,8 +28,12 @@ impl Opt
/// opt!("--long"; "Description", ["OTHER", "OTHER 2"], "value"); // --long, --other: Description (see `OTHER`, `OTHER 2`) (default: `value`)
/// ```
#[macro_export] macro_rules! opt {
(where $desc:literal) => {
Opt(&[], None, $desc, 2, None, None)
(where $desc:literal $(, [$($see:literal),*])?) => {
{
let o = Opt(&[], None, $desc, 2, None, None);
$(let o = o.with_slice(&[$($see),*]);)?
o
}
};
(in $supersection:literal) => {
Opt(&[], None, $supersection, 1, None, None)
@ -88,6 +92,9 @@ impl fmt::Display for Opt
for line in desc.split('\n') {
writeln!(f, "> {}", line)?;
}
if let Some(strings) = self.5 {
writeln!(f, "> (see {})", strings.iter().map(|x| iter!["`".clear(), x.underline(), "`".clear()]).flat_join(", "))?;
}
return Ok(());
},
(&[], desc, 1) => return write!(f, "[{}]:", desc.bold().bright_blue()),
@ -171,14 +178,22 @@ impl fmt::Display for Opt
opt!("I/O"),
opt!(where "Child I/O related operations"),
opt!("inherit"; * 3 "Inherit the i/o from parent (this) process"),
opt!("close"; * 4 "Close the I/O"),
opt!("inherit"; * 3 "Inherit the stream from parent (this) process"),
opt!("close"; * 4 "Close the stream"),
opt!("ignore"; * 3 "Don't close the stream, but don't do anything with it"),
opt!("file" => "filename"; * 2 "Use this file as input / output.\n\t\t\t\tFor input, if the file is not readable or nonexistant, it causes a panic.\n\t\t\t\tFor output, it appends to the file or uses a new one for output.\n\t\t\t\tIf this is not possible, it causes a panic.\n\t\t\t\tTo overwrite the files instead of appending, use file:clobber"),
opt!("file:clobber" => "filename"; "Only valid for outputs, overwrite the file and write to it, instead of appending"),
opt!("stderr"; * 3 "Redirect stdout to the same location as stderr.\n\t\t\t\tIf there is a cycle detected here, or it is used for anything other that stdout, there is a panic"),
opt!("stdout"; * 3 "Redirect stderr to the same location as stdout.\n\t\t\t\tIf there is a cycle detected here, or it is used for anything other that stdout, there is a panic"),
opt!("Control"),
opt!(where "Controlling how processes are spawned\nThese can be overridden individually with explicit inputs"),
opt!("--uid" => "uid"; "Run as user specified by `uid`. Panics if `uid` is not a valid user id\n\t\t(note: Process must be ran as root to use this option)"),
opt!("--user" => "user"; "Same as `--uid`, except specified user is by name instead of uid"),
opt!("--gid" => "gid"; "Same as `--uid`, except runs as specific group instead of user"),
opt!("--group" => "group"; "Same as `--gid`, except specified group is by name instead of gid"),
opt!()
]
}
@ -187,7 +202,15 @@ impl fmt::Display for Opt
{
iter![
opt!(in "COMPLETION"),
opt!(where "Directives for how to handle process completion"),
opt!(where "Directives for how to handle abnormal process completion (i.e. non-zero exit codes)\nThis does not apply to `detached` processes", ["DETACHING"]),
opt!("ignore"; * 2 "Ignore process return code"),
opt!("supercede"; * 2 "If return code is a non-zero code, use it as the return code for the parent (this) process.\n\t\t\tIf there are multiple non-zero return codes, it is not specified which is returned"),
opt!("terminate"; * 2 "If return code is a non-zero code, abort all running children and return the code as this process' return code immediately"),
opt!("wait"; * 3 "Same as `terminate`, except waits for currently active processes to complete before aborting"),
opt!("log"; * 3 "Write the code to this process' `stderr` if non-zero"),
opt!("file" => "filename"; "If non-zero, write the code to a file if non-zero. If unable to write to the file, it is ignored"),
opt!("retry" => "number"; "If non-zero, restart the process up to `number` times.\n\t\t\tIf `number` if 'inf', retry indefinately (this can cause an infinite loop if program never completes with zero exit code)"),
opt!()
]

Loading…
Cancel
Save