1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
//! OS-string argv helpers (issue #213).
//!
//! `oo` reads its command line with `std::env::args_os`, so no argument is
//! ever converted with a panicking API. On unix, wrapped-command arguments
//! are passed to the child verbatim as [`OsString`] bytes; text that `oo`
//! itself consumes (reserved-subcommand names and arguments, labels, history)
//! is converted lossily with `OsStr::to_string_lossy` (see #213) or rejected
//! by [`reject_non_utf8_reserved_args`] (see #213).
use OsString;
/// The stderr line printed when an argument that `oo` itself must interpret
/// is not valid UTF-8 (see #213).
pub const NON_UTF8_ARG_ERR: &str = "oo: argument is not valid UTF-8";
/// The reserved subcommand names that `oo` itself handles. A non-UTF-8 first
/// word that is not in this set is simply the command to run (see #213).
pub const RESERVED_SUBCOMMANDS: & = &;
/// The argument's text, when it is valid UTF-8; `Err(NON_UTF8_ARG_ERR)`
/// otherwise.
///
/// Reserved subcommand names and `oo`'s own option values are matched only
/// as valid UTF-8 (see #213): `OsStr::to_str` is `None` for non-UTF-8 content
/// on every platform, so this check runs on the OS string before any lossy
/// conversion, identically on unix and non-unix.
/// Pre-validate the arguments of a reserved subcommand before dispatch (see
/// #213). Returns `Ok(())` when every argument `oo` itself consumes is valid
/// UTF-8, or `Err(NON_UTF8_ARG_ERR)` for the first violation.
///
/// The UTF-8 policy lives here, next to [`utf8_or`], so `main` only owns the
/// exit decision:
///
/// - a non-UTF-8 first word is simply the command to run: it can never match
/// a reserved name, so the arguments pass through as bytes (the non-UTF-8
/// case returns `Ok` here and is rejected by nobody);
/// - for a reserved first word, every argument is oo-owned and must be valid
/// UTF-8 — except `learn`, where only the `--hint` value is oo-owned and
/// the wrapped command's arguments pass through as raw bytes.
/// Join OS-string arguments with spaces, converting each lossily, for the
/// command line recorded in labels, history, and the learn payload (see
/// #213).