This commit is contained in:
sylvestre
2023-07-12 02:59:54 +00:00
parent a6eaf0e660
commit b85b8ba4ea
20 changed files with 57 additions and 51 deletions
+4 -30
View File
@@ -132,19 +132,6 @@
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
</pre></div><pre class="rust"><code><span class="comment">// spell-checker:ignore (ToDO) conv
</span><span class="kw">use </span><span class="kw">crate</span>::options;
@@ -183,23 +170,10 @@
settings.number_separator = val.to_owned();
}
}
<span class="kw">match </span>opts.get_one::&lt;String&gt;(options::NUMBER_FORMAT) {
<span class="prelude-val">None </span>=&gt; {}
<span class="prelude-val">Some</span>(val) =&gt; <span class="kw">match </span>val.as_str() {
<span class="string">&quot;ln&quot; </span>=&gt; {
settings.number_format = <span class="kw">crate</span>::NumberFormat::Left;
}
<span class="string">&quot;rn&quot; </span>=&gt; {
settings.number_format = <span class="kw">crate</span>::NumberFormat::Right;
}
<span class="string">&quot;rz&quot; </span>=&gt; {
settings.number_format = <span class="kw">crate</span>::NumberFormat::RightZero;
}
<span class="kw">_ </span>=&gt; {
errs.push(String::from(<span class="string">&quot;Illegal value for -n&quot;</span>));
}
},
}
settings.number_format = opts
.get_one::&lt;String&gt;(options::NUMBER_FORMAT)
.map(Into::into)
.unwrap_or_default();
<span class="kw">match </span>opts.get_one::&lt;String&gt;(options::BODY_NUMBERING) {
<span class="prelude-val">None </span>=&gt; {}
<span class="prelude-val">Some</span>(val) =&gt; {
+35 -3
View File
@@ -405,6 +405,22 @@
<a href="#405" id="405">405</a>
<a href="#406" id="406">406</a>
<a href="#407" id="407">407</a>
<a href="#408" id="408">408</a>
<a href="#409" id="409">409</a>
<a href="#410" id="410">410</a>
<a href="#411" id="411">411</a>
<a href="#412" id="412">412</a>
<a href="#413" id="413">413</a>
<a href="#414" id="414">414</a>
<a href="#415" id="415">415</a>
<a href="#416" id="416">416</a>
<a href="#417" id="417">417</a>
<a href="#418" id="418">418</a>
<a href="#419" id="419">419</a>
<a href="#420" id="420">420</a>
<a href="#421" id="421">421</a>
<a href="#422" id="422">422</a>
<a href="#423" id="423">423</a>
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
// *
// * (c) Tobias Bohumir Schottdorf &lt;tobias.schottdorf@gmail.com&gt;
@@ -419,11 +435,12 @@
<span class="kw">use </span>std::iter::repeat;
<span class="kw">use </span>std::path::Path;
<span class="kw">use </span>uucore::error::{FromIo, UResult, USimpleError};
<span class="kw">use </span>uucore::{format_usage, help_about, help_usage};
<span class="kw">use </span>uucore::{format_usage, help_about, help_section, help_usage};
<span class="kw">mod </span>helper;
<span class="kw">const </span>ABOUT: <span class="kw-2">&amp;</span>str = <span class="macro">help_about!</span>(<span class="string">&quot;nl.md&quot;</span>);
<span class="kw">const </span>AFTER_HELP: <span class="kw-2">&amp;</span>str = <span class="macro">help_section!</span>(<span class="string">&quot;after help&quot;</span>, <span class="string">&quot;nl.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;nl.md&quot;</span>);
<span class="comment">// Settings store options used by nl to produce its output.
@@ -482,12 +499,25 @@
<span class="comment">// NumberFormat specifies how line numbers are output within their allocated
// space. They are justified to the left or right, in the latter case with
// the option of having all unused space to its left turned into leading zeroes.
</span><span class="attr">#[derive(Default)]
</span><span class="kw">enum </span>NumberFormat {
Left,
Right,
<span class="attr">#[default]
</span>Right,
RightZero,
}
<span class="kw">impl</span>&lt;T: AsRef&lt;str&gt;&gt; From&lt;T&gt; <span class="kw">for </span>NumberFormat {
<span class="kw">fn </span>from(s: T) -&gt; <span class="self">Self </span>{
<span class="kw">match </span>s.as_ref() {
<span class="string">&quot;ln&quot; </span>=&gt; <span class="self">Self</span>::Left,
<span class="string">&quot;rn&quot; </span>=&gt; <span class="self">Self</span>::Right,
<span class="string">&quot;rz&quot; </span>=&gt; <span class="self">Self</span>::RightZero,
<span class="kw">_ </span>=&gt; <span class="macro">unreachable!</span>(<span class="string">&quot;Should have been caught by clap&quot;</span>),
}
}
}
<span class="kw">pub mod </span>options {
<span class="kw">pub const </span>HELP: <span class="kw-2">&amp;</span>str = <span class="string">&quot;help&quot;</span>;
<span class="kw">pub const </span>FILE: <span class="kw-2">&amp;</span>str = <span class="string">&quot;file&quot;</span>;
@@ -553,6 +583,7 @@
.about(ABOUT)
.version(<span class="macro">crate_version!</span>())
.override_usage(format_usage(USAGE))
.after_help(AFTER_HELP)
.infer_long_args(<span class="bool-val">true</span>)
.disable_help_flag(<span class="bool-val">true</span>)
.arg(
@@ -614,7 +645,8 @@
.short(<span class="string">&#39;n&#39;</span>)
.long(options::NUMBER_FORMAT)
.help(<span class="string">&quot;insert line numbers according to FORMAT&quot;</span>)
.value_name(<span class="string">&quot;FORMAT&quot;</span>),
.value_name(<span class="string">&quot;FORMAT&quot;</span>)
.value_parser([<span class="string">&quot;ln&quot;</span>, <span class="string">&quot;rn&quot;</span>, <span class="string">&quot;rz&quot;</span>]),
)
.arg(
Arg::new(options::NO_RENUMBER)
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
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
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
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
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