summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2025-07-20 14:26:40 -0700
committerJesse Morgan <jesse@jesterpm.net>2025-07-20 14:26:40 -0700
commitf3a03a49795c54bd2626d5a8d4f6e31db7f8db22 (patch)
treef0977e55bfb919f700f532d4c5165da20558a687
parente9efd5189a09a954ccb11e41c821b628f3e439b2 (diff)
Add get-template commandHEADmaster
-rw-r--r--src/lib.rs4
-rw-r--r--src/main.rs20
2 files changed, 24 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 441a1c5..9ff0b0a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -213,6 +213,10 @@ impl MP32RSS {
self.index.templates.values()
}
+ pub fn get_template(&self, name: &str) -> Option<&Template> {
+ self.index.templates.get(name)
+ }
+
/// Add a new template and rerender.
pub async fn add_template(
&mut self,
diff --git a/src/main.rs b/src/main.rs
index 5c56c93..f94e8d6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -39,6 +39,9 @@ enum Command {
/// Add or replace a template and regenerate the feed.
AddTemplate(AddTemplateArgs),
+ /// Download a template
+ GetTemplate(GetTemplateArgs),
+
/// Remove a template and the files generated from it.
RemoveTemplate {
/// The template name.
@@ -90,6 +93,13 @@ struct AddTemplateArgs {
name: String,
}
+#[derive(clap::Args, Debug)]
+struct GetTemplateArgs {
+ /// The rendered filename.
+ name: String,
+}
+
+
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
env_logger::Builder::from_env(Env::default().default_filter_or("info")).init();
@@ -108,6 +118,7 @@ async fn main() -> Result<(), Box<dyn Error>> {
Command::Delete { filename } => feed.delete(&filename).await,
Command::Templates => list_templates(&feed),
Command::AddTemplate(add_template_args) => add_template(&mut feed, add_template_args).await,
+ Command::GetTemplate(get_template_args) => get_template(&mut feed, get_template_args).await,
Command::RemoveTemplate { name } => feed.delete_template(&name).await,
}
}
@@ -172,3 +183,12 @@ async fn add_template(feed: &mut MP32RSS, args: AddTemplateArgs) -> Result<(), B
)
.await
}
+
+async fn get_template(feed: &mut MP32RSS, args: GetTemplateArgs) -> Result<(), Box<dyn Error>> {
+ if let Some(template) = feed.get_template(&args.name) {
+ println!("{}", template.template);
+ } else {
+ eprintln!("Could not find {}", args.name);
+ }
+ Ok(())
+}