main: Added `parse_args()`: Parses args, converts error to eyre::Report, and adds section for suggestion (TODO: Implement `--help`) and section on which args existed.
/// Issue a warning when `-exec{}` is provided as an argument, but no positional arguments (`{}`) are specified in the argument list to the command.
letmutidx=0;
#[cold]
//XXX: When `-exec{}` is provided, but no `{}` arguments are found, maybe issue a warning with `if_trace!(warning!())`? There are valid situations to do this in, but they are rare...
if_trace!(warn!("-exec{{}} provided with no positional arguments ({}), there will be no replacement with the data. Did you mean `-exec`?",POSITIONAL_ARG_STRING));
try_parse_for!(@assert_parser_okay$parser);
//_assert_is_closure(&$then); //XXX: There isn't a good way to tell without having to specify some bound on return type...
/// 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 '{}' before this argument?",iffirst_is_positional{"-exec{{}}"}else{"-exec"},ifsecond_is_positional{"-exec{{}}"}else{"-exec"},EXEC_MODE_STRING_TERMINATOR)
//XXX: When `-exec{}` is provided, but no `{}` arguments are found, maybe issue a warning with `if_trace!(warning!())`? There are valid situations to do this in, but they are rare...
}
todo!("//TODO: Parse `args` into `Options`")
Ok(())
};
parser()
.with_index(idx)
.map(move|_|output)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
#[derive(Debug)]
pubenumArgParseError
pubenumArgParseError
{
{
/// With an added argument index.
WithIndex(usize,Box<ArgParseError>),
/// Returned when an invalid or unknown argument is found
/// Returned when an invalid or unknown argument is found
UnknownOption(OsString),
UnknownOption(OsString),
/// Returned when the argument, `argument`, is passed in an invalid context by the user.
/// Returned when the argument, `argument`, is passed in an invalid context by the user.
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)
/// Execution of commands (if passed) **always** happens *after* the copy to `stdout`, but *before* the **close** of `stdout`. If the copy to `stdout` fails, the exec will not be executed regardless of if the mode required is actually using `stdout`.
/// Execution of commands (if passed) **always** happens *after* the copy to `stdout`, but *before* the **close** of `stdout`. If the copy to `stdout` fails, the exec will not be executed regardless of if the mode required is actually using `stdout`.
/// The process shall always wait for the child to terminate before exiting. If the child daemon forks, that fork is not followed, and the process exists anyway.
/// The process shall always wait for the child to terminate before exiting. If the child daemon forks, that fork is not followed, and the process exists anyway.
/// Ideally, A `SIGHUP` handler should be registered, which tells the parent to stop waiting on the child and exit now. TODO: The behaviour of the child is unspecified if this happens. It may be killed, or re-attached to `init`. But the return code of the parent should always be `0` in this case.
/// Ideally, A `SIGHUP` handler should be registered, which tells the parent to stop waiting on the child and exit now. TODO: The behaviour of the child is unspecified if this happens. It may be killed, or re-attached to `init`. But the return code of the parent should always be `0` in this case.
.join_by_clone(std::borrow::Cow::Borrowed(" "))//XXX: this can be replaced by `flat_map() -> [x, " "]` really... Dunno which will be faster...
.collect::<String>()
.header("The program arguments were"))
.with_suggestion(||"Try passing `--help`")
}
#[cfg_attr(feature="logging", instrument(err))]
#[cfg_attr(feature="logging", instrument(err))]
fnmain()-> eyre::Result<()>{
fnmain()-> eyre::Result<()>{
init()?;
init()?;
feature_check()?;
feature_check()?;
if_trace!(debug!("initialised"));
if_trace!(debug!("initialised"));
//TODO: How to cleanly feature-gate `args`?
letopt=parse_args()?;
//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?
//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?