You've already forked uutils.github.io
mirror of
https://github.com/uutils/uutils.github.io.git
synced 2026-06-10 16:12:28 -07:00
deploy: f0e8d44e6e
This commit is contained in:
+34
-18
@@ -1985,6 +1985,14 @@
|
||||
<a href="#1985" id="1985">1985</a>
|
||||
<a href="#1986" id="1986">1986</a>
|
||||
<a href="#1987" id="1987">1987</a>
|
||||
<a href="#1988" id="1988">1988</a>
|
||||
<a href="#1989" id="1989">1989</a>
|
||||
<a href="#1990" id="1990">1990</a>
|
||||
<a href="#1991" id="1991">1991</a>
|
||||
<a href="#1992" id="1992">1992</a>
|
||||
<a href="#1993" id="1993">1993</a>
|
||||
<a href="#1994" id="1994">1994</a>
|
||||
<a href="#1995" id="1995">1995</a>
|
||||
</pre></div><pre class="rust"><code><span class="attr">#![allow(clippy::missing_safety_doc)]
|
||||
#![allow(clippy::extra_unused_lifetimes)]
|
||||
|
||||
@@ -2030,7 +2038,8 @@
|
||||
};
|
||||
<span class="kw">use </span>uucore::update_control::{<span class="self">self</span>, UpdateMode};
|
||||
<span class="kw">use </span>uucore::{
|
||||
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error, show_warning,
|
||||
crash, format_usage, help_about, help_section, help_usage, prompt_yes, show_error,
|
||||
show_warning, util_name,
|
||||
};
|
||||
|
||||
<span class="kw">use </span><span class="kw">crate</span>::copydir::copy_directory;
|
||||
@@ -3089,24 +3098,22 @@
|
||||
}
|
||||
|
||||
<span class="doccomment">/// When handling errors, we don't always want to show them to the user. This function handles that.
|
||||
/// If the error is printed, returns true, false otherwise.
|
||||
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&</span>Error) -> bool {
|
||||
</span><span class="kw">fn </span>show_error_if_needed(error: <span class="kw-2">&</span>Error) {
|
||||
<span class="kw">match </span>error {
|
||||
<span class="comment">// When using --no-clobber, we don't want to show
|
||||
// an error message
|
||||
</span>Error::NotAllFilesCopied => (),
|
||||
</span>Error::NotAllFilesCopied => {
|
||||
<span class="comment">// Need to return an error code
|
||||
</span>}
|
||||
Error::Skipped => {
|
||||
<span class="comment">// touch a b && echo "n"|cp -i a b && echo $?
|
||||
// should return an error from GNU 9.2
|
||||
</span><span class="kw">return </span><span class="bool-val">true</span>;
|
||||
}
|
||||
</span>}
|
||||
<span class="kw">_ </span>=> {
|
||||
<span class="macro">show_error!</span>(<span class="string">"{}"</span>, error);
|
||||
<span class="kw">return </span><span class="bool-val">true</span>;
|
||||
}
|
||||
}
|
||||
<span class="bool-val">false
|
||||
</span>}
|
||||
}
|
||||
|
||||
<span class="doccomment">/// Copy all `sources` to `target`. Returns an
|
||||
/// `Err(Error::NotAllFilesCopied)` if at least one non-fatal error was
|
||||
@@ -3162,9 +3169,8 @@
|
||||
options,
|
||||
<span class="kw-2">&mut </span>symlinked_files,
|
||||
) {
|
||||
<span class="kw">if </span>show_error_if_needed(<span class="kw-2">&</span>error) {
|
||||
non_fatal_errors = <span class="bool-val">true</span>;
|
||||
}
|
||||
show_error_if_needed(<span class="kw-2">&</span>error);
|
||||
non_fatal_errors = <span class="bool-val">true</span>;
|
||||
}
|
||||
}
|
||||
seen_sources.insert(source);
|
||||
@@ -3241,13 +3247,23 @@
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>OverwriteMode {
|
||||
<span class="kw">fn </span>verify(<span class="kw-2">&</span><span class="self">self</span>, path: <span class="kw-2">&</span>Path) -> CopyResult<()> {
|
||||
<span class="kw">fn </span>verify(<span class="kw-2">&</span><span class="self">self</span>, path: <span class="kw-2">&</span>Path, verbose: bool) -> CopyResult<()> {
|
||||
<span class="kw">match </span><span class="kw-2">*</span><span class="self">self </span>{
|
||||
<span class="self">Self</span>::NoClobber => <span class="prelude-val">Err</span>(Error::NotAllFilesCopied),
|
||||
<span class="self">Self</span>::NoClobber => {
|
||||
<span class="kw">if </span>verbose {
|
||||
<span class="macro">println!</span>(<span class="string">"skipped {}"</span>, path.quote());
|
||||
} <span class="kw">else </span>{
|
||||
<span class="macro">eprintln!</span>(<span class="string">"{}: not replacing {}"</span>, util_name(), path.quote());
|
||||
}
|
||||
<span class="prelude-val">Err</span>(Error::NotAllFilesCopied)
|
||||
}
|
||||
<span class="self">Self</span>::Interactive(<span class="kw">_</span>) => {
|
||||
<span class="kw">if </span><span class="macro">prompt_yes!</span>(<span class="string">"overwrite {}?"</span>, path.quote()) {
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
} <span class="kw">else </span>{
|
||||
<span class="kw">if </span>verbose {
|
||||
<span class="macro">println!</span>(<span class="string">"skipped {}"</span>, path.quote());
|
||||
}
|
||||
<span class="prelude-val">Err</span>(Error::Skipped)
|
||||
}
|
||||
}
|
||||
@@ -3455,7 +3471,7 @@
|
||||
<span class="kw">return </span><span class="prelude-val">Err</span>(<span class="macro">format!</span>(<span class="string">"{} and {} are the same file"</span>, source.quote(), dest.quote()).into());
|
||||
}
|
||||
|
||||
options.overwrite.verify(dest)<span class="question-mark">?</span>;
|
||||
options.overwrite.verify(dest, options.verbose)<span class="question-mark">?</span>;
|
||||
|
||||
<span class="kw">let </span>backup_path = backup_control::get_backup_path(options.backup, dest, <span class="kw-2">&</span>options.backup_suffix);
|
||||
<span class="kw">if let </span><span class="prelude-val">Some</span>(backup_path) = backup_path {
|
||||
@@ -3813,7 +3829,7 @@
|
||||
</span>File::create(dest).context(dest.display().to_string())<span class="question-mark">?</span>;
|
||||
} <span class="kw">else if </span>source_is_fifo && options.recursive && !options.copy_contents {
|
||||
<span class="attr">#[cfg(unix)]
|
||||
</span>copy_fifo(dest, options.overwrite)<span class="question-mark">?</span>;
|
||||
</span>copy_fifo(dest, options.overwrite, options.verbose)<span class="question-mark">?</span>;
|
||||
} <span class="kw">else if </span>source_is_symlink {
|
||||
copy_link(source, dest, symlinked_files)<span class="question-mark">?</span>;
|
||||
} <span class="kw">else </span>{
|
||||
@@ -3838,9 +3854,9 @@
|
||||
<span class="comment">// "Copies" a FIFO by creating a new one. This workaround is because Rust's
|
||||
// built-in fs::copy does not handle FIFOs (see rust-lang/rust/issues/79390).
|
||||
</span><span class="attr">#[cfg(unix)]
|
||||
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&</span>Path, overwrite: OverwriteMode) -> CopyResult<()> {
|
||||
</span><span class="kw">fn </span>copy_fifo(dest: <span class="kw-2">&</span>Path, overwrite: OverwriteMode, verbose: bool) -> CopyResult<()> {
|
||||
<span class="kw">if </span>dest.exists() {
|
||||
overwrite.verify(dest)<span class="question-mark">?</span>;
|
||||
overwrite.verify(dest, verbose)<span class="question-mark">?</span>;
|
||||
fs::remove_file(dest)<span class="question-mark">?</span>;
|
||||
}
|
||||
|
||||
|
||||
@@ -625,6 +625,34 @@
|
||||
<a href="#625" id="625">625</a>
|
||||
<a href="#626" id="626">626</a>
|
||||
<a href="#627" id="627">627</a>
|
||||
<a href="#628" id="628">628</a>
|
||||
<a href="#629" id="629">629</a>
|
||||
<a href="#630" id="630">630</a>
|
||||
<a href="#631" id="631">631</a>
|
||||
<a href="#632" id="632">632</a>
|
||||
<a href="#633" id="633">633</a>
|
||||
<a href="#634" id="634">634</a>
|
||||
<a href="#635" id="635">635</a>
|
||||
<a href="#636" id="636">636</a>
|
||||
<a href="#637" id="637">637</a>
|
||||
<a href="#638" id="638">638</a>
|
||||
<a href="#639" id="639">639</a>
|
||||
<a href="#640" id="640">640</a>
|
||||
<a href="#641" id="641">641</a>
|
||||
<a href="#642" id="642">642</a>
|
||||
<a href="#643" id="643">643</a>
|
||||
<a href="#644" id="644">644</a>
|
||||
<a href="#645" id="645">645</a>
|
||||
<a href="#646" id="646">646</a>
|
||||
<a href="#647" id="647">647</a>
|
||||
<a href="#648" id="648">648</a>
|
||||
<a href="#649" id="649">649</a>
|
||||
<a href="#650" id="650">650</a>
|
||||
<a href="#651" id="651">651</a>
|
||||
<a href="#652" id="652">652</a>
|
||||
<a href="#653" id="653">653</a>
|
||||
<a href="#654" id="654">654</a>
|
||||
<a href="#655" id="655">655</a>
|
||||
</pre></div><pre class="rust"><code><span class="comment">// * This file is part of the uutils coreutils package.
|
||||
// *
|
||||
// * (c) Martin Kysel <code@martinkysel.com>
|
||||
@@ -641,10 +669,10 @@
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
<span class="kw">use </span>clap::{crate_version, Arg, ArgAction, ArgMatches, Command};
|
||||
<span class="kw">use </span>clap::{crate_version, value_parser, Arg, ArgAction, ArgMatches, Command};
|
||||
<span class="kw">use </span>crossterm::event::KeyEventKind;
|
||||
<span class="kw">use </span>crossterm::{
|
||||
cursor::MoveTo,
|
||||
cursor::{MoveTo, MoveUp},
|
||||
event::{<span class="self">self</span>, Event, KeyCode, KeyEvent, KeyModifiers},
|
||||
execute, queue,
|
||||
style::Attribute,
|
||||
@@ -680,16 +708,28 @@
|
||||
<span class="kw">const </span>MULTI_FILE_TOP_PROMPT: <span class="kw-2">&</span>str = <span class="string">"::::::::::::::\n{}\n::::::::::::::\n"</span>;
|
||||
|
||||
<span class="kw">struct </span>Options {
|
||||
silent: bool,
|
||||
clean_print: bool,
|
||||
lines: <span class="prelude-ty">Option</span><u16>,
|
||||
print_over: bool,
|
||||
silent: bool,
|
||||
squeeze: bool,
|
||||
}
|
||||
|
||||
<span class="kw">impl </span>Options {
|
||||
<span class="kw">fn </span>from(matches: <span class="kw-2">&</span>ArgMatches) -> <span class="self">Self </span>{
|
||||
<span class="kw">let </span>lines = <span class="kw">match </span>(
|
||||
matches.get_one::<u16>(options::LINES).copied(),
|
||||
matches.get_one::<u16>(options::NUMBER).copied(),
|
||||
) {
|
||||
<span class="comment">// We add 1 to the number of lines to display because the last line
|
||||
// is used for the banner
|
||||
</span>(<span class="prelude-val">Some</span>(number), <span class="kw">_</span>) <span class="kw">if </span>number > <span class="number">0 </span>=> <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
|
||||
(<span class="prelude-val">None</span>, <span class="prelude-val">Some</span>(number)) <span class="kw">if </span>number > <span class="number">0 </span>=> <span class="prelude-val">Some</span>(number + <span class="number">1</span>),
|
||||
(<span class="kw">_</span>, <span class="kw">_</span>) => <span class="prelude-val">None</span>,
|
||||
};
|
||||
<span class="self">Self </span>{
|
||||
clean_print: matches.get_flag(options::CLEAN_PRINT),
|
||||
lines,
|
||||
print_over: matches.get_flag(options::PRINT_OVER),
|
||||
silent: matches.get_flag(options::SILENT),
|
||||
squeeze: matches.get_flag(options::SQUEEZE),
|
||||
@@ -794,6 +834,23 @@
|
||||
.help(<span class="string">"Squeeze multiple blank lines into one"</span>)
|
||||
.action(ArgAction::SetTrue),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::LINES)
|
||||
.short(<span class="string">'n'</span>)
|
||||
.long(options::LINES)
|
||||
.value_name(<span class="string">"number"</span>)
|
||||
.num_args(<span class="number">1</span>)
|
||||
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
|
||||
.help(<span class="string">"The number of lines per screen full"</span>),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::NUMBER)
|
||||
.long(options::NUMBER)
|
||||
.required(<span class="bool-val">false</span>)
|
||||
.num_args(<span class="number">1</span>)
|
||||
.value_parser(<span class="macro">value_parser!</span>(u16).range(<span class="number">0</span>..))
|
||||
.help(<span class="string">"Same as --lines"</span>),
|
||||
)
|
||||
<span class="comment">// The commented arguments below are unimplemented:
|
||||
/*
|
||||
.arg(
|
||||
@@ -814,22 +871,6 @@
|
||||
.long(options::PLAIN)
|
||||
.help("Suppress underlining and bold"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::LINES)
|
||||
.short('n')
|
||||
.long(options::LINES)
|
||||
.value_name("number")
|
||||
.takes_value(true)
|
||||
.help("The number of lines per screen full"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::NUMBER)
|
||||
.allow_hyphen_values(true)
|
||||
.long(options::NUMBER)
|
||||
.required(false)
|
||||
.takes_value(true)
|
||||
.help("Same as --lines"),
|
||||
)
|
||||
.arg(
|
||||
Arg::new(options::FROM_LINE)
|
||||
.short('F')
|
||||
@@ -890,7 +931,11 @@
|
||||
next_file: <span class="prelude-ty">Option</span><<span class="kw-2">&</span>str>,
|
||||
options: <span class="kw-2">&</span>Options,
|
||||
) -> UResult<()> {
|
||||
<span class="kw">let </span>(cols, rows) = terminal::size().unwrap();
|
||||
<span class="kw">let </span>(cols, <span class="kw-2">mut </span>rows) = terminal::size().unwrap();
|
||||
<span class="kw">if let </span><span class="prelude-val">Some</span>(number) = options.lines {
|
||||
rows = number;
|
||||
}
|
||||
|
||||
<span class="kw">let </span>lines = break_buff(buff, usize::from(cols));
|
||||
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>pager = Pager::new(rows, lines, next_file, options);
|
||||
@@ -954,6 +999,7 @@
|
||||
..
|
||||
}) => {
|
||||
pager.page_up();
|
||||
paging_add_back_message(options, stdout)<span class="question-mark">?</span>;
|
||||
}
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char(<span class="string">'j'</span>),
|
||||
@@ -974,7 +1020,7 @@
|
||||
pager.prev_line();
|
||||
}
|
||||
Event::Resize(col, row) => {
|
||||
pager.page_resize(col, row);
|
||||
pager.page_resize(col, row, options.lines);
|
||||
}
|
||||
Event::Key(KeyEvent {
|
||||
code: KeyCode::Char(k),
|
||||
@@ -1074,8 +1120,10 @@
|
||||
}
|
||||
|
||||
<span class="comment">// TODO: Deal with column size changes.
|
||||
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16) {
|
||||
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
|
||||
</span><span class="kw">fn </span>page_resize(<span class="kw-2">&mut </span><span class="self">self</span>, <span class="kw">_</span>: u16, row: u16, option_line: <span class="prelude-ty">Option</span><u16>) {
|
||||
<span class="kw">if </span>option_line.is_none() {
|
||||
<span class="self">self</span>.content_rows = row.saturating_sub(<span class="number">1</span>);
|
||||
};
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>draw(<span class="kw-2">&mut </span><span class="self">self</span>, stdout: <span class="kw-2">&mut </span>std::io::Stdout, wrong_key: <span class="prelude-ty">Option</span><char>) {
|
||||
@@ -1163,6 +1211,14 @@
|
||||
}
|
||||
}
|
||||
|
||||
<span class="kw">fn </span>paging_add_back_message(options: <span class="kw-2">&</span>Options, stdout: <span class="kw-2">&mut </span>std::io::Stdout) -> UResult<()> {
|
||||
<span class="kw">if </span>options.lines.is_some() {
|
||||
<span class="macro">execute!</span>(stdout, MoveUp(<span class="number">1</span>))<span class="question-mark">?</span>;
|
||||
stdout.write_all(<span class="string">"\n\r...back 1 page\n"</span>.as_bytes())<span class="question-mark">?</span>;
|
||||
}
|
||||
<span class="prelude-val">Ok</span>(())
|
||||
}
|
||||
|
||||
<span class="comment">// Break the lines on the cols of the terminal
|
||||
</span><span class="kw">fn </span>break_buff(buff: <span class="kw-2">&</span>str, cols: usize) -> Vec<String> {
|
||||
<span class="kw">let </span><span class="kw-2">mut </span>lines = Vec::with_capacity(buff.lines().count());
|
||||
|
||||
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
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user