Skip to content
Merged
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
2,163 changes: 2,118 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ console = "0.15"
dirs = "6"
rhai = { version = "1", features = ["sync"] }
tempfile = "3"
gix = { version = "0.72", default-features = false, features = ["blocking-network-client", "blocking-http-transport-reqwest-rust-tls", "worktree-mutation"] }
sha2 = "0.10"
5 changes: 3 additions & 2 deletions crates/diecut-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ inquire = { workspace = true }
indicatif = { workspace = true }
console = { workspace = true }
rhai = { workspace = true }

[dev-dependencies]
dirs = { workspace = true }
gix = { workspace = true }
tempfile = { workspace = true }
sha2 = { workspace = true }
22 changes: 17 additions & 5 deletions crates/diecut-core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub enum DicecutError {
source: toml::de::Error,
},

#[error("Invalid variable definition for '{name}'")]
#[error("Invalid variable definition for '{name}': {reason}")]
ConfigInvalidVariable { name: String, reason: String },

#[error("Validation failed for variable '{name}': {message}")]
Expand Down Expand Up @@ -96,10 +96,6 @@ pub enum DicecutError {
))]
UnsupportedFormat { path: PathBuf },

#[error("Git source not yet implemented: {url}")]
#[diagnostic(help("Git template sources will be available in a future release"))]
GitNotImplemented { url: String },

#[error("Invalid template abbreviation: {input}")]
#[diagnostic(help(
"Supported abbreviations: gh:user/repo, gl:user/repo, bb:user/repo, sr:~user/repo"
Expand All @@ -109,6 +105,22 @@ pub enum DicecutError {
#[error("Hook '{hook}' failed: {message}")]
#[diagnostic(help("Check the Rhai script for errors"))]
HookError { hook: String, message: String },

#[error("Cache metadata error: {context}")]
#[diagnostic(help("Try clearing the cache with `diecut cache clear`"))]
CacheMetadata { context: String },

#[error("Unsafe URL scheme in '{url}': {reason}")]
#[diagnostic(help("Use https:// URLs for remote templates"))]
UnsafeUrl { url: String, reason: String },

#[error("Git clone failed for {url}")]
#[diagnostic(help("Check the URL and your network connection"))]
GitClone { url: String, reason: String },

#[error("Git checkout failed for ref '{git_ref}'")]
#[diagnostic(help("Ensure the branch, tag, or commit exists in the repository"))]
GitCheckout { git_ref: String, reason: String },
}

pub type Result<T> = std::result::Result<T, DicecutError>;
6 changes: 3 additions & 3 deletions crates/diecut-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::adapter::resolve_template;
use crate::error::{DicecutError, Result};
use crate::prompt::{collect_variables, PromptOptions};
use crate::render::{build_context_with_namespace, walk_and_render, GeneratedProject};
use crate::template::{resolve_source, TemplateSource};
use crate::template::{get_or_clone, resolve_source, TemplateSource};

/// Options for the `generate` operation.
pub struct GenerateOptions {
Expand All @@ -38,8 +38,8 @@ pub fn generate(options: GenerateOptions) -> Result<GeneratedProject> {
let source = resolve_source(&options.template)?;
let template_dir = match &source {
TemplateSource::Local(path) => path.clone(),
TemplateSource::Git { url, .. } => {
return Err(DicecutError::GitNotImplemented { url: url.clone() });
TemplateSource::Git { url, git_ref } => {
get_or_clone(url, git_ref.as_deref())?
}
};

Expand Down
Loading
Loading