Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: implement --verbose flag on ion template inspect cmd #21

Merged
merged 41 commits into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
348dc92
feat: add ion template inspect cmd
diversable Feb 15, 2023
d142870
bump patch release
diversable Feb 15, 2023
be88ce3
fix: ion template inspect; add more tests
diversable Feb 15, 2023
24ec3df
update tests
diversable Feb 15, 2023
b4f161c
fix: inspect template implementation
diversable Feb 15, 2023
7ecda5a
reverse bump version
diversable Feb 15, 2023
f6956df
Merge branch 'Roger-luo:main' into main
diversable Feb 15, 2023
64280da
test: update template tests
diversable Feb 16, 2023
a8802fb
Merge branch 'Roger-luo:main' into main
diversable Feb 16, 2023
cf02c96
Fix test: template
diversable Feb 16, 2023
31f29f2
Merge branch 'Roger-luo:main' into main
diversable Feb 17, 2023
8c83346
feat: add --verbose flag to `ion template inspect`
diversable Feb 18, 2023
dbedb17
fix: refactor
diversable Feb 18, 2023
2f23481
Merge branch 'Roger-luo:main' into main
diversable Feb 18, 2023
a44b8a4
fix: update tmpl inspect -v --all combination
diversable Feb 18, 2023
840f6b0
Merge branch 'main' into template
diversable Feb 18, 2023
70f7ca1
fix: tests
diversable Feb 18, 2023
4b8d890
Fix: tests
diversable Feb 18, 2023
3a18aa7
Merge branch 'template' of https://github.com/diversable/Ion into tem…
diversable Feb 18, 2023
b2771fc
fix: clippy
diversable Feb 18, 2023
5ba05ca
fix: fmt
diversable Feb 18, 2023
e43a945
Update grcov.yml
diversable Feb 18, 2023
75ad65e
update readme: add link to template repo
diversable Feb 18, 2023
73ce742
Update grcov.yml
diversable Feb 18, 2023
5a913ce
Update grcov.yml
diversable Feb 18, 2023
ec6474f
update
diversable Feb 20, 2023
995583b
Merge branch 'main'
diversable Feb 20, 2023
0f1ca84
Merge branch 'main' into template
diversable Feb 20, 2023
636e44e
fix: tests
diversable Feb 20, 2023
f4e6be2
fmt
diversable Feb 20, 2023
83e4181
Merge branch 'main' into template
diversable Feb 20, 2023
4226e38
ion requested updates
diversable Feb 20, 2023
d82409d
template macro minor update..
diversable Feb 20, 2023
10ed0bb
Merge branch 'Roger-luo:main' into template
diversable Feb 20, 2023
64ec29a
Merge branch 'Roger-luo:main' into template
diversable Feb 21, 2023
bad6c7d
request: update to debug printing
diversable Feb 22, 2023
4494d14
rm comment
diversable Feb 22, 2023
bbd6a1f
remove dependence on impl Display
diversable Feb 22, 2023
653c0f6
remove impl Display stubs
diversable Feb 22, 2023
17a8b98
finish removing display
diversable Feb 22, 2023
1bedf44
cleanup
diversable Feb 22, 2023
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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Download tarball in the release page and extract it to your `$HOME/.julia` direc

