args: Added visitor-pattern argument parsing. Fixed bug in `try_parse_for!()` which `continue`d on the wrong branch. Improved specific and general error messages regarding arguments. Parsing for `-exec/{}` works! A correct `Options` struct is produced, edge-and error- cases are handled correctly with informative messages (TODO: Implement `--help`.)
TODO: Should `-exec{} {}` be valid? That is, should we allow the use of `fexecve()` instead of `execve()` in the special case where the command itself of a positional exec is the positional replacement string? This may be useful, but also dangerous and perhaps not possible with a memfd or with a pipe. We"d also need to `ioctl()` set to permissions to RX instead of RO, and any subsequent instances of the replacement string *should probably* be `dup()`"d file-descriptors with -X permission set. Note for later. For now, a warning is ommitted if this is present, explaining to the user that executing the input is not (yet??) supported.
Fortune for collect's current commit: Future small blessing − 末小吉
parser.parse(/*if_trace!{true arg.clone(); */std::mem::replace(arg,OsString::default())/*}*/,rest).map_err(Into::into)//This clone is not needed, the argument is captured by `try_parse_with` (in debug) and `parse` (in warning) already.
if_trace!(warn!("-exec{{}} provided with no positional arguments ({}), there will be no replacement with the data. Did you mean `-exec`?",POSITIONAL_ARG_STRING));
if_trace!(warn!("-exec{{}} provided with no positional arguments `{}`, there will be no replacement with the data. Did you mean `-exec`?",POSITIONAL_ARG_STRING));
}
/// Issue a warning if the user apparently meant to specify two `-exec/{}` arguments to `collect`, but seemingly is accidentally is passing the `-exec/{}` string as an argument to the first.
warn!("{} provided, but argument to command {command:?} number #{argument_number} is `{}`. Are you missing the terminator '{}' before this argument?",iffirst_is_positional{"-exec{}"}else{"-exec"},ifsecond_is_positional{"-exec{}"}else{"-exec"},EXEC_MODE_STRING_TERMINATOR)
}
}
/// Issue a warning if the user apparently missed a command to `-exec{}`, and has typed `-exec{} {}`...
//TODO: Do we make this a feature in the future? Being able to `fexecve()` the input received?
pubfnexecp_command_not_substituted()
{
if_trace!{
warn!("-exec{{}} provided with a command as the positional replacement string `{}`. Commands are not substituted. Are you missing a command? (Note: Currently, `fexecve()`ing the input is not supported.)",POSITIONAL_ARG_STRING)
}
}
/// Issue a warning if the user apparently attempted to terminate a `-exec/{}` argument, but instead made the command of the `-exec/{}` itself the terminator.
warn!("{exec_arg_str} provided with a command that is the -exec/-exec{{}} terminator character `{}`. The sequence is not terminated, and instead the terminator character itself is taken as the command to execute. Did you miss a command before the terminator?",EXEC_MODE_STRING_TERMINATOR)
//TODO: maybe look into fd SEALing? Maybe we can prevent a consumer process from reading from stdout until we've finished the transfer. The name SEAL sounds like it might have something to do with that?