Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
20a7a3b
commit 3892098
Showing
10 changed files
with
219 additions
and
4 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
use std::fmt; | ||
use std::path::PathBuf; | ||
|
||
use crate::common::*; | ||
|
||
// A structure used to compare environment files | ||
pub struct CompareFileType { | ||
pub path: PathBuf, | ||
pub keys: Vec<String>, | ||
pub missing: Vec<String>, | ||
} | ||
|
||
pub struct CompareWarning { | ||
pub path: PathBuf, | ||
pub missing_keys: Vec<String>, | ||
} | ||
|
||
impl fmt::Display for CompareWarning { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
write!( | ||
f, | ||
"{}", | ||
format!( | ||
"{} is missing keys: {}", | ||
self.path.display(), | ||
self.missing_keys.join(", ") | ||
) | ||
.italic(), | ||
) | ||
} | ||
} |
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,24 @@ | ||
use crate::common::{CompareWarning, FileEntry}; | ||
|
||
pub struct CompareOutput { | ||
// Quiet program output mode | ||
is_quiet_mode: bool, | ||
} | ||
|
||
impl CompareOutput { | ||
pub fn new(is_quiet_mode: bool) -> Self { | ||
CompareOutput { is_quiet_mode } | ||
} | ||
|
||
/// Prints information about a file in process | ||
pub fn print_processing_info(&self, file: &FileEntry) { | ||
if !self.is_quiet_mode { | ||
println!("Comparing {}", file); | ||
} | ||
} | ||
|
||
/// Prints warnings without any additional information | ||
pub fn print_warnings(&self, warnings: &[CompareWarning]) { | ||
warnings.iter().for_each(|w| println!("{}", w)) | ||
} | ||
} |
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,2 +1,3 @@ | ||
pub mod check; | ||
pub mod compare; | ||
pub mod fix; |
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,6 +1,7 @@ | ||
mod args; | ||
mod checks; | ||
mod common; | ||
mod compare; | ||
mod fixes; | ||
mod flags; | ||
mod options; | ||
|
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 crate::common::TestDir; | ||
|
||
#[test] | ||
fn files_with_same_environment_variables() { | ||
let test_dir = TestDir::new(); | ||
let testfile_one = test_dir.create_testfile(".env1", "FOO=abc\nBAR=def"); | ||
let testfile_two = test_dir.create_testfile(".env2", "FOO=abc\nBAR=def"); | ||
let expected_output = format!("Comparing .env1\nComparing .env2\n"); | ||
|
||
test_dir.test_command_success_with_args( | ||
&["compare", testfile_one.as_str(), testfile_two.as_str()], | ||
expected_output, | ||
); | ||
} | ||
|
||
#[test] | ||
fn files_with_same_environment_variables_in_quiet_mode() { | ||
let test_dir = TestDir::new(); | ||
let testfile_one = test_dir.create_testfile(".env1", "FOO=abc\nBAR=def"); | ||
let testfile_two = test_dir.create_testfile(".env2", "FOO=abc\nBAR=def"); | ||
let expected_output = format!(""); | ||
|
||
test_dir.test_command_success_with_args( | ||
&[ | ||
"compare", | ||
"--quiet", | ||
testfile_one.as_str(), | ||
testfile_two.as_str(), | ||
], | ||
expected_output, | ||
); | ||
} | ||
|
||
#[test] | ||
fn files_with_different_environment_variables() { | ||
let test_dir = TestDir::new(); | ||
let testfile_one = test_dir.create_testfile(".env1", "FOO=abc"); | ||
let testfile_two = test_dir.create_testfile(".env2", "FOO=abc\nBAR=def"); | ||
let expected_output = format!("Comparing .env1\nComparing .env2\n.env1 is missing keys: BAR\n"); | ||
|
||
test_dir.test_command_fail_with_args( | ||
&["compare", testfile_one.as_str(), testfile_two.as_str()], | ||
expected_output, | ||
) | ||
} | ||
|
||
#[test] | ||
fn files_with_different_environment_variables_in_quiet_mode() { | ||
let test_dir = TestDir::new(); | ||
let testfile_one = test_dir.create_testfile(".env1", "FOO=abc"); | ||
let testfile_two = test_dir.create_testfile(".env2", "FOO=abc\nBAR=def"); | ||
let expected_output = format!(".env1 is missing keys: BAR\n"); | ||
|
||
test_dir.test_command_fail_with_args( | ||
&[ | ||
"compare", | ||
"--quiet", | ||
testfile_one.as_str(), | ||
testfile_two.as_str(), | ||
], | ||
expected_output, | ||
) | ||
} |
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 @@ | ||
mod compare; |