### build from source
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'd be nice if this can be in a separate PR, I probably will put up the website soon, so we can decide whether to have this in a different PR


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
Expand Down
242 changes: 200 additions & 42 deletions ion_derive/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,61 +17,219 @@ pub fn emit_template(ast: &DeriveInput) -> TokenStream {
let context_expr = emit_context();

let gen = quote! {
use log::debug;
use anyhow::Result;
use crate::config::Config;

#context_expr

impl #name {
pub fn from_name(config: &Config, name: &String) -> Result<Self> {
let mut template = config.template_dir();
template.push(name);
template.push("template.toml");

assert!(template.is_file(), "Template file not found: {}", template.display());
let source = std::fs::read_to_string(template)?;
let template : Template = toml::from_str(&source)?;
Ok(template)
}
use log::debug;
use anyhow::Result;
use crate::config::Config;

#context_expr

impl #name {
pub fn from_name(config: &Config, name: &String) -> Result<Self> {
let mut template = config.template_dir();
template.push(name);
template.push("template.toml");

assert!(template.is_file(), "Template file not found: {}", template.display());
let source = std::fs::read_to_string(template)?;
let template : Template = toml::from_str(&source)?;
Ok(template)
}

pub fn render(&self, config: &Config, ctx: &mut Context) -> Result<()> {
let old_pwd = std::env::current_dir()?;
std::env::set_current_dir(&*ctx.project.path)?;

self.collect(config, ctx)?;
debug!("Context: {:#?}", ctx);
if ctx.prompt {
self.prompt(config, ctx)?;
}
#render
self.post_render(config, ctx)?;
self.validate(config, ctx)?;

std::env::set_current_dir(old_pwd)?;
Ok(())
}

pub fn collect(&self, config: &Config, ctx: &mut Context) -> Result<()> {
#collect
Ok(())
}

pub fn render(&self, config: &Config, ctx: &mut Context) -> Result<()> {
let old_pwd = std::env::current_dir()?;
std::env::set_current_dir(&*ctx.project.path)?;
pub fn prompt(&self, config: &Config, ctx: &mut Context) -> Result<()> {
#prompt
Ok(())
}

pub fn post_render(&self, config: &Config, ctx: &Context) -> Result<()> {
#post_render
Ok(())
}

self.collect(config, ctx)?;
debug!("Context: {:#?}", ctx);
if ctx.prompt {
self.prompt(config, ctx)?;
pub fn validate(&self, config: &Config, ctx: &Context) -> Result<()> {
#validate
Ok(())
}
#render
self.post_render(config, ctx)?;
self.validate(config, ctx)?;

std::env::set_current_dir(old_pwd)?;
Ok(())
}

pub fn collect(&self, config: &Config, ctx: &mut Context) -> Result<()> {
#collect
Ok(())

impl fmt::Display for Template {
fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
write!(
format_buffer,
"Name:\n{}\n\nDescription:\n{}\n\n",
self.name, self.description
)?;

if let Some(repo) = &self.repo {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to generate the names instead of manually writing them, like how I generate other methods

Copy link
Contributor Author

@diversable diversable Feb 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one might take a little while -- I have zero experience writing Rust macros (I know how to use them, just not how to write them).

But I'm reading up on it. The resources are a little thin, but I'll get it eventually...

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, perhaps we should just do the debug printing, so that you don't need to implement this now

write!(format_buffer, "Repo:\n{}\n", repo)?;
} else {
write!(format_buffer, "Repo:\nNone\n\n")?;
}

if let Some(project_file) = &self.project_file {
write!(format_buffer, "Project File:\n{}\n", project_file)?;
} else {
write!(format_buffer, "Project File:\nNone\n\n")?;
}

if let Some(readme) = &self.readme {
write!(format_buffer, "Readme:\n{}\n", readme)?;
} else {
write!(format_buffer, "Readme:\nNone\n\n")?;
}

if let Some(src_dir) = &self.src_dir {
write!(format_buffer, "Source Directory:\n{}\n", src_dir)?;
} else {
write!(format_buffer, "Source Directory:\nNone\n\n")?;
}

pub fn prompt(&self, config: &Config, ctx: &mut Context) -> Result<()> {
#prompt
Ok(())
if let Some(tests) = &self.tests {
write!(format_buffer, "Tests:\n{}\n", tests)?;
} else {
write!(format_buffer, "Tests:\nNone\n\n")?;
}

pub fn post_render(&self, config: &Config, ctx: &Context) -> Result<()> {
#post_render
Ok(())
if let Some(license_dir) = &self.license {
write!(format_buffer, "License Template:\n{}\n", license_dir)?;
} else {
write!(format_buffer, "License Template:\nNone\n\n")?;
}

pub fn validate(&self, config: &Config, ctx: &Context) -> Result<()> {
#validate
Ok(())
if let Some(citation) = &self.citation {
write!(format_buffer, "Citation:\n{}\n", citation)?;
} else {
write!(format_buffer, "Citation:\nNone\n\n")?;
}

if let Some(documenter) = &self.documenter {
write!(format_buffer, "Documenter:\n{}\n", documenter)?;
} else {
write!(format_buffer, "Documenter:\nNone\n\n")?;
}

if let Some(codecov) = &self.codecov {
write!(format_buffer, "CodeCov:\n{}\n", codecov)?;
} else {
write!(format_buffer, "CodeCov:\nNone\n\n")?;
}

if let Some(coveralls) = &self.coveralls {
write!(format_buffer, "Coveralls:\n{}\n", coveralls)?;
} else {
write!(format_buffer, "Coveralls:\nNone\n\n")?;
}
if let Some(github) = &self.github {
write!(format_buffer, "Github:\n{}\n", github)?;
} else {
write!(format_buffer, "Github:\nNone\n")?;
}

Ok(())
}
};
}


};
gen.into()
}

// impl fmt::Display for Template {
// fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
// write!(
// format_buffer,
// "Name:\n{}\n\nDescription:\n{}\n\n",
// self.name, self.description
// )?;

// if let Some(repo) = &self.repo {
// write!(format_buffer, "Repo:\n{repo}\n")?;
// } else {
// write!(format_buffer, "Repo:\nNone\n\n")?;
// }

// if let Some(project_file) = &self.project_file {
// write!(format_buffer, "Project File:\n{project_file}\n")?;
// } else {
// write!(format_buffer, "Project File:\nNone\n\n")?;
// }

// if let Some(readme) = &self.readme {
// write!(format_buffer, "Readme:\n{readme}\n")?;
// } else {
// write!(format_buffer, "Readme:\nNone\n\n")?;
// }

// if let Some(src_dir) = &self.src_dir {
// write!(format_buffer, "Source Directory:\n{src_dir}\n")?;
// } else {
// write!(format_buffer, "Source Directory:\nNone\n\n")?;
// }

// if let Some(tests) = &self.tests {
// write!(format_buffer, "Tests:\n{tests}\n")?;
// } else {
// write!(format_buffer, "Tests:\nNone\n\n")?;
// }

// if let Some(license_dir) = &self.license {
// write!(format_buffer, "License Template:\n{license_dir}\n")?;
// } else {
// write!(format_buffer, "License Template:\nNone\n\n")?;
// }

// if let Some(citation) = &self.citation {
// write!(format_buffer, "Citation:\n{citation}\n")?;
// } else {
// write!(format_buffer, "Citation:\nNone\n\n")?;
// }

// if let Some(documenter) = &self.documenter {
// write!(format_buffer, "Documenter:\n{documenter}\n")?;
// } else {
// write!(format_buffer, "Documenter:\nNone\n\n")?;
// }

// if let Some(codecov) = &self.codecov {
// write!(format_buffer, "CodeCov:\n{codecov}\n")?;
// } else {
// write!(format_buffer, "CodeCov:\nNone\n\n")?;
// }

// if let Some(coveralls) = &self.coveralls {
// write!(format_buffer, "Coveralls:\n{coveralls}\n")?;
// } else {
// write!(format_buffer, "Coveralls:\nNone\n\n")?;
// }
// if let Some(github) = &self.github {
// write!(format_buffer, "Github:\n{github}\n")?;
// } else {
// write!(format_buffer, "Github:\nNone\n")?;
// }

// Ok(())
// }
// }
17 changes: 11 additions & 6 deletions src/bin/ion/commands/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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::<String>("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)?;
}
}
};
Expand Down
12 changes: 12 additions & 0 deletions src/ion/blueprints/components/citation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use crate::{blueprints::*, config::Config};
use chrono::Datelike;
use dialoguer::{Confirm, Input};
use serde_derive::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Serialize, Clone)]
pub struct Info {
Expand Down Expand Up @@ -116,3 +117,14 @@ impl Blueprint for Citation {
.render(ctx, "CITATION.cff")
}
}

