Skip to content
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
108 changes: 106 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 2 additions & 7 deletions helix-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,8 @@ dotenvy = "0.15.7"
tokio-tungstenite = "0.27.0"
futures-util = "0.3.31"
regex = "1.11.2"

[dev-dependencies]
tempfile = "3.14.0"

[lib]
name = "helix_cli"
path = "src/lib.rs"
handlebars = "6.3.2"
tempfile = "3.23.0"

[[bin]]
name = "helix"
Expand Down
51 changes: 49 additions & 2 deletions helix-cli/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ use crate::CloudDeploymentTypeCommand;
use crate::commands::integrations::ecr::{EcrAuthType, EcrManager};
use crate::commands::integrations::fly::{FlyAuthType, FlyManager, VmSize};
use crate::commands::integrations::helix::HelixManager;
use crate::commands::templates::{TemplateFetcher, TemplateProcessor, TemplateSource};
use crate::config::{CloudConfig, HelixConfig};
use crate::docker::DockerManager;
use crate::errors::project_error;
use crate::project::ProjectContext;
use crate::utils::{print_instructions, print_status, print_success};
use eyre::Result;
use std::collections::HashMap;
use std::env;
use std::fs;
use std::path::Path;

pub async fn run(
path: Option<String>,
_template: String,
template: Option<String>,
queries_path: String,
deployment_type: Option<CloudDeploymentTypeCommand>,
) -> Result<()> {
Expand Down Expand Up @@ -47,6 +49,29 @@ pub async fn run(
// Create project directory if it doesn't exist
fs::create_dir_all(&project_dir)?;

// Process template if provided
if let Some(template_spec) = template {
process_template(&template_spec, &project_dir, project_name)?;

print_success(&format!(
"Helix project successfully initialized from template: `{template_spec}`",
));

print_instructions(
"Next steps:",
&[
&format!(
"1. Explore your project files in `{}`",
project_dir.display()
),
"2. Run `helix build dev` to compile your project",
"3. Run `helix push dev` to start your development instance",
],
);

return Ok(());
}

// Create default helix.toml with custom queries path
let mut config = HelixConfig::default_config(project_name);
config.project.queries = std::path::PathBuf::from(&queries_path);
Expand All @@ -55,7 +80,6 @@ pub async fn run(
create_project_structure(&project_dir, &queries_path)?;

// Initialize deployment type based on flags

match deployment_type {
Some(deployment) => {
match deployment {
Expand Down Expand Up @@ -184,6 +208,29 @@ pub async fn run(
Ok(())
}

fn process_template(
template_str: &str,
project_dir: &Path,
project_name: &str,
) -> eyre::Result<()> {
// Parse template source
let template_source = TemplateSource::parse(template_str)?;

// Prepare template variables for rendering
let mut variables = HashMap::new();
variables.insert("project_name".to_string(), project_name.to_string());

// Fetch raw template from git (with caching)
print_status("TEMPLATE", &format!("Resolving template: {}", template_str));
let raw_template_path = TemplateFetcher::fetch(&template_source)?;

// Render and apply template to project directory.
print_status("TEMPLATE", "Rendering template...");
TemplateProcessor::render_to_dir(&raw_template_path, project_dir, &variables)?;

Ok(())
}

fn create_project_structure(project_dir: &Path, queries_path: &str) -> Result<()> {
// Create directories
fs::create_dir_all(project_dir.join(".helix"))?;
Expand Down
1 change: 1 addition & 0 deletions helix-cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ pub mod push;
pub mod start;
pub mod status;
pub mod stop;
pub mod templates;
pub mod update;
Loading
Loading