Skip to content

Commit

Permalink
ref: Privatize top-level modules and delete dead code (#1992)
Browse files Browse the repository at this point in the history
Since the CLI is only published as a binary, and not as a library, there is no reason for the top-level modules to be public. So, this PR makes them private.

After making them private, the Rust compiler warned of several parts of the code that were unused. So, this PR removes all the dead code noticed by the compiler. The Rust compiler also warned of some code that was unused in Linux and Windows (but they are still used in the macOS binary), this PR adds #[cfg(target_os = "macos")] directives as needed to ensure this code is only compiled for the macOS platform
  • Loading branch information
szokeasaurusrex committed Mar 26, 2024
1 parent 63a515d commit 14ff75a
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 299 deletions.
29 changes: 7 additions & 22 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use std::{env, fmt};
use anyhow::{Context, Result};
use backoff::backoff::Backoff;
use brotli2::write::BrotliEncoder;
use chrono::{DateTime, Duration, FixedOffset, Utc};
#[cfg(target_os = "macos")]
use chrono::Duration;
use chrono::{DateTime, FixedOffset, Utc};
use clap::ArgMatches;
use flate2::write::GzEncoder;
use if_chain::if_chain;
Expand Down Expand Up @@ -158,7 +160,6 @@ pub enum ProgressBarMode {
Disabled,
Request,
Response,
Both,
Shared((Arc<ProgressBar>, u64, usize, Arc<RwLock<Vec<u64>>>)),
}

Expand All @@ -170,12 +171,12 @@ impl ProgressBarMode {

/// Returns whether a progress bar should be displayed during upload.
pub fn request(&self) -> bool {
matches!(*self, ProgressBarMode::Request | ProgressBarMode::Both)
matches!(*self, ProgressBarMode::Request)
}

/// Returns whether a progress bar should be displayed during download.
pub fn response(&self) -> bool {
matches!(*self, ProgressBarMode::Response | ProgressBarMode::Both)
matches!(*self, ProgressBarMode::Response)
}
}

Expand Down Expand Up @@ -324,7 +325,6 @@ pub type ApiResult<T> = Result<T, ApiError>;
#[derive(Eq, PartialEq, Debug)]
pub enum Method {
Get,
Head,
Post,
Put,
Delete,
Expand All @@ -334,7 +334,6 @@ impl fmt::Display for Method {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
Method::Get => write!(f, "GET"),
Method::Head => write!(f, "HEAD"),
Method::Post => write!(f, "POST"),
Method::Put => write!(f, "PUT"),
Method::Delete => write!(f, "DELETE"),
Expand Down Expand Up @@ -532,7 +531,8 @@ impl Api {
}

/// Convenience method that waits for a few seconds until a resource
/// becomes available.
/// becomes available. We only use this in the macOS binary.
#[cfg(target_os = "macos")]
pub fn wait_until_available(&self, url: &str, duration: Duration) -> ApiResult<bool> {
let started = Utc::now();
loop {
Expand Down Expand Up @@ -1851,11 +1851,6 @@ impl ApiRequest {

match method {
Method::Get => handle.get(true)?,
Method::Head => {
handle.get(true)?;
handle.custom_request("HEAD")?;
handle.nobody(true)?;
}
Method::Post => handle.custom_request("POST")?,
Method::Put => handle.custom_request("PUT")?,
Method::Delete => handle.custom_request("DELETE")?,
Expand Down Expand Up @@ -2235,16 +2230,6 @@ pub struct Artifact {
}

impl Artifact {
pub fn get_header<'a>(&'a self, key: &str) -> Option<&'a str> {
let ikey = key.to_lowercase();
for (k, v) in &self.headers {
if k.to_lowercase() == ikey {
return Some(v.as_str());
}
}
None
}

pub fn get_sourcemap_reference(&self) -> Option<&str> {
get_sourcemap_reference_from_headers(self.headers.iter())
}
Expand Down
4 changes: 3 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,9 @@ impl Config {
)
}

/// Returns true if notifications should be displayed
/// Returns true if notifications should be displayed.
/// We only use this function in the macOS binary.
#[cfg(target_os = "macos")]
pub fn show_notifications(&self) -> Result<bool> {
Ok(self
.ini
Expand Down
10 changes: 5 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
//! exported function is `main` which is directly invoked from the
//! compiled binary that links against this library.

pub mod api;
pub mod commands;
pub mod config;
pub mod constants;
pub mod utils;
mod api;
mod commands;
mod config;
mod constants;
mod utils;

/// Executes the command line application and exits the process.
pub fn main() {
Expand Down
140 changes: 0 additions & 140 deletions src/utils/codepush.rs

This file was deleted.

48 changes: 0 additions & 48 deletions src/utils/dif_upload.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1876,17 +1876,6 @@ impl DifUpload {
self
}

/// Add a `DebugId` to filter for.
///
/// By default, all DebugIds will be included.
pub fn filter_id<I>(&mut self, id: I) -> &mut Self
where
I: Into<DebugId>,
{
self.ids.insert(id.into());
self
}

/// Add `DebugId`s to filter for.
///
/// By default, all DebugIds will be included. If `ids` is empty, this will
Expand All @@ -1910,18 +1899,6 @@ impl DifUpload {
self
}

/// Add `FileFormat`s to filter for.
///
/// By default, all object formats will be included. If `formats` is empty, this
/// will not be changed.
pub fn filter_formats<I>(&mut self, formats: I) -> &mut Self
where
I: IntoIterator<Item = DifFormat>,
{
self.formats.extend(formats);
self
}

/// Add an `ObjectFeature` to filter for.
///
/// By default, all object features will be included.
Expand All @@ -1930,31 +1907,6 @@ impl DifUpload {
self
}

/// Add a file extension to filter for.
///
/// By default, all file extensions will be included.
pub fn filter_extension<S>(&mut self, extension: S) -> &mut Self
where
S: Into<OsString>,
{
self.extensions.insert(extension.into());
self
}

/// Add a file extension to filter for.
///
/// By default, all file extensions will be included.
pub fn filter_extensions<I>(&mut self, extensions: I) -> &mut Self
where
I: IntoIterator,
I::Item: Into<OsString>,
{
for extension in extensions {
self.extensions.insert(extension.into());
}
self
}

/// Set a path containing BCSymbolMaps to resolve hidden symbols in dSYMs
/// obtained from iTunes Connect. This requires the `dsymutil` command.
///
Expand Down
31 changes: 0 additions & 31 deletions src/utils/enc.rs

This file was deleted.

16 changes: 0 additions & 16 deletions src/utils/file_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ impl ReleaseFileSearch {
self
}

pub fn extension<E>(&mut self, extension: E) -> &mut Self
where
E: Into<String>,
{
self.extensions.insert(extension.into());
self
}

pub fn extensions<E>(&mut self, extensions: E) -> &mut Self
where
E: IntoIterator,
Expand All @@ -64,14 +56,6 @@ impl ReleaseFileSearch {
self
}

pub fn ignore<I>(&mut self, ignore: I) -> &mut Self
where
I: Into<String>,
{
self.ignores.insert(ignore.into());
self
}

pub fn ignores<I>(&mut self, ignores: I) -> &mut Self
where
I: IntoIterator,
Expand Down
Loading

0 comments on commit 14ff75a

Please sign in to comment.