Skip to content
Closed
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 changes: 1 addition & 1 deletion src/commands/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ pub fn handle(cmd: NewCommands) -> Result<()> {
}

fn search_templates(query: &str) -> Result<()> {
let results = templates::search_templates(query)?;
let results = templates::search_templates(query, None)?;
p::header(&format!("Template search results for '{}'", query));
if results.is_empty() {
p::info("No templates matched that query.");
Expand Down
15 changes: 13 additions & 2 deletions src/commands/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,27 @@ fn list() -> Result<()> {
}

fn search(query: String) -> Result<()> {
let results = templates::search_templates(&query)?;
let results = templates::search_templates(&query, None)?;
p::header(&format!("Template search results for '{}'", query));
if results.is_empty() {
p::info("No templates matched that query.");
return Ok(());
}

p::info(&format!("Found {} result(s), ranked by popularity:", results.len()));
println!();

for (i, template) in results.iter().enumerate() {
println!(" {:>2}. {}@{}", i + 1, template.name, template.version);
let badge = p::verified_badge(template.verified);
println!(
" {:>2}. {}@{}{}",
i + 1,
template.name.cyan().bold(),
template.version,
badge
);
p::kv("Description", &template.description);
p::kv("Downloads", &template.downloads.to_string());
p::kv("Source", &template.source);
if !template.tags.is_empty() {
p::kv("Tags", &template.tags.join(", "));
Expand Down
8 changes: 8 additions & 0 deletions src/utils/print.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,11 @@ pub fn progress_bar(total: u64, msg: &str) -> ProgressBar {
pub fn multi_progress() -> MultiProgress {
MultiProgress::new()
}

pub fn verified_badge(verified: bool) -> colored::ColoredString {
if verified {
" ✓ verified".green()
} else {
"".normal()
}
}
8 changes: 5 additions & 3 deletions src/utils/templates.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ use serde::{Deserialize, Serialize};
use std::fs;
use std::path::{Path, PathBuf};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TemplateRegistry {
pub version: String,
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct TemplateRegistry {
#[serde(default)]
Expand All @@ -17,11 +14,16 @@ pub struct TemplateEntry {
pub name: String,
pub description: String,
pub version: String,
pub author: String,
pub source: String,
#[serde(default)]
pub tags: Vec<String>,
#[serde(default)]
pub path: Option<String>,
#[serde(default)]
pub downloads: u64,
#[serde(default)]
pub verified: bool,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down
12 changes: 6 additions & 6 deletions templates/registry.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
},
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z",
"downloads": 0,
"downloads": 1240,
"verified": true
},
{
Expand All @@ -30,7 +30,7 @@
},
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z",
"downloads": 0,
"downloads": 874,
"verified": true
},
{
Expand All @@ -46,8 +46,8 @@
},
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z",
"downloads": 0,
"verified": true
"downloads": 512,
"verified": false
},
{
"name": "multisig-wallet",
Expand All @@ -62,8 +62,8 @@
},
"created_at": "2025-01-01T00:00:00Z",
"updated_at": "2025-01-01T00:00:00Z",
"downloads": 0,
"verified": true
"downloads": 389,
"verified": false
}
]
}