This commit is contained in:
sylvestre
2023-03-30 02:40:47 +00:00
parent 9903fb5b2d
commit 81f793582c
6 changed files with 21 additions and 15 deletions
+10 -10
View File
@@ -469,7 +469,7 @@
<span class="kw">use </span>std::io::{BufRead, BufReader};
<span class="kw">use </span>std::path::PathBuf;
<span class="kw">use </span>uucore::display::Quotable;
<span class="attr">#[cfg(not(any(target_os = <span class="string">&quot;macos&quot;</span>, target_os = <span class="string">&quot;redox&quot;</span>)))]
<span class="attr">#[cfg(not(any(target_os = <span class="string">&quot;redox&quot;</span>)))]
</span><span class="kw">use </span>uucore::error::FromIo;
<span class="kw">use </span>uucore::error::{UResult, USimpleError};
<span class="kw">use </span>uucore::{format_usage, help_about, help_usage, show};
@@ -669,19 +669,19 @@
<span class="kw">let </span>iter = std::iter::once(date);
Box::new(iter)
}
DateSource::File(<span class="kw-2">ref </span>path) =&gt; <span class="kw">match </span>File::open(path) {
<span class="prelude-val">Ok</span>(file) =&gt; {
<span class="kw">let </span>lines = BufReader::new(file).lines();
<span class="kw">let </span>iter = lines.filter_map(Result::ok).map(parse_date);
Box::new(iter)
}
<span class="prelude-val">Err</span>(_err) =&gt; {
DateSource::File(<span class="kw-2">ref </span>path) =&gt; {
<span class="kw">if </span>path.is_dir() {
<span class="kw">return </span><span class="prelude-val">Err</span>(USimpleError::new(
<span class="number">2</span>,
<span class="macro">format!</span>(<span class="string">&quot;{}: No such file or directory&quot;</span>, path.display()),
<span class="macro">format!</span>(<span class="string">&quot;expected file, got directory {}&quot;</span>, path.quote()),
));
}
},
<span class="kw">let </span>file = File::open(path)
.map_err_context(|| path.as_os_str().to_string_lossy().to_string())<span class="question-mark">?</span>;
<span class="kw">let </span>lines = BufReader::new(file).lines();
<span class="kw">let </span>iter = lines.map_while(Result::ok).map(parse_date);
Box::new(iter)
}
DateSource::Now =&gt; {
<span class="kw">let </span>iter = std::iter::once(<span class="prelude-val">Ok</span>(now));
Box::new(iter)
+7 -1
View File
@@ -42,6 +42,9 @@
<a href="#42" id="42">42</a>
<a href="#43" id="43">43</a>
<a href="#44" id="44">44</a>
<a href="#45" id="45">45</a>
<a href="#46" id="46">46</a>
<a href="#47" id="47">47</a>
</pre><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * (c) Colin Warren &lt;me@zv.ms&gt;
@@ -60,8 +63,10 @@
<span class="kw">use </span>uucore::display::Quotable;
<span class="kw">use </span>uucore::error::{FromIo, UResult};
<span class="kw">use </span>uucore::{format_usage, help_about, help_usage};
<span class="kw">static </span>ABOUT: <span class="kw-2">&amp;</span>str = <span class="string">&quot;Unlink the file at FILE.&quot;</span>;
<span class="kw">const </span>ABOUT: <span class="kw-2">&amp;</span>str = <span class="macro">help_about!</span>(<span class="string">&quot;unlink.md&quot;</span>);
<span class="kw">const </span>USAGE: <span class="kw-2">&amp;</span>str = <span class="macro">help_usage!</span>(<span class="string">&quot;unlink.md&quot;</span>);
<span class="kw">static </span>OPT_PATH: <span class="kw-2">&amp;</span>str = <span class="string">&quot;FILE&quot;</span>;
<span class="attr">#[uucore::main]
@@ -77,6 +82,7 @@
Command::new(uucore::util_name())
.version(<span class="macro">crate_version!</span>())
.about(ABOUT)
.override_usage(format_usage(USAGE))
.infer_long_args(<span class="bool-val">true</span>)
.arg(
Arg::new(OPT_PATH)
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long