Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli: init with template #1721

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion devenv/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,11 @@ impl GlobalOptions {
#[derive(Subcommand, Clone)]
pub enum Commands {
#[command(about = "Scaffold devenv.yaml, devenv.nix, .gitignore and .envrc.")]
Init { target: Option<PathBuf> },
Init {
target: Option<PathBuf>,
#[arg(long, help = "Use template")]
template: Option<String>,
},

#[command(about = "Generate devenv.yaml and devenv.nix using AI")]
Generate {
Expand Down
7 changes: 7 additions & 0 deletions devenv/src/cnix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@ impl<'a> Nix<'a> {
Ok(())
}

pub async fn init(&self, template: &String) -> Result<()> {
self.run_nix("nix", &["flake", "init", "-t", &template], &self.options)
.await?;

Ok(())
}

pub async fn metadata(&self) -> Result<String> {
let options = Options {
cache_output: true,
Expand Down
7 changes: 6 additions & 1 deletion devenv/src/devenv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ impl Devenv {
self.devenv_dotfile.join("processes.pid")
}

pub fn init(&self, target: &Option<PathBuf>) -> Result<()> {
pub async fn init(&self, target: &Option<PathBuf>, template: &Option<String>) -> Result<()> {
if let Some(template) = template {
self.nix.init(template).await?;
return Ok(());
}

let target = target
.clone()
.unwrap_or_else(|| fs::canonicalize(".").expect("Failed to get current directory"));
Expand Down
2 changes: 1 addition & 1 deletion devenv/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ async fn main() -> Result<()> {
};
Ok(())
}
Commands::Init { target } => devenv.init(&target),
Commands::Init { target, template } => devenv.init(&target, &template).await,
Commands::Generate {
description,
host,
Expand Down
Loading