diff --git a/README.md b/README.md index e0a30e2..3a5f45c 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Download tarball in the release page and extract it to your `$HOME/.julia` direc ### build from source -Using [`just`](https://github.com/casey/just): +Using [`just`](https://github.com/casey/just) and [Rust's cargo/rustc compiler](https://rustup.rs/): ```bash just install diff --git a/ion_derive/src/template.rs b/ion_derive/src/template.rs index 9eecaee..8e9c40b 100644 --- a/ion_derive/src/template.rs +++ b/ion_derive/src/template.rs @@ -71,7 +71,9 @@ pub fn emit_template(ast: &DeriveInput) -> TokenStream { #validate Ok(()) } + } + }; gen.into() } diff --git a/src/bin/ion/commands/template.rs b/src/bin/ion/commands/template.rs index 36ec194..dd57b17 100644 --- a/src/bin/ion/commands/template.rs +++ b/src/bin/ion/commands/template.rs @@ -16,7 +16,8 @@ pub fn cli() -> Command { Command::new("inspect") .about("inspect the contents of a template") .arg(arg!([TEMPLATE] "Selects which template to print out")) - .arg(arg!(--"all" "Inspect all installed templates")), + .arg(arg!(--"all" "Inspect all installed templates")) + .arg(arg!(verbose: -v --verbose "Inspect details of the template output")), ) .arg_required_else_help(true) } @@ -43,17 +44,21 @@ pub fn exec(config: &mut Config, matches: &ArgMatches) -> CliResult { RemoteTemplate::new(config).download()?; } Some(("inspect", matches)) => { + let all_flag = matches.get_flag("all"); + let verbose_flag = matches.get_flag("verbose"); + download_templates(config)?; - // Iff a template name is provided, inspect template; otherwise, check for --all flag; if no --all, ask user to select template from list + // Iff a template name is provided, inspect template; otherwise, check for --all flag; if no --all, ask user to select template from list match matches.get_one::("TEMPLATE") { - Some(template) => inspect_template(config, template.to_owned())?, + Some(template) => { + inspect_template(config, template.to_owned(), verbose_flag)?; + } None => { - let all_flag = matches.get_flag("all"); if all_flag { - inspect_all_templates(config)?; + inspect_all_templates(config, verbose_flag)?; } else { - ask_inspect_template(config)?; + ask_inspect_template(config, verbose_flag)?; } } }; diff --git a/src/ion/blueprints/components/documenter.rs b/src/ion/blueprints/components/documenter.rs index 08e475e..06c69ab 100644 --- a/src/ion/blueprints/components/documenter.rs +++ b/src/ion/blueprints/components/documenter.rs @@ -1,7 +1,6 @@ use crate::blueprints::*; use crate::utils::*; use crate::PackageSpec; -use anyhow::Ok; use serde_derive::{Deserialize, Serialize}; #[derive(Debug, Serialize, Clone)] diff --git a/src/ion/blueprints/components/license.rs b/src/ion/blueprints/components/license.rs index 7276123..c1bff7a 100644 --- a/src/ion/blueprints/components/license.rs +++ b/src/ion/blueprints/components/license.rs @@ -2,6 +2,7 @@ use crate::blueprints::*; use chrono::Datelike; use dialoguer::Input; use serde_derive::{Deserialize, Serialize}; + use std::path::PathBuf; #[derive(Debug, Serialize, Clone)] diff --git a/src/ion/blueprints/components/project_file.rs b/src/ion/blueprints/components/project_file.rs index dc5b054..abd29f1 100644 --- a/src/ion/blueprints/components/project_file.rs +++ b/src/ion/blueprints/components/project_file.rs @@ -4,6 +4,7 @@ use dialoguer::Confirm; use julia_semver::Version; use log::debug; use serde_derive::{Deserialize, Serialize}; + use uuid::Uuid; #[derive(Debug, Serialize, Clone)] diff --git a/src/ion/blueprints/template.rs b/src/ion/blueprints/template.rs index b9ce891..4d69f7f 100644 --- a/src/ion/blueprints/template.rs +++ b/src/ion/blueprints/template.rs @@ -2,6 +2,7 @@ use super::badge::Badge; use super::components::*; use super::Blueprint; use super::{Julia, Project}; + use ion_derive::Template; use serde_derive::Deserialize; diff --git a/src/ion/blueprints/utils.rs b/src/ion/blueprints/utils.rs index 95062a6..c04cd7f 100644 --- a/src/ion/blueprints/utils.rs +++ b/src/ion/blueprints/utils.rs @@ -112,7 +112,7 @@ pub fn list_templates(config: &Config) -> Result<()> { Ok(()) } -pub fn inspect_template(config: &Config, template_name: String) -> Result<()> { +pub fn inspect_template(config: &Config, template_name: String, verbose_flag: bool) -> Result<()> { let templates = config.template_dir().read_dir()?; let mut template_found: bool = false; @@ -136,8 +136,14 @@ pub fn inspect_template(config: &Config, template_name: String) -> Result<()> { } }; if template.name == template_name { - template_found = true; - println!("{source}"); + // If there's no verbose flag (default), print the source, otherwise, display the full template details (verbose true) + if verbose_flag { + template_found = true; + println!("{:#?}", template); + } else { + template_found = true; + println!("{source}"); + } } } } @@ -145,12 +151,16 @@ pub fn inspect_template(config: &Config, template_name: String) -> Result<()> { // If the template the user requested is not in the list of downloaded templates, ask user to select existing template to inspect if !template_found { println!("The {template_name} template was not found.\nInstalled templates are:"); - ask_inspect_template(config)? + + ask_inspect_template(config, verbose_flag)? } Ok(()) } -pub fn inspect_all_templates(config: &Config) -> Result<()> { +pub fn ask_inspect_template(config: &Config, verbose_flag: bool) -> Result<()> { + // Get selection options from installed templates + let mut selection_options = vec![]; + let templates = config.template_dir().read_dir()?; for entry in templates { @@ -165,17 +175,37 @@ pub fn inspect_all_templates(config: &Config) -> Result<()> { if path.is_dir() { let source = std::fs::read_to_string(path.join("template.toml"))?; - println!("\n{source}\n**********"); + let template = match toml::from_str::