Skip to content

Commit 4763b70

Browse files
committed
cli: init with template
1 parent 47abb5d commit 4763b70

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

devenv/src/cli.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,11 @@ impl GlobalOptions {
182182
#[derive(Subcommand, Clone)]
183183
pub enum Commands {
184184
#[command(about = "Scaffold devenv.yaml, devenv.nix, .gitignore and .envrc.")]
185-
Init { target: Option<PathBuf> },
185+
Init {
186+
target: Option<PathBuf>,
187+
#[arg(long, help = "Use template")]
188+
template: Option<String>,
189+
},
186190

187191
#[command(about = "Generate devenv.yaml and devenv.nix using AI")]
188192
Generate {

devenv/src/cnix.rs

+7
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,13 @@ impl Nix {
246246
Ok(())
247247
}
248248

249+
pub async fn init(&self, template: &String) -> Result<()> {
250+
self.run_nix("nix", &["flake", "init", "-t", &template], &self.options)
251+
.await?;
252+
253+
Ok(())
254+
}
255+
249256
pub async fn metadata(&self) -> Result<String> {
250257
let options = Options {
251258
cache_output: true,

devenv/src/devenv.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,12 @@ impl Devenv {
145145
self.devenv_dotfile.join("processes.pid")
146146
}
147147

148-
pub fn init(&self, target: &Option<PathBuf>) -> Result<()> {
148+
pub async fn init(&self, target: &Option<PathBuf>, template: &Option<String>) -> Result<()> {
149+
if let Some(template) = template {
150+
self.nix.init(template).await?;
151+
return Ok(());
152+
}
153+
149154
let target = target
150155
.clone()
151156
.unwrap_or_else(|| fs::canonicalize(".").expect("Failed to get current directory"));

devenv/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ async fn main() -> Result<()> {
133133
};
134134
Ok(())
135135
}
136-
Commands::Init { target } => devenv.init(&target),
136+
Commands::Init { target, template } => devenv.init(&target, &template).await,
137137
Commands::Generate { .. } => match which::which("devenv-generate") {
138138
Ok(devenv_generate) => {
139139
let error = Command::new(devenv_generate)

0 commit comments

Comments
 (0)