Skip to content

Commit 70df8ed

Browse files
committed
deploy: f0e8d44
1 parent f61bd3b commit 70df8ed

25 files changed

+147
-75
lines changed

dev/src/uu_cp/cp.rs.html

+34-18
Original file line numberDiff line numberDiff line change
@@ -1985,6 +1985,14 @@
19851985
<a href="#1985" id="1985">1985</a>
19861986
<a href="#1986" id="1986">1986</a>
19871987
<a href="#1987" id="1987">1987</a>
1988+
<a href="#1988" id="1988">1988</a>
1989+
<a href="#1989" id="1989">1989</a>
1990+
<a href="#1990" id="1990">1990</a>
1991+
<a href="#1991" id="1991">1991</a>
1992+
<a href="#1992" id="1992">1992</a>
1993+
<a href="#1993" id="1993">1993</a>
1994+
<a href="#1994" id="1994">1994</a>
1995+
<a href="#1995" id="1995">1995</a>
19881996
</pre></div><pre class="rust"><code><span class="attr">#![allow(clippy::missing_safety_doc)]
19891997
#![allow(clippy::extra_unused_lifetimes)]
19901998

@@ -2030,7 +2038,8 @@
20302038
};
20312039
<span class="kw">use </span>uucore::update_control::{<span class="self">self</span>, UpdateMode};
20322040
<span class="kw">use </span>uucore::{
2033-
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error, show_warning,
2041+
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error,
2042+
show_warning, util_name,
20342043
};
20352044

20362045
<span class="kw">use </span><span class="kw">crate</span>::copydir::copy_directory;
@@ -3089,24 +3098,22 @@
30893098
}
30903099

30913100
<span class="doccomment">/// When handling errors, we don&#39;t always want to show them to the user. This function handles that.
3092-
/// If the error is printed, returns true, false otherwise.
3093-
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&amp;</span>Error) -&gt; bool {
3101+
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&amp;</span>Error) {
30943102
<span class="kw">match </span>error {
30953103
<span class="comment">// When using --no-clobber, we don&#39;t want to show
30963104
// an error message
3097-
</span>Error::NotAllFilesCopied =&gt; (),
3105+
</span>Error::NotAllFilesCopied =&gt; {
3106+
<span class="comment">// Need to return an error code
3107+
</span>}
30983108
Error::Skipped =&gt; {
30993109
<span class="comment">// touch a b &amp;&amp; echo &quot;n&quot;|cp -i a b &amp;&amp; echo $?
31003110
// should return an error from GNU 9.2
3101-
</span><span class="kw">return </span><span class="bool-val">true</span>;
3102-
}
3111+
</span>}
31033112
<span class="kw">_ </span>=&gt; {
31043113
<span class="macro">show_error!</span>(<span class="string">&quot;{}&quot;</span>, error);
3105-
<span class="kw">return </span><span class="bool-val">true</span>;
31063114
}
31073115
}
3108-
<span class="bool-val">false
3109-
</span>}
3116+
}
31103117

31113118
<span class="doccomment">/// Copy all `sources` to `target`. Returns an
31123119
/// `Err(Error::NotAllFilesCopied)` if at least one non-fatal error was
@@ -3162,9 +3169,8 @@
31623169
options,
31633170
<span class="kw-2">&amp;mut </span>symlinked_files,
31643171
) {
3165-
<span class="kw">if </span>show_error_if_needed(<span class="kw-2">&amp;</span>error) {
3166-
non_fatal_errors = <span class="bool-val">true</span>;
3167-
}
3172+
show_error_if_needed(<span class="kw-2">&amp;</span>error);
3173+
non_fatal_errors = <span class="bool-val">true</span>;
31683174
}
31693175
}
31703176
seen_sources.insert(source);
@@ -3241,13 +3247,23 @@
32413247
}
32423248

