-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Resolves #110 This PR adds the `OS` enum and updates `AssetName` logic to use it instead of `env::consts::OS`. It also improves a single error message to display `Specify 'asset_name.{get_current_os()}'` in it.
- Loading branch information
Showing
6 changed files
with
81 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod asset_name; | ||
pub mod os; | ||
pub mod release; | ||
pub mod tool; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
use std::env; | ||
use std::fmt::{Display, Formatter}; | ||
|
||
#[derive(Debug, PartialEq, Eq)] | ||
pub enum OS { | ||
Windows, | ||
MacOS, | ||
Linux, | ||
} | ||
|
||
/// Return the current OS where the 'tool-sync' is running | ||
/// | ||
/// !!! WARNING !!! This function uses OS of the system where 'tool-sync' was | ||
/// compiled. The function relies on the assumption that a user will run e.g. | ||
/// the macOS executable on macOS | ||
pub fn get_current_os() -> OS { | ||
match env::consts::OS { | ||
"windows" => OS::Windows, | ||
"macos" => OS::MacOS, | ||
_ => OS::Linux, | ||
} | ||
} | ||
|
||
impl Display for OS { | ||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Windows => { | ||
write!(f, "windows") | ||
} | ||
Self::MacOS => { | ||
write!(f, "macos") | ||
} | ||
Self::Linux => { | ||
write!(f, "linux") | ||
} | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn current_os() { | ||
let os = get_current_os(); | ||
|
||
if cfg!(target_os = "windows") { | ||
assert_eq!(os, OS::Windows); | ||
} else if cfg!(target_os = "macos") { | ||
assert_eq!(os, OS::MacOS); | ||
} else { | ||
assert_eq!(os, OS::Linux); | ||
} | ||
} | ||
|
||
#[test] | ||
fn os_display() { | ||
assert_eq!(OS::Windows.to_string(), String::from("windows")); | ||
assert_eq!(OS::MacOS.to_string(), String::from("macos")); | ||
assert_eq!(OS::Linux.to_string(), String::from("linux")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters