-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
tinty config
subcommand (with flags) to return config related i…
…nformation (#24)
- Loading branch information
1 parent
4b4b17b
commit 93bd9a9
Showing
9 changed files
with
222 additions
and
18 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
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
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,34 @@ | ||
use anyhow::{anyhow, Result}; | ||
use std::path::Path; | ||
|
||
use crate::config::Config; | ||
|
||
pub fn config( | ||
config_path: &Path, | ||
data_path: &Path, | ||
config_path_flag: bool, | ||
data_dir_path_flag: bool, | ||
) -> Result<()> { | ||
let config = Config::read(config_path)?; | ||
let path_tuple: (bool, bool) = (config_path_flag, data_dir_path_flag); | ||
|
||
match path_tuple { | ||
(true, false) => { | ||
println!("{}", config_path.display()); | ||
} | ||
(false, true) => { | ||
println!("{}", data_path.display()); | ||
} | ||
(false, false) => { | ||
println!("{config}"); | ||
} | ||
(true, true) => { | ||
// This case should be dealt with by clap | ||
return Err(anyhow!( | ||
"the argument '--data-dir-path' cannot be used with '--config-path'", | ||
)); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
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,4 +1,5 @@ | ||
pub mod apply; | ||
pub mod config; | ||
pub mod current; | ||
pub mod info; | ||
pub mod init; | ||
|
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,118 @@ | ||
mod common; | ||
|
||
use crate::common::{setup, write_to_file}; | ||
use anyhow::Result; | ||
|
||
#[test] | ||
fn test_cli_config_without_config() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let expected = r#"shell = "sh -c '{}'" | ||
[[items]] | ||
name = "base16-shell" | ||
path = "https://github.com/tinted-theming/base16-shell" | ||
hook = ". %f" | ||
supported-systems = ["base16"] | ||
themes-dir = "scripts" | ||
"#; | ||
let (_, _, command_vec, cleanup) = setup("test_cli_config_without_config", "config")?; | ||
|
||
// --- | ||
// Act | ||
// --- | ||
let (stdout, _) = common::run_command(command_vec).unwrap(); | ||
|
||
// ------ | ||
// Assert | ||
// ------ | ||
assert_eq!(stdout, expected); | ||
|
||
cleanup()?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_cli_config_with_config() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let config_text = r#"shell = "zsh -c '{}'" | ||
default-scheme = "base16-oceanicnext" | ||
[[items]] | ||
name = "tinted-vim" | ||
path = "https://github.com/tinted-theming/tinted-vim" | ||
supported-systems = ["base16", "base24"] | ||
themes-dir = "colors" | ||
"#; | ||
let (config_path, _, command_vec, cleanup) = setup("test_cli_config_with_config", "config")?; | ||
|
||
write_to_file(&config_path, config_text)?; | ||
|
||
// --- | ||
// Act | ||
// --- | ||
let (stdout, _) = common::run_command(command_vec).unwrap(); | ||
|
||
// ------ | ||
// Assert | ||
// ------ | ||
assert_eq!(stdout, config_text); | ||
|
||
cleanup()?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_cli_config_with_config_flag() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let (config_path, _, command_vec, cleanup) = | ||
setup("test_cli_config_with_config_flag", "config --config-path")?; | ||
|
||
// --- | ||
// Act | ||
// --- | ||
let (stdout, _) = common::run_command(command_vec).unwrap(); | ||
|
||
// ------ | ||
// Assert | ||
// ------ | ||
assert!( | ||
stdout.contains(format!("{}", config_path.display()).as_str()), | ||
"stdout does not contain the expected output" | ||
); | ||
|
||
cleanup()?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_cli_config_with_data_flag() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let (_, data_path, command_vec, cleanup) = | ||
setup("test_cli_config_with_data_flag", "config --data-dir-path")?; | ||
|
||
// --- | ||
// Act | ||
// --- | ||
let (stdout, _) = common::run_command(command_vec).unwrap(); | ||
|
||
// ------ | ||
// Assert | ||
// ------ | ||
assert!( | ||
stdout.contains(format!("{}", data_path.display()).as_str()), | ||
"stdout does not contain the expected output" | ||
); | ||
|
||
cleanup()?; | ||
Ok(()) | ||
} |