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.
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 '{}' before this argument?",iffirst_is_positional{"-exec{{}}"}else{"-exec"},ifsecond_is_positional{"-exec{{}}"}else{"-exec"},EXEC_MODE_STRING_TERMINATOR)
}
}
}
letmutargs=args.into_iter().map(Into::into);
letmutargs=args.into_iter().map(Into::into);
letmutoutput=Options::default();
letmutidx=0;
//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...
//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));
}
/// 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?