|
5 | 5 |
|
6 | 6 | // spell-checker:ignore (ToDO) fname, algo, bitlen |
7 | 7 |
|
8 | | -use std::ffi::OsStr; |
9 | | - |
10 | 8 | use clap::Command; |
11 | 9 | use uu_checksum_common::{ChecksumCommand, checksum_main, default_checksum_app, options}; |
12 | 10 |
|
@@ -42,48 +40,6 @@ fn print_cpu_debug_info() { |
42 | 40 | } |
43 | 41 | } |
44 | 42 |
|
45 | | -/// cksum has a bunch of legacy behavior. We handle this in this function to |
46 | | -/// make sure they are self contained and "easier" to understand. |
47 | | -/// |
48 | | -/// Returns a pair of boolean. The first one indicates if we should use tagged |
49 | | -/// output format, the second one indicates if we should use the binary flag in |
50 | | -/// the untagged case. |
51 | | -fn handle_tag_text_binary_flags<S: AsRef<OsStr>>( |
52 | | - args: impl Iterator<Item = S>, |
53 | | -) -> UResult<(bool, bool)> { |
54 | | - let mut tag = true; |
55 | | - let mut binary = false; |
56 | | - let mut text = false; |
57 | | - |
58 | | - // --binary, --tag and --untagged are tight together: none of them |
59 | | - // conflicts with each other but --tag will reset "binary" and "text" and |
60 | | - // set "tag". |
61 | | - |
62 | | - for arg in args { |
63 | | - let arg = arg.as_ref(); |
64 | | - if arg == "-b" || arg == "--binary" { |
65 | | - text = false; |
66 | | - binary = true; |
67 | | - } else if arg == "--text" { |
68 | | - text = true; |
69 | | - binary = false; |
70 | | - } else if arg == "--tag" { |
71 | | - tag = true; |
72 | | - binary = false; |
73 | | - text = false; |
74 | | - } else if arg == "--untagged" { |
75 | | - tag = false; |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - // Specifying --text without ever mentioning --untagged fails. |
80 | | - if text && tag { |
81 | | - return Err(ChecksumError::TextWithoutUntagged.into()); |
82 | | - } |
83 | | - |
84 | | - Ok((tag, binary)) |
85 | | -} |
86 | | - |
87 | 43 | /// Sanitize the `--length` argument depending on `--algorithm` and `--length`. |
88 | 44 | fn maybe_sanitize_length( |
89 | 45 | algo_cli: Option<AlgoKind>, |
@@ -122,13 +78,18 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { |
122 | 78 | .map(String::as_str); |
123 | 79 |
|
124 | 80 | let length = maybe_sanitize_length(algo_cli, input_length)?; |
| 81 | + let tag = !matches.get_flag(options::UNTAGGED); |
| 82 | + let text = matches.get_flag(options::TEXT); |
125 | 83 |
|
126 | | - let (tag, binary) = handle_tag_text_binary_flags(std::env::args_os())?; |
| 84 | + //Specifying --text without ever mentioning --untagged fails. |
| 85 | + if text && tag { |
| 86 | + return Err(ChecksumError::TextWithoutUntagged.into()); |
| 87 | + } |
127 | 88 |
|
128 | 89 | let output_format = OutputFormat::from_cksum( |
129 | 90 | algo_cli.unwrap_or(AlgoKind::Crc), |
130 | 91 | tag, |
131 | | - binary, |
| 92 | + !text, |
132 | 93 | /* raw */ matches.get_flag(options::RAW), |
133 | 94 | /* base64 */ matches.get_flag(options::BASE64), |
134 | 95 | ); |
|
0 commit comments