-
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
current
operation to print the last scheme name set by the user
- Version bump to 0.7.0 - Useful command to easily check the last set scheme instead of manually looking at the value of `current_scheme` file - Attempt to reach feature parity with Flavours
- Loading branch information
1 parent
2cd4215
commit bdf00b1
Showing
11 changed files
with
128 additions
and
3 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
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
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,22 @@ | ||
use crate::constants::CURRENT_SCHEME_FILE_NAME; | ||
use crate::utils::read_file_to_string; | ||
use anyhow::{anyhow, Result}; | ||
use std::path::Path; | ||
|
||
/// Initialize based on existing data_path files | ||
/// | ||
/// This is used to set the theme when your shell is opened. It is based on your previously set | ||
/// theme or your default theme set in config. | ||
pub fn current(data_path: &Path) -> Result<()> { | ||
let current_scheme_name = read_file_to_string(&data_path.join(CURRENT_SCHEME_FILE_NAME)).ok(); | ||
|
||
match current_scheme_name { | ||
Some(scheme_name) => { | ||
println!("{}", scheme_name); | ||
Ok(()) | ||
} | ||
None => Err(anyhow!( | ||
"Failed to read last scheme from file. Try setting a scheme and try again." | ||
)), | ||
} | ||
} |
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 current; | ||
pub mod init; | ||
pub mod list; | ||
pub mod set; | ||
|
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,83 @@ | ||
mod common; | ||
|
||
use crate::common::{cleanup, write_to_file, COMMAND_NAME, REPO_NAME}; | ||
use anyhow::{anyhow, Result}; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
#[test] | ||
fn test_cli_current_subcommand_with_setup() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let config_path = Path::new("test_cli_current_subcommand_with_setup"); | ||
let scheme_name = "base16-oceanicnext"; | ||
let command = format!( | ||
"{} --config=\"{}\" current", | ||
COMMAND_NAME, | ||
config_path.display(), | ||
); | ||
let command_vec = shell_words::split(command.as_str()).map_err(anyhow::Error::new)?; | ||
let system_data_path: PathBuf = | ||
dirs::data_dir().ok_or_else(|| anyhow!("Error getting data directory"))?; | ||
let data_dir = system_data_path.join(format!("tinted-theming/{}", REPO_NAME)); | ||
let current_scheme_path = data_dir.join("current_scheme"); | ||
cleanup(config_path)?; | ||
if !config_path.exists() { | ||
fs::create_dir(config_path)?; | ||
} | ||
write_to_file(¤t_scheme_path, scheme_name)?; | ||
|
||
// // --- | ||
// // Act | ||
// // --- | ||
let (stdout, stderr) = common::run_command(command_vec).unwrap(); | ||
|
||
// // ------ | ||
// // Assert | ||
// // ------ | ||
assert!( | ||
stdout.contains(scheme_name), | ||
"stdout does not contain the expected output" | ||
); | ||
assert!( | ||
stderr.is_empty(), | ||
"stderr does not contain the expected output" | ||
); | ||
|
||
cleanup(config_path)?; | ||
Ok(()) | ||
} | ||
|
||
#[test] | ||
fn test_cli_current_subcommand_without_setup() -> Result<()> { | ||
// ------- | ||
// Arrange | ||
// ------- | ||
let config_path = Path::new("test_cli_current_subcommand_without_setup"); | ||
let command = format!( | ||
"{} --config=\"{}\" current", | ||
COMMAND_NAME, | ||
config_path.display(), | ||
); | ||
let command_vec = shell_words::split(command.as_str()).map_err(anyhow::Error::new)?; | ||
cleanup(config_path)?; | ||
fs::create_dir(config_path)?; | ||
|
||
// // --- | ||
// // Act | ||
// // --- | ||
let (_, stderr) = common::run_command(command_vec).unwrap(); | ||
|
||
// // ------ | ||
// // Assert | ||
// // ------ | ||
cleanup(config_path)?; | ||
assert!( | ||
stderr | ||
.contains("Failed to read last scheme from file. Try setting a scheme and try again."), | ||
"stderr does not contain the expected output" | ||
); | ||
|
||
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