-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactored and separated file format
- Loading branch information
Showing
9 changed files
with
144 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
HELLO=string | ||
TAYLOR=string | ||
AGE=int | ||
SCORE=float | ||
ACTIVE=bool |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,12 @@ | ||
pre-commit: | ||
commands: | ||
format: | ||
glob: "*.rs" | ||
run: cargo fmt | ||
|
||
check: | ||
run: "cargo check" | ||
|
||
test: | ||
run: "cargo test" | ||
|
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,27 @@ | ||
#[derive(Debug, PartialEq)] | ||
pub enum SupportedFormats { | ||
ENV, | ||
TOML, | ||
YAML, | ||
INVALID, | ||
} | ||
|
||
impl SupportedFormats { | ||
pub fn to_string(&self) -> String { | ||
match self { | ||
SupportedFormats::ENV => "env", | ||
SupportedFormats::TOML => "toml", | ||
SupportedFormats::YAML => "yaml", | ||
_ => "invalid", | ||
} | ||
.to_string() | ||
} | ||
|
||
pub fn supported_formats() -> Vec<String> { | ||
return vec![ | ||
SupportedFormats::ENV.to_string(), | ||
SupportedFormats::TOML.to_string(), | ||
SupportedFormats::YAML.to_string(), | ||
]; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
use crate::common::SupportedFormats; | ||
use colored::*; | ||
|
||
fn _extract_file_format(path: &str) -> SupportedFormats { | ||
let file_extension = path.split('.').last().unwrap(); | ||
match file_extension { | ||
"env" => SupportedFormats::ENV, | ||
"toml" => SupportedFormats::TOML, | ||
"yaml" => SupportedFormats::YAML, | ||
_ => SupportedFormats::INVALID, | ||
} | ||
} | ||
|
||
fn _check_file_format(path: &str) -> SupportedFormats { | ||
let format = _extract_file_format(path); | ||
if format == SupportedFormats::INVALID { | ||
println!( | ||
"{} {}", | ||
"❌ Error:".red(), | ||
"Unsupported file format".bold() | ||
); | ||
println!( | ||
"{} {}", | ||
"Supported formats:".bold(), | ||
SupportedFormats::supported_formats().join(", ").bold() | ||
); | ||
std::process::exit(1); | ||
} | ||
return format; | ||
} | ||
|
||
fn _check_path_exists(path: &str) { | ||
if std::path::Path::new(path).exists() == false { | ||
println!("{} {}", "❌ Error:".red(), "File not found".bold()); | ||
std::process::exit(1); | ||
} | ||
} | ||
|
||
pub fn validate_file(path: &str) -> SupportedFormats { | ||
_check_path_exists(path); | ||
_check_file_format(path) | ||
} |
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 |
---|---|---|
|
@@ -7,3 +7,5 @@ AGE=25 | |
ACTIVE =true | ||
|
||
# | ||
|
||
|