|
3 | 3 | // For the full copyright and license information, please view the LICENSE |
4 | 4 | // file that was distributed with this source code. |
5 | 5 |
|
6 | | -use clap::{Arg, ArgAction, Command, builder::PossibleValue}; |
| 6 | +// spell-checker:ignore espidf nopipe |
| 7 | + |
7 | 8 | use std::ffi::OsString; |
8 | 9 | use std::fs::OpenOptions; |
9 | 10 | use std::io::{Error, ErrorKind, Read, Result, Write, stderr, stdin, stdout}; |
10 | 11 | use std::path::PathBuf; |
11 | 12 | use uucore::display::Quotable; |
12 | 13 | use uucore::error::{UResult, strip_errno}; |
13 | | -use uucore::format_usage; |
14 | | -use uucore::parser::shortcut_value_parser::ShortcutValueParser; |
15 | 14 | use uucore::translate; |
16 | 15 |
|
17 | | -// spell-checker:ignore espidf nopipe |
| 16 | +mod cli; |
| 17 | +pub use crate::cli::uu_app; |
| 18 | +use crate::cli::{Options, OutputErrorMode, options}; |
18 | 19 |
|
19 | 20 | #[cfg(target_os = "linux")] |
20 | 21 | use uucore::signals::ensure_stdout_not_broken; |
21 | 22 | #[cfg(unix)] |
22 | 23 | use uucore::signals::{disable_pipe_errors, ignore_interrupts}; |
23 | 24 |
|
24 | | -mod options { |
25 | | - pub const APPEND: &str = "append"; |
26 | | - pub const IGNORE_INTERRUPTS: &str = "ignore-interrupts"; |
27 | | - pub const FILE: &str = "file"; |
28 | | - pub const IGNORE_PIPE_ERRORS: &str = "ignore-pipe-errors"; |
29 | | - pub const OUTPUT_ERROR: &str = "output-error"; |
30 | | -} |
31 | | - |
32 | | -#[allow(dead_code)] |
33 | | -struct Options { |
34 | | - append: bool, |
35 | | - ignore_interrupts: bool, |
36 | | - ignore_pipe_errors: bool, |
37 | | - files: Vec<OsString>, |
38 | | - output_error: Option<OutputErrorMode>, |
39 | | -} |
40 | | - |
41 | | -#[derive(Clone, Debug)] |
42 | | -enum OutputErrorMode { |
43 | | - /// Diagnose write error on any output |
44 | | - Warn, |
45 | | - /// Diagnose write error on any output that is not a pipe |
46 | | - WarnNoPipe, |
47 | | - /// Exit upon write error on any output |
48 | | - Exit, |
49 | | - /// Exit upon write error on any output that is not a pipe |
50 | | - ExitNoPipe, |
51 | | -} |
52 | | - |
53 | 25 | #[uucore::main] |
54 | 26 | pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
55 | 27 | let matches = uucore::clap_localization::handle_clap_result(uu_app(), args)?; |
@@ -84,69 +56,6 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
84 | 56 | tee(&options).map_err(|_| 1.into()) |
85 | 57 | } |
86 | 58 |
|
87 | | -pub fn uu_app() -> Command { |
88 | | - Command::new("tee") |
89 | | - .version(uucore::crate_version!()) |
90 | | - .help_template(uucore::localized_help_template("tee")) |
91 | | - .about(translate!("tee-about")) |
92 | | - .override_usage(format_usage(&translate!("tee-usage"))) |
93 | | - .after_help(translate!("tee-after-help")) |
94 | | - .infer_long_args(true) |
95 | | - // Since we use value-specific help texts for "--output-error", clap's "short help" and "long help" differ. |
96 | | - // However, this is something that the GNU tests explicitly test for, so we *always* show the long help instead. |
97 | | - .disable_help_flag(true) |
98 | | - .arg( |
99 | | - Arg::new("--help") |
100 | | - .short('h') |
101 | | - .long("help") |
102 | | - .help(translate!("tee-help-help")) |
103 | | - .action(ArgAction::HelpLong), |
104 | | - ) |
105 | | - .arg( |
106 | | - Arg::new(options::APPEND) |
107 | | - .long(options::APPEND) |
108 | | - .short('a') |
109 | | - .help(translate!("tee-help-append")) |
110 | | - .action(ArgAction::SetTrue) |
111 | | - .overrides_with(options::APPEND), |
112 | | - ) |
113 | | - .arg( |
114 | | - Arg::new(options::IGNORE_INTERRUPTS) |
115 | | - .long(options::IGNORE_INTERRUPTS) |
116 | | - .short('i') |
117 | | - .help(translate!("tee-help-ignore-interrupts")) |
118 | | - .action(ArgAction::SetTrue), |
119 | | - ) |
120 | | - .arg( |
121 | | - Arg::new(options::FILE) |
122 | | - .action(ArgAction::Append) |
123 | | - .value_hint(clap::ValueHint::FilePath) |
124 | | - .value_parser(clap::value_parser!(OsString)), |
125 | | - ) |
126 | | - .arg( |
127 | | - Arg::new(options::IGNORE_PIPE_ERRORS) |
128 | | - .short('p') |
129 | | - .help(translate!("tee-help-ignore-pipe-errors")) |
130 | | - .action(ArgAction::SetTrue), |
131 | | - ) |
132 | | - .arg( |
133 | | - Arg::new(options::OUTPUT_ERROR) |
134 | | - .long(options::OUTPUT_ERROR) |
135 | | - .require_equals(true) |
136 | | - .num_args(0..=1) |
137 | | - .default_missing_value("warn-nopipe") |
138 | | - .value_parser(ShortcutValueParser::new([ |
139 | | - PossibleValue::new("warn").help(translate!("tee-help-output-error-warn")), |
140 | | - PossibleValue::new("warn-nopipe") |
141 | | - .help(translate!("tee-help-output-error-warn-nopipe")), |
142 | | - PossibleValue::new("exit").help(translate!("tee-help-output-error-exit")), |
143 | | - PossibleValue::new("exit-nopipe") |
144 | | - .help(translate!("tee-help-output-error-exit-nopipe")), |
145 | | - ])) |
146 | | - .help(translate!("tee-help-output-error")), |
147 | | - ) |
148 | | -} |
149 | | - |
150 | 59 | fn tee(options: &Options) -> Result<()> { |
151 | 60 | #[cfg(unix)] |
152 | 61 | { |
|
0 commit comments