Skip to content

Commit 5c78f72

Browse files
committed
Make all cli functions and structs crate-private
Signed-off-by: hi-rustin <[email protected]>
1 parent 457d643 commit 5c78f72

13 files changed

+103
-99
lines changed

src/cli/common.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ use crate::utils::notify::NotificationLevel;
2121
use crate::utils::utils;
2222
use crate::{Cfg, Notification, Toolchain, UpdateStatus};
2323

24-
pub const WARN_COMPLETE_PROFILE: &str = "downloading with complete profile isn't recommended unless you are a developer of the rust language";
24+
pub(crate) const WARN_COMPLETE_PROFILE: &str = "downloading with complete profile isn't recommended unless you are a developer of the rust language";
2525

26-
pub fn confirm(question: &str, default: bool) -> Result<bool> {
26+
pub(crate) fn confirm(question: &str, default: bool) -> Result<bool> {
2727
write!(process().stdout(), "{} ", question)?;
2828
let _ = std::io::stdout().flush();
2929
let input = read_line()?;
@@ -40,13 +40,13 @@ pub fn confirm(question: &str, default: bool) -> Result<bool> {
4040
Ok(r)
4141
}
4242

43-
pub enum Confirm {
43+
pub(crate) enum Confirm {
4444
Yes,
4545
No,
4646
Advanced,
4747
}
4848

49-
pub fn confirm_advanced() -> Result<Confirm> {
49+
pub(crate) fn confirm_advanced() -> Result<Confirm> {
5050
writeln!(process().stdout())?;
5151
writeln!(process().stdout(), "1) Proceed with installation (default)")?;
5252
writeln!(process().stdout(), "2) Customize installation")?;
@@ -67,7 +67,7 @@ pub fn confirm_advanced() -> Result<Confirm> {
6767
Ok(r)
6868
}
6969

70-
pub fn question_str(question: &str, default: &str) -> Result<String> {
70+
pub(crate) fn question_str(question: &str, default: &str) -> Result<String> {
7171
writeln!(process().stdout(), "{} [{}]", question, default)?;
7272
let _ = std::io::stdout().flush();
7373
let input = read_line()?;
@@ -81,7 +81,7 @@ pub fn question_str(question: &str, default: &str) -> Result<String> {
8181
}
8282
}
8383

84-
pub fn question_bool(question: &str, default: bool) -> Result<bool> {
84+
pub(crate) fn question_bool(question: &str, default: bool) -> Result<bool> {
8585
let default_text = if default { "(Y/n)" } else { "(y/N)" };
8686
writeln!(process().stdout(), "{} {}", question, default_text)?;
8787

@@ -101,7 +101,7 @@ pub fn question_bool(question: &str, default: bool) -> Result<bool> {
101101
}
102102
}
103103

104-
pub fn read_line() -> Result<String> {
104+
pub(crate) fn read_line() -> Result<String> {
105105
let stdin = process().stdin();
106106
let stdin = stdin.lock();
107107
let mut lines = stdin.lines();
@@ -156,7 +156,7 @@ impl NotifyOnConsole {
156156
}
157157
}
158158

159-
pub fn set_globals(verbose: bool, quiet: bool) -> Result<Cfg> {
159+
pub(crate) fn set_globals(verbose: bool, quiet: bool) -> Result<Cfg> {
160160
use std::cell::RefCell;
161161

162162
use super::download_tracker::DownloadTracker;
@@ -175,7 +175,11 @@ pub fn set_globals(verbose: bool, quiet: bool) -> Result<Cfg> {
175175
}))
176176
}
177177

178-
pub fn show_channel_update(cfg: &Cfg, name: &str, updated: Result<UpdateStatus>) -> Result<()> {
178+
pub(crate) fn show_channel_update(
179+
cfg: &Cfg,
180+
name: &str,
181+
updated: Result<UpdateStatus>,
182+
) -> Result<()> {
179183
show_channel_updates(cfg, vec![(name.to_string(), updated)])
180184
}
181185

@@ -277,13 +281,13 @@ pub(crate) fn update_all_channels(
277281
}
278282

279283
#[derive(Clone, Copy, Debug)]
280-
pub enum SelfUpdatePermission {
284+
pub(crate) enum SelfUpdatePermission {
281285
HardFail,
282286
Skip,
283287
Permit,
284288
}
285289

286-
pub fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermission> {
290+
pub(crate) fn self_update_permitted(explicit: bool) -> Result<SelfUpdatePermission> {
287291
if cfg!(windows) {
288292
Ok(SelfUpdatePermission::Permit)
289293
} else {
@@ -528,7 +532,7 @@ pub(crate) fn list_overrides(cfg: &Cfg) -> Result<utils::ExitCode> {
528532

529533
git_testament!(TESTAMENT);
530534

531-
pub fn version() -> &'static str {
535+
pub(crate) fn version() -> &'static str {
532536
lazy_static! {
533537
// Because we trust our `stable` branch given the careful release
534538
// process, we mark it trusted here so that our version numbers look
@@ -618,7 +622,7 @@ pub fn report_error(e: &anyhow::Error) {
618622
}
619623
}
620624

621-
pub fn ignorable_error(error: &'static str, no_prompt: bool) -> Result<()> {
625+
pub(crate) fn ignorable_error(error: &'static str, no_prompt: bool) -> Result<()> {
622626
let error = anyhow!(error);
623627
report_error(&error);
624628
if no_prompt {

src/cli/download_tracker.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::Notification;
1616
const DOWNLOAD_TRACK_COUNT: usize = 5;
1717

1818
/// Tracks download progress and displays information about it to a terminal.
19-
pub struct DownloadTracker {
19+
pub(crate) struct DownloadTracker {
2020
/// Content-Length of the to-be downloaded object.
2121
content_len: Option<usize>,
2222
/// Total data downloaded in bytes.
@@ -53,7 +53,7 @@ pub struct DownloadTracker {
5353

5454
impl DownloadTracker {
5555
/// Creates a new DownloadTracker.
56-
pub fn new() -> Self {
56+
pub(crate) fn new() -> Self {
5757
Self {
5858
content_len: None,
5959
total_downloaded: 0,
@@ -68,7 +68,7 @@ impl DownloadTracker {
6868
}
6969
}
7070

71-
pub fn with_display_progress(mut self, display_progress: bool) -> Self {
71+
pub(crate) fn with_display_progress(mut self, display_progress: bool) -> Self {
7272
self.display_progress = display_progress;
7373
self
7474
}
@@ -104,12 +104,12 @@ impl DownloadTracker {
104104
}
105105

106106
/// Notifies self that Content-Length information has been received.
107-
pub fn content_length_received(&mut self, content_len: u64) {
107+
pub(crate) fn content_length_received(&mut self, content_len: u64) {
108108
self.content_len = Some(content_len as usize);
109109
}
110110

111111
/// Notifies self that data of size `len` has been received.
112-
pub fn data_received(&mut self, len: usize) {
112+
pub(crate) fn data_received(&mut self, len: usize) {
113113
self.total_downloaded += len;
114114
self.downloaded_this_sec += len;
115115

@@ -135,7 +135,7 @@ impl DownloadTracker {
135135
}
136136
}
137137
/// Notifies self that the download has finished.
138-
pub fn download_finished(&mut self) {
138+
pub(crate) fn download_finished(&mut self) {
139139
if self.displayed_charcount.is_some() {
140140
// Display the finished state
141141
self.display();
@@ -223,7 +223,7 @@ impl DownloadTracker {
223223
self.units.push(new_unit);
224224
}
225225

226-
pub fn pop_unit(&mut self) {
226+
pub(crate) fn pop_unit(&mut self) {
227227
self.units.pop();
228228
}
229229
}

src/cli/help.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
pub static RUSTUP_HELP: &str = r"DISCUSSION:
1+
pub(crate) static RUSTUP_HELP: &str = r"DISCUSSION:
22
Rustup installs The Rust Programming Language from the official
33
release channels, enabling you to easily switch between stable,
44
beta, and nightly compilers and keep them updated. It makes
@@ -8,7 +8,7 @@ pub static RUSTUP_HELP: &str = r"DISCUSSION:
88
If you are new to Rust consider running `rustup doc --book` to
99
learn Rust.";
1010

11-
pub static SHOW_HELP: &str = r"DISCUSSION:
11+
pub(crate) static SHOW_HELP: &str = r"DISCUSSION:
1212
Shows the name of the active toolchain and the version of `rustc`.
1313
1414
If the active toolchain has installed support for additional
@@ -17,7 +17,7 @@ pub static SHOW_HELP: &str = r"DISCUSSION:
1717
If there are multiple toolchains installed then all installed
1818
toolchains are listed as well.";
1919

20-
pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"DISCUSSION:
20+
pub(crate) static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"DISCUSSION:
2121
Shows the name of the active toolchain.
2222
2323
This is useful for figuring out the active tool chain from
@@ -26,24 +26,24 @@ pub static SHOW_ACTIVE_TOOLCHAIN_HELP: &str = r"DISCUSSION:
2626
You should use `rustc --print sysroot` to get the sysroot, or
2727
`rustc --version` to get the toolchain version.";
2828

29-
pub static UPDATE_HELP: &str = r"DISCUSSION:
29+
pub(crate) static UPDATE_HELP: &str = r"DISCUSSION:
3030
With no toolchain specified, the `update` command updates each of
3131
the installed toolchains from the official release channels, then
3232
updates rustup itself.
3333
3434
If given a toolchain argument then `update` updates that
3535
toolchain, the same as `rustup toolchain install`.";
3636

37-
pub static INSTALL_HELP: &str = r"DISCUSSION:
37+
pub(crate) static INSTALL_HELP: &str = r"DISCUSSION:
3838
Installs a specific rust toolchain.
3939
4040
The 'install' command is an alias for 'rustup update <toolchain>'.";
4141

42-
pub static DEFAULT_HELP: &str = r"DISCUSSION:
42+
pub(crate) static DEFAULT_HELP: &str = r"DISCUSSION:
4343
Sets the default toolchain to the one specified. If the toolchain
4444
is not already installed then it is installed first.";
4545

46-
pub static TOOLCHAIN_HELP: &str = r"DISCUSSION:
46+
pub(crate) static TOOLCHAIN_HELP: &str = r"DISCUSSION:
4747
Many `rustup` commands deal with *toolchains*, a single
4848
installation of the Rust compiler. `rustup` supports multiple
4949
types of toolchains. The most basic track the official release
@@ -85,7 +85,7 @@ pub static TOOLCHAIN_HELP: &str = r"DISCUSSION:
8585
often used for developing Rust itself. For more information see
8686
`rustup toolchain help link`.";
8787

88-
pub static TOOLCHAIN_LINK_HELP: &str = r"DISCUSSION:
88+
pub(crate) static TOOLCHAIN_LINK_HELP: &str = r"DISCUSSION:
8989
'toolchain' is the custom name to be assigned to the new toolchain.
9090
Any name is permitted as long as it does not fully match an initial
9191
substring of a standard release channel. For example, you can use
@@ -104,7 +104,7 @@ pub static TOOLCHAIN_LINK_HELP: &str = r"DISCUSSION:
104104
If you now compile a crate in the current directory, the custom
105105
toolchain 'latest-stage1' will be used.";
106106

107-
pub static OVERRIDE_HELP: &str = r"DISCUSSION:
107+
pub(crate) static OVERRIDE_HELP: &str = r"DISCUSSION:
108108
Overrides configure Rustup to use a specific toolchain when
109109
running in a specific directory.
110110
@@ -125,14 +125,14 @@ pub static OVERRIDE_HELP: &str = r"DISCUSSION:
125125
override and use the default toolchain again, `rustup override
126126
unset`.";
127127

128-
pub static OVERRIDE_UNSET_HELP: &str = r"DISCUSSION:
128+
pub(crate) static OVERRIDE_UNSET_HELP: &str = r"DISCUSSION:
129129
If `--path` argument is present, removes the override toolchain
130130
for the specified directory. If `--nonexistent` argument is
131131
present, removes the override toolchain for all nonexistent
132132
directories. Otherwise, removes the override toolchain for the
133133
current directory.";
134134

135-
pub static RUN_HELP: &str = r"DISCUSSION:
135+
pub(crate) static RUN_HELP: &str = r"DISCUSSION:
136136
Configures an environment to use the given toolchain and then runs
137137
the specified program. The command may be any program, not just
138138
rustc or cargo. This can be used for testing arbitrary toolchains
@@ -147,14 +147,14 @@ pub static RUN_HELP: &str = r"DISCUSSION:
147147
148148
$ rustup run nightly cargo build";
149149

150-
pub static DOC_HELP: &str = r"DISCUSSION:
150+
pub(crate) static DOC_HELP: &str = r"DISCUSSION:
151151
Opens the documentation for the currently active toolchain with
152152
the default browser.
153153
154154
By default, it opens the documentation index. Use the various
155155
flags to open specific pieces of documentation.";
156156

157-
pub static COMPLETIONS_HELP: &str = r"DISCUSSION:
157+
pub(crate) static COMPLETIONS_HELP: &str = r"DISCUSSION:
158158
Enable tab completion for Bash, Fish, Zsh, or PowerShell
159159
The script is output on `stdout`, allowing one to re-direct the
160160
output to the file of their choosing. Where you place the file
@@ -274,11 +274,11 @@ pub static COMPLETIONS_HELP: &str = r"DISCUSSION:
274274
275275
$ rustup completions zsh cargo > ~/.zfunc/_cargo";
276276

277-
pub static TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
277+
pub(crate) static TOOLCHAIN_ARG_HELP: &str = "Toolchain name, such as 'stable', 'nightly', \
278278
or '1.8.0'. For more information see `rustup \
279279
help toolchain`";
280280

281-
pub static TOPIC_ARG_HELP: &str = "Topic such as 'core', 'fn', 'usize', 'eprintln!', \
281+
pub(crate) static TOPIC_ARG_HELP: &str = "Topic such as 'core', 'fn', 'usize', 'eprintln!', \
282282
'core::arch', 'alloc::format!', 'std::fs', \
283283
'std::fs::read_dir', 'std::io::Bytes', \
284284
'std::iter::Sum', 'std::io::error::Result' etc...";

src/cli/job.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@
1919
2020
#![allow(clippy::missing_safety_doc)]
2121

22-
pub use self::imp::Setup;
22+
pub(crate) use self::imp::Setup;
2323

24-
pub fn setup() -> Option<Setup> {
24+
pub(crate) fn setup() -> Option<Setup> {
2525
unsafe { imp::setup() }
2626
}
2727

2828
#[cfg(unix)]
2929
mod imp {
30-
pub type Setup = ();
30+
pub(crate) type Setup = ();
3131

32-
pub unsafe fn setup() -> Option<()> {
32+
pub(crate) unsafe fn setup() -> Option<()> {
3333
Some(())
3434
}
3535
}
@@ -47,19 +47,19 @@ mod imp {
4747
use winapi::um::winnt::HANDLE;
4848
use winapi::um::winnt::*;
4949

50-
pub struct Setup {
50+
pub(crate) struct Setup {
5151
job: Handle,
5252
}
5353

54-
pub struct Handle {
54+
pub(crate) struct Handle {
5555
inner: HANDLE,
5656
}
5757

5858
fn last_err() -> io::Error {
5959
io::Error::last_os_error()
6060
}
6161

62-
pub unsafe fn setup() -> Option<Setup> {
62+
pub(crate) unsafe fn setup() -> Option<Setup> {
6363
// Creates a new job object for us to use and then adds ourselves to it.
6464
// Note that all errors are basically ignored in this function,
6565
// intentionally. Job objects are "relatively new" in Windows,

src/cli/log.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ macro_rules! debug {
2323
( $ ( $ arg : tt ) * ) => ( $crate::cli::log::debug_fmt ( format_args ! ( $ ( $ arg ) * ) ) )
2424
}
2525

26-
pub fn warn_fmt(args: fmt::Arguments<'_>) {
26+
pub(crate) fn warn_fmt(args: fmt::Arguments<'_>) {
2727
let mut t = term2::stderr();
2828
let _ = t.fg(term2::color::YELLOW);
2929
let _ = t.attr(term2::Attr::Bold);
@@ -33,7 +33,7 @@ pub fn warn_fmt(args: fmt::Arguments<'_>) {
3333
let _ = writeln!(t);
3434
}
3535

36-
pub fn err_fmt(args: fmt::Arguments<'_>) {
36+
pub(crate) fn err_fmt(args: fmt::Arguments<'_>) {
3737
let mut t = term2::stderr();
3838
let _ = t.fg(term2::color::RED);
3939
let _ = t.attr(term2::Attr::Bold);
@@ -43,7 +43,7 @@ pub fn err_fmt(args: fmt::Arguments<'_>) {
4343
let _ = writeln!(t);
4444
}
4545

46-
pub fn info_fmt(args: fmt::Arguments<'_>) {
46+
pub(crate) fn info_fmt(args: fmt::Arguments<'_>) {
4747
let mut t = term2::stderr();
4848
let _ = t.attr(term2::Attr::Bold);
4949
let _ = write!(t, "info: ");
@@ -52,7 +52,7 @@ pub fn info_fmt(args: fmt::Arguments<'_>) {
5252
let _ = writeln!(t);
5353
}
5454

55-
pub fn verbose_fmt(args: fmt::Arguments<'_>) {
55+
pub(crate) fn verbose_fmt(args: fmt::Arguments<'_>) {
5656
let mut t = term2::stderr();
5757
let _ = t.fg(term2::color::MAGENTA);
5858
let _ = t.attr(term2::Attr::Bold);
@@ -62,7 +62,7 @@ pub fn verbose_fmt(args: fmt::Arguments<'_>) {
6262
let _ = writeln!(t);
6363
}
6464

65-
pub fn debug_fmt(args: fmt::Arguments<'_>) {
65+
pub(crate) fn debug_fmt(args: fmt::Arguments<'_>) {
6666
if process().var("RUSTUP_DEBUG").is_ok() {
6767
let mut t = term2::stderr();
6868
let _ = t.fg(term2::color::BLUE);

src/cli/markdown.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ struct LineWrapper<'a, T: Terminal> {
1111
indent: u32,
1212
margin: u32,
1313
pos: u32,
14-
pub w: &'a mut T,
14+
pub(crate) w: &'a mut T,
1515
}
1616

1717
impl<'a, T: Terminal + 'a> LineWrapper<'a, T> {
@@ -221,7 +221,7 @@ impl<'a, T: Terminal + io::Write + 'a> LineFormatter<'a, T> {
221221
}
222222
}
223223

224-
pub fn md<'a, S: AsRef<str>, T: Terminal + io::Write + 'a>(t: &'a mut T, content: S) {
224+
pub(crate) fn md<'a, S: AsRef<str>, T: Terminal + io::Write + 'a>(t: &'a mut T, content: S) {
225225
let mut f = LineFormatter::new(t, 0, 79);
226226
let parser = pulldown_cmark::Parser::new(content.as_ref());
227227
for event in parser {

0 commit comments

Comments
 (0)