32433249
<span class="kw">impl </span>OverwriteMode {
3244-
<span class="kw">fn </span>verify(<span class="kw-2">&amp;</span><span class="self">self</span>, path: <span class="kw-2">&amp;</span>Path) -&gt; CopyResult&lt;()&gt; {
3250+
<span class="kw">fn </span>verify(<span class="kw-2">&amp;</span><span class="self">self</span>, path: <span class="kw-2">&amp;</span>Path, verbose: bool) -&gt; CopyResult&lt;()&gt; {
32453251
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
3246-
<span class="self">Self</span>::NoClobber =&gt; <span class="prelude-val">Err</span>(Error::NotAllFilesCopied),
3252+
<span class="self">Self</span>::NoClobber =&gt; {
3253+
<span class="kw">if </span>verbose {
3254+
<span class="macro">println!</span>(<span class="string">&quot;skipped {}&quot;</span>, path.quote());
3255+
} <span class="kw">else </span>{
3256+
<span class="macro">eprintln!</span>(<span class="string">&quot;{}: not replacing {}&quot;</span>, util_name(), path.quote());
3257+
}
3258+
<span class="prelude-val">Err</span>(Error::NotAllFilesCopied)
3259+
}
32473260
<span class="self">Self</span>::Interactive(<span class="kw">_</span>) =&gt; {
32483261
<span class="kw">if </span><span class="macro">prompt_yes!</span>(<span class="string">&quot;overwrite {}?&quot;</span>, path.quote()) {
32493262
<span class="prelude-val">Ok</span>(())
32503263
} <span class="kw">else </span>{
3264+
<span class="kw">if </span>verbose {
3265+
<span class="macro">println!</span>(<span class="string">&quot;skipped {}&quot;</span>, path.quote());
3266+
}
32513267
<span class="prelude-val">Err</span>(Error::Skipped)
32523268
}
32533269
}
@@ -3455,7 +3471,7 @@
34553471
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">&quot;{} and {} are the same file&quot;</span>, source.quote(), dest.quote()).into());
34563472
}
34573473

3458-
options.overwrite.verify(dest)<span class="question-mark">?</span>;
3474+
options.overwrite.verify(dest, options.verbose)<span class="question-mark">?</span>;
34593475

34603476
<span class="kw">let </span>backup_path = backup_control::get_backup_path(options.backup, dest, <span class="kw-2">&amp;</span>options.backup_suffix);
34613477
<span class="kw">if let </span><span class="prelude-val">Some</span>(backup_path) = backup_path {
@@ -3813,7 +3829,7 @@
38133829
</span>File::create(dest).context(dest.display().to_string())<span class="question-mark">?</span>;
38143830
} <span class="kw">else if </span>source_is_fifo &amp;&amp; options.recursive &amp;&amp; !options.copy_contents {
38153831
<span class="attr">#[cfg(unix)]
3816-
</span>copy_fifo(dest, options.overwrite)<span class="question-mark">?</span>;
3832+
</span>copy_fifo(dest, options.overwrite, options.verbose)<span class="question-mark">?</span>;
38173833
} <span class="kw">else if </span>source_is_symlink {
38183834
copy_link(source, dest, symlinked_files)<span class="question-mark">?</span>;
38193835
} <span class="kw">else </span>{
@@ -3838,9 +3854,9 @@
38383854
<span class="comment">// &quot;Copies&quot; a FIFO by creating a new one. This workaround is because Rust&#39;s
38393855
// built-in fs::copy does not handle FIFOs (see rust-lang/rust/issues/79390).
38403856
</span><span class="attr">#[cfg(unix)]
3841-
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&amp;</span>Path, overwrite: OverwriteMode) -&gt; CopyResult&lt;()&gt; {
3857+
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&amp;</span>Path, overwrite: OverwriteMode, verbose: bool) -&gt; CopyResult&lt;()&gt; {
38423858
<span class="kw">if </span>dest.exists() {
3843-
overwrite.verify(dest)<span class="question-mark">?</span>;
3859+
overwrite.verify(dest, verbose)<span class="question-mark">?</span>;
38443860
fs::remove_file(dest)<span class="question-mark">?</span>;
38453861
}
38463862

dev/src/uu_more/more.rs.html

+79-23
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,34 @@
625625
<a href="#625" id="625">625</a>
626626
<a href="#626" id="626">626</a>
627627
<a href="#627" id="627">627</a>
628+
<a href="#628" id="628">628</a>
629+
<a href="#629" id="629">629</a>
630+
<a href="#630" id="630">630</a>
631+
<a href="#631" id="631">631</a>
632+
<a href="#632" id="632">632</a>
633+
<a href="#633" id="633">633</a>
634+
<a href="#634" id="634">634</a>
635+
<a href="#635" id="635">635</a>
636+
<a href="#636" id="636">636</a>
637+
<a href="#637" id="637">637</a>
638+
<a href="#638" id="638">638</a>
639+
<a href="#639" id="639">639</a>
640+
<a href="#640" id="640">640</a>
641+
<a href="#641" id="641">641</a>
642+
<a href="#642" id="642">642</a>
643+
<a href="#643" id="643">643</a>
644+
<a href="#644" id="644">644</a>
645+
<a href="#645" id="645">645</a>
646+
<a href="#646" id="646">646</a>
647+
<a href="#647" id="647">647</a>
648+
<a href="#648" id="648">648</a>
649+
<a href="#649" id="649">649</a>
650+
<a href="#650" id="650">650</a>
651+
<a href="#651" id="651">651</a>
652+
<a href="#652" id="652">652</a>
653+
<a href="#653" id="653">653</a>
654+
<a href="#654" id="654">654</a>
655+
<a href="#655" id="655">655</a>
628656
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
629657
// *
630658
// * (c) Martin Kysel &lt;code@martinkysel.com&gt;
@@ -641,10 +669,10 @@
641669
time::Duration,
642670
};
643671

644-
<span class="kw">use </span>clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
672+
<span class="kw">use </span>clap::{crate_version, value_parser, Arg, ArgAction, ArgMatches, Command};
645673
<span class="kw">use </span>crossterm::event::KeyEventKind;
646674
<span class="kw">use </span>crossterm::{
647-
cursor::MoveTo,
675+
cursor::{MoveTo, MoveUp},
648676
event::{<span class="self">self</span>, Event, KeyCode, KeyEvent, KeyModifiers},
649677
execute, queue,
650678
style::Attribute,
@@ -680,16 +708,28 @@
680708
<span class="kw">const </span>MULTI_FILE_TOP_PROMPT: <span class="kw-2">&amp;</span>str = <span class="string">&quot;::::::::::::::\n{}\n::::::::::::::\n&quot;</span>;
681709

682710
<span class="kw">struct </span>Options {
683-
silent: bool,
684711
clean_print: bool,
712+
lines: <span class="prelude-ty">Option</span>&lt;u16&gt;,
685713
print_over: bool,
714+
silent: bool,
686715
squeeze: bool,
687716
}
688717

689718
<span class="kw">impl </span>Options {
690719
<span class="kw">fn </span>from(matches: <span class="kw-2">&amp;</span>ArgMatches) -&gt; <span class="self">Self </span>{
720+
<span class="kw">let </span>lines = <span class="kw">match </span>(
721+
matches.get_one::&lt;u16&gt;(options::LINES).copied(),
722+
matches.get_one::&lt;u16&gt;(options::NUMBER).copied(),
723+
) {
724+
<span class="comment">// We add 1 to the number of lines to display because the last line
725+
// is used for the banner
726+
</span>(<span class="prelude-val">Some</span>(number), <span class="kw">_</span>) <span class="kw">if </span>number &gt; <span class="number">0 </span>=&gt; <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
727+
(<span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(number)) <span class="kw">if </span>number &gt; <span class="number">0 </span>=&gt; <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
728+
(<span class="kw">_</span>, <span class="kw">_</span>) =&gt; <span class="prelude-val">None</span>,
729+
};
691730
<span class="self">Self </span>{
692731
clean_print: matches.get_flag(options::CLEAN_PRINT),
732+
lines,
693733
print_over: matches.get_flag(options::PRINT_OVER),
694734
silent: matches.get_flag(options::SILENT),
695735
squeeze: matches.get_flag(options::SQUEEZE),
@@ -794,6 +834,23 @@
794834
.help(<span class="string">&quot;Squeeze multiple blank lines into one&quot;</span>)
795835
.action(ArgAction::SetTrue),
796836
)
837+
.arg(
838+
Arg::new(options::LINES)
839+
.short(<span class="string">&#39;n&#39;</span>)
840+
.long(options::LINES)
841+
.value_name(<span class="string">&quot;number&quot;</span>)
842+
.num_args(<span class="number">1</span>)
843+
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
844+
.help(<span class="string">&quot;The number of lines per screen full&quot;</span>),
845+
)
846+
.arg(
847+
Arg::new(options::NUMBER)
848+
.long(options::NUMBER)
849+
.required(<span class="bool-val">false</span>)
850+
.num_args(<span class="number">1</span>)
851+
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
852+
.help(<span class="string">&quot;Same as --lines&quot;</span>),
853+
)
797854
<span class="comment">// The commented arguments below are unimplemented:
798855
/*
799856
.arg(
@@ -814,22 +871,6 @@
814871
.long(options::PLAIN)
815872
.help(&quot;Suppress underlining and bold&quot;),
816873
)
817-
.arg(
818-
Arg::new(options::LINES)
819-
.short(&#39;n&#39;)
820-
.long(options::LINES)
821-
.value_name(&quot;number&quot;)
822-
.takes_value(true)
823-
.help(&quot;The number of lines per screen full&quot;),
824-
)
825-
.arg(
826-
Arg::new(options::NUMBER)
827-
.allow_hyphen_values(true)
828-
.long(options::NUMBER)
829-
.required(false)
830-
.takes_value(true)
831-
.help(&quot;Same as --lines&quot;),
832-
)
833874
.arg(
834875
Arg::new(options::FROM_LINE)
835876
.short(&#39;F&#39;)
@@ -890,7 +931,11 @@
890931
next_file: <span class="prelude-ty">Option</span>&lt;<span class="kw-2">&amp;</span>str&gt;,
891932
options: <span class="kw-2">&amp;</span>Options,
892933
) -&gt; UResult&lt;()&gt; {
893-
<span class="kw">let </span>(cols, rows) = terminal::size().unwrap();
934+
<span class="kw">let </span>(cols, <span class="kw-2">mut </span>rows) = terminal::size().unwrap();
935+
<span class="kw">if let </span><span class="prelude-val">Some</span>(number) = options.lines {
936+
rows = number;
937+
}
938+
894939
<span class="kw">let </span>lines = break_buff(buff, usize::from(cols));
895940

896941
<span class="kw">let </span><span class="kw-2">mut </span>pager = Pager::new(rows, lines, next_file, options);
@@ -954,6 +999,7 @@
954999
..
9551000
}) =&gt; {
9561001
pager.page_up();
1002+
paging_add_back_message(options, stdout)<span class="question-mark">?</span>;
9571003
}
9581004
Event::Key(KeyEvent {
9591005
code: KeyCode::Char(<span class="string">&#39;j&#39;</span>),
@@ -974,7 +1020,7 @@
9741020
pager.prev_line();
9751021
}
9761022
Event::Resize(col, row) =&gt; {
977-
pager.page_resize(col, row);
1023+
pager.page_resize(col, row, options.lines);
9781024
}
9791025
Event::Key(KeyEvent {
9801026
code: KeyCode::Char(k),
@@ -1074,8 +1120,10 @@
10741120
}
10751121

10761122
<span class="comment">// TODO: Deal with column size changes.
1077-
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&amp;mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16) {
1078-
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
1123+
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&amp;mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16, option_line: <span class="prelude-ty">Option</span>&lt;u16&gt;) {
1124+
<span class="kw">if </span>option_line.is_none() {
1125+
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
1126+
};
10791127
}
10801128

10811129
<span class="kw">fn </span>draw(<span class="kw-2">&amp;mut </span><span class="self">self</span>, stdout: <span class="kw-2">&amp;mut </span>std::io::Stdout, wrong_key: <span class="prelude-ty">Option</span>&lt;char&gt;) {
@@ -1163,6 +1211,14 @@
11631211
}
11641212
}
11651213

1214+
<span class="kw">fn </span>paging_add_back_message(options: <span class="kw-2">&amp;</span>Options, stdout: <span class="kw-2">&amp;mut </span>std::io::Stdout) -&gt; UResult&lt;()&gt; {
1215+
<span class="kw">if </span>options.lines.is_some() {
1216+
<span class="macro">execute!</span>(stdout, MoveUp(<span class="number">1</span>))<span class="question-mark">?</span>;
1217+
stdout.write_all(<span class="string">&quot;\n\r...back 1 page\n&quot;</span>.as_bytes())<span class="question-mark">?</span>;
1218+
}
1219+
<span class="prelude-val">Ok</span>(())
1220+
}
1221+
11661222
<span class="comment">// Break the lines on the cols of the terminal
11671223
</span><span class="kw">fn </span>break_buff(buff: <span class="kw-2">&amp;</span>str, cols: usize) -&gt; Vec&lt;String&gt; {
11681224
<span class="kw">let </span><span class="kw-2">mut </span>lines = Vec::with_capacity(buff.lines().count());

0 commit comments

Comments
 (0)