-
Notifications
You must be signed in to change notification settings - Fork 3
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
Changes from 32 commits
348dc92
d142870
be88ce3
24ec3df
b4f161c
7ecda5a
f6956df
64280da
a8802fb
cf02c96
31f29f2
8c83346
dbedb17
2f23481
a44b8a4
840f6b0
70f7ca1
4b8d890
3a18aa7
b2771fc
5ba05ca
e43a945
75ad65e
73ce742
5a913ce
ec6474f
995583b
0f1ca84
636e44e
f4e6be2
83e4181
4226e38
d82409d
10ed0bb
64ec29a
bad6c7d
4494d14
bbd6a1f
653c0f6
17a8b98
1bedf44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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... There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(()) | ||
// } | ||
// } |
There was a problem hiding this comment.
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