Skip to content

Commit b3c30a3

Browse files
committed
generate: read placeholders with choices from cargo-generate.toml
1 parent b0b1fe4 commit b3c30a3

File tree

5 files changed

+255
-168
lines changed

5 files changed

+255
-168
lines changed

xtask/Cargo.lock

Lines changed: 3 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xtask/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ edition = "2024"
77
[dependencies]
88
anyhow = "1.0.100"
99
clap = { version = "4.5.53", features = ["derive"] }
10-
strum = { version = "0.27.2", features = ["derive"] }
1110
log = "0.4.28"
1211
env_logger = "0.11.8"
12+
13+
# deps below are copied from `cargo-generate`
1314
cargo-generate = { version = "0.23.7", default-features = false, features = [] }
15+
serde = { version = "~1.0", features = ["derive"] }
16+
toml = { version = "~0.9", features = ["preserve_order"] }
17+
indexmap = { version = "~2", features = ["serde"] }

xtask/src/cargo_generate_config.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//! These definitions are copied from `cargo_generate::config`, since that interface isn't pub.
2+
//! Only keys we need are kept.
3+
4+
use indexmap::IndexMap;
5+
use serde::Deserialize;
6+
use std::collections::HashMap;
7+
8+
pub const CONFIG_FILE_NAME: &str = "cargo-generate.toml";
9+
10+
#[derive(Deserialize, Debug, PartialEq, Default, Clone)]
11+
pub struct Config {
12+
pub template: Option<TemplateConfig>,
13+
pub placeholders: Option<TemplateSlotsTable>,
14+
pub conditional: Option<HashMap<String, ConditionalConfig>>,
15+
}
16+
17+
#[derive(Deserialize, Debug, PartialEq, Eq, Default, Clone)]
18+
pub struct TemplateConfig {
19+
pub sub_templates: Option<Vec<String>>,
20+
}
21+
22+
#[derive(Deserialize, Debug, PartialEq, Clone)]
23+
pub struct ConditionalConfig {
24+
pub placeholders: Option<TemplateSlotsTable>,
25+
}
26+
27+
#[derive(Deserialize, Debug, PartialEq, Clone, Default)]
28+
pub struct TemplateSlotsTable(pub IndexMap<String, toml::Value>);

0 commit comments

Comments
 (0)