impl fmt::Display for Citation {
fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
write!(
format_buffer,
"Template: {}\nReadme: {}\n",
self.template, self.readme
)?;
Ok(())
}
}
12 changes: 12 additions & 0 deletions src/ion/blueprints/components/codecov.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::blueprints::*;
use serde_derive::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Serialize, Clone)]
pub struct Info;
Expand All @@ -18,3 +19,14 @@ impl Blueprint for Codecov {
Ok(())
}
}

impl fmt::Display for Codecov {
fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
if let Some(template) = &self.template {
writeln!(format_buffer, "CodeCov template: {template}")?;
} else {
writeln!(format_buffer, "CodeCov template: None")?;
}
Ok(())
}
}
12 changes: 12 additions & 0 deletions src/ion/blueprints/components/coveralls.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::blueprints::*;
use serde_derive::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Serialize, Clone)]
pub struct Info;
Expand All @@ -20,3 +21,14 @@ impl Blueprint for Coveralls {
Ok(())
}
}

impl fmt::Display for Coveralls {
fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
if let Some(template) = &self.template {
writeln!(format_buffer, "Coveralls template: {template}")?;
} else {
writeln!(format_buffer, "Coveralls template: None")?;
}
Ok(())
}
}
13 changes: 12 additions & 1 deletion src/ion/blueprints/components/documenter.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use crate::blueprints::*;
use crate::utils::*;
use crate::PackageSpec;
use anyhow::Ok;
use serde_derive::{Deserialize, Serialize};
use std::fmt;

#[derive(Debug, Serialize, Clone)]
pub struct Info;
Expand Down Expand Up @@ -77,3 +77,14 @@ impl Badgeable for Documenter {
}
}
}

impl fmt::Display for Documenter {
fn fmt(&self, format_buffer: &mut fmt::Formatter) -> fmt::Result {
write!(
format_buffer,
"Make.jl template: {}\nIndex.md template: {}\nDoc project template: {}\nIgnore files: {:#?}\n",
self.make_jl, self.index_md, self.doc_project, self.ignore
)?;
Ok(())
}
}
Loading