Skip to content

Commit 74ee1cb

Browse files
committed
Update List operation to get list of schemes recursively
This now ignores directory structure
1 parent 14c76f1 commit 74ee1cb

File tree

3 files changed

+42
-14
lines changed

3 files changed

+42
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
- Support arguments with `current` subcommand to allow consumers to get
88
specific current scheme data
99

10+
### Changed
11+
12+
- Update `list` operation to get schemes from a directory recursively
13+
1014
## [0.21.1] - 2024-10-02
1115

1216
### Fixed

src/operations/list.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
use crate::{
2-
constants::{CUSTOM_SCHEMES_DIR_NAME, REPO_DIR, REPO_NAME, SCHEMES_REPO_NAME},
3-
utils::get_all_scheme_names,
4-
};
1+
use crate::constants::{CUSTOM_SCHEMES_DIR_NAME, REPO_DIR, REPO_NAME, SCHEMES_REPO_NAME};
52
use anyhow::{anyhow, Result};
63
use std::path::Path;
4+
use tinted_builder_rust::utils::get_scheme_files;
75

86
/// Lists available color schemes
97
///
@@ -32,9 +30,13 @@ pub fn list(data_path: &Path, is_custom: bool) -> Result<()> {
3230
_ => {}
3331
}
3432

35-
let scheme_vec = get_all_scheme_names(&schemes_dir_path, None)?;
36-
for scheme in scheme_vec {
37-
println!("{}", scheme);
33+
let scheme_files = get_scheme_files(&schemes_dir_path, true)?;
34+
for scheme_file in scheme_files {
35+
let scheme_container = scheme_file.get_scheme()?;
36+
let system = scheme_container.get_scheme_system();
37+
let slug = scheme_container.get_scheme_slug();
38+
39+
println!("{}-{}", system, slug);
3840
}
3941

4042
Ok(())

tests/cli_list_subcommand_tests.rs

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::utils::REPO_NAME;
44
use anyhow::Result;
55
use std::fs;
66
use std::path::Path;
7-
use utils::setup;
7+
use utils::{setup, write_to_file};
88

99
#[test]
1010
fn test_cli_list_subcommand_without_setup() -> Result<()> {
@@ -103,7 +103,7 @@ fn test_cli_list_subcommand_with_custom() -> Result<()> {
103103
let (_, data_path, command_vec, cleanup) =
104104
setup("test_cli_list_subcommand_with_custom", "list")?;
105105
let scheme_system = "base16";
106-
let scheme_name_one = "tinted-theming";
106+
let scheme_name_one = "tinty-generated";
107107
let scheme_name_two = "tinty";
108108
let expected_output = format!(
109109
"{}-{}\n{}-{}",
@@ -112,13 +112,35 @@ fn test_cli_list_subcommand_with_custom() -> Result<()> {
112112
let custom_scheme_path = data_path.join("custom-schemes");
113113

114114
fs::create_dir_all(custom_scheme_path.join(scheme_system))?;
115-
fs::write(
116-
custom_scheme_path.join(format!("{}/{}.yaml", scheme_system, scheme_name_one)),
117-
"",
115+
fs::copy(
116+
"./tests/fixtures/schemes/tinty-generated.yaml",
117+
custom_scheme_path.join("base16-tinty-generated.yaml"),
118118
)?;
119-
fs::write(
119+
write_to_file(
120120
custom_scheme_path.join(format!("{}/{}.yaml", scheme_system, scheme_name_two)),
121-
"",
121+
r#"
122+
system: base16
123+
name: Tinty
124+
slug: tinty
125+
author: Tinty
126+
variant: dark
127+
palette:
128+
base00: '#282628'
129+
base01: '#403e3f'
130+
base02: '#595757'
131+
base03: '#71706e'
132+
base04: '#8a8986'
133+
base05: '#a2a29d'
134+
base06: '#bbbbb5'
135+
base07: '#d4d4cd'
136+
base08: '#bf2546'
137+
base09: '#f69622'
138+
base0A: '#f99923'
139+
base0B: '#19953f'
140+
base0C: '#40dab9'
141+
base0D: '#0666dc'
142+
base0E: '#8554ac'
143+
base0F: '#ac7424'"#,
122144
)?;
123145

124146
let mut command_vec = command_vec.clone();

0 commit comments

Comments
 (0)