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 all 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 @@ -16,7 +16,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
2 changes: 2 additions & 0 deletions ion_derive/src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ pub fn emit_template(ast: &DeriveInput) -> TokenStream {
#validate
Ok(())
}

}

};
gen.into()
}
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
1 change: 0 additions & 1 deletion src/ion/blueprints/components/documenter.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/ion/blueprints/components/license.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/ion/blueprints/components/project_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
1 change: 1 addition & 0 deletions src/ion/blueprints/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
66 changes: 45 additions & 21 deletions src/ion/blueprints/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -136,21 +136,31 @@ 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}");
}
}
}
}

// 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 {
Expand All @@ -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::<Template>(&source) {
Ok(t) => t,
Err(e) => {
return Err(format_err!("Error parsing template: {}", e));
}
};

selection_options.push(template.name);
}
}

// Ask for template to print to console
let template_name = Select::with_theme(&ColorfulTheme::default())
.items(&selection_options)
.default(1)
.interact_opt()?;

if let Some(template_name) = template_name {
inspect_template(
config,
selection_options[template_name].to_owned(),
verbose_flag,
)?
};

Ok(())
}

pub fn ask_inspect_template(config: &Config) -> Result<()> {
// Get selection options from installed templates
let mut selection_options = vec![];

pub fn inspect_all_templates(config: &Config, verbose_flag: bool) -> Result<()> {
let templates = config.template_dir().read_dir()?;

for entry in templates {
let entry = match entry {
Ok(e) => e,
Expand All @@ -195,20 +225,14 @@ pub fn ask_inspect_template(config: &Config) -> Result<()> {
}
};

selection_options.push(template.name);
if verbose_flag {
println!("\n{:#?}\n**********", template);
} else {
println!("\n{source}\n**********");
}
}
}

// Ask for template to print to console
let template_name = Select::with_theme(&ColorfulTheme::default())
.items(&selection_options)
.default(1)
.interact_opt()?;

if let Some(template_name) = template_name {
inspect_template(config, selection_options[template_name].to_owned())?
};

Ok(())
}

Expand Down
53 changes: 52 additions & 1 deletion tests/bin/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,64 @@ fn test_ctrl_c() -> Result<()> {
Ok(())
}

#[test]
fn test_verbose() -> Result<()> {
// Test --verbose flag
let mut p = Ion::new()
.arg("template")
.arg("inspect")
.arg("--verbose")
.arg("package")
.spawn(Some(5_000))?;

p.exp_string("template")?;
p.exp_eof()?;

Ok(())
}

#[test]
fn test_verbose_all() -> Result<()> {
// Test --verbose --all flags together
let mut p = Ion::new()
.arg("template")
.arg("inspect")
.arg("--verbose")
.arg("--all")
.spawn(Some(5_000))?;

p.exp_string("template")?;
p.exp_string("template")?;
p.exp_string("template")?;
p.exp_eof()?;

Ok(())
}

#[test]
fn test_verbose_user_input() -> Result<()> {
// Test --verbose flag, ask for user selection
let mut p = Ion::new()
.arg("template")
.arg("inspect")
.arg("--verbose")
.spawn(Some(10_000))?;

// Send <ENTER> keycode
p.send_control('j')?;
p.exp_string("template")?;
p.exp_eof()?;

Ok(())
}

#[test]
fn test_nonce() -> Result<()> {
let mut p = Ion::new()
.arg("template")
.arg("inspect")
.arg("nonce")
.spawn(Some(5_000))?;
.spawn(Some(15_000))?;

p.send_control('j')?; // skip download if there is
p.exp_string("Installed templates are:")?;
Expand Down