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

Add verbose mode to wasmi cli #957

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
9 changes: 9 additions & 0 deletions crates/cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ pub struct Args {
/// Arguments given to the Wasm module or the invoked function.
#[clap(value_name = "ARGS")]
func_args: Vec<String>,

/// Enable informational messages beyond warnings or errors.
#[clap(long = "verbose")]
verbose: bool,
Copy link
Member

Choose a reason for hiding this comment

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

I am not 100% sure but I think it is important that the func_args field comes last since it takes a variable number of arguments. So please move the verbose field before it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds fine. Change made.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, if you'd prefer restricting the remaining fuel message to verbose mode already, let me know, and I can do that, too.

}

/// The chosen Wasmi compilation mode.
Expand Down Expand Up @@ -142,6 +146,11 @@ impl Args {
self.compilation_mode.into()
}

/// Returns `true` if verbose messaging is enabled.
pub fn verbose(&self) -> bool {
self.verbose
}

/// Pre-opens all directories given in `--dir` and returns them for use by the [`WasiCtx`].
///
/// # Errors
Expand Down
4 changes: 3 additions & 1 deletion crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ fn main() -> Result<()> {
let mut func_results = utils::prepare_func_results(&ty);
typecheck_args(&func_name, &ty, &func_args)?;

print_execution_start(args.wasm_file(), &func_name, &func_args);
if args.verbose() {
print_execution_start(args.wasm_file(), &func_name, &func_args);
}
if args.invoked().is_some() && ty.params().len() != args.func_args().len() {
bail!(
"invalid amount of arguments given to function {}. expected {} but received {}",
Expand Down
9 changes: 9 additions & 0 deletions crates/cli/tests/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ where
fn test_proc_exit() {
let mut cmd = get_cmd();
let assert = cmd.arg(get_bin_path("proc_exit")).assert();
assert!(assert.get_output().stdout.is_empty());
assert.failure().code(1);
}

#[test]
fn test_verbose() {
let mut cmd = get_cmd();
let assert = cmd.arg(get_bin_path("proc_exit")).arg("--verbose").assert();
let stdout = &assert.get_output().stdout;
assert!(contains_slice(stdout, b"proc_exit.wat\")::()"));
Robbepop marked this conversation as resolved.
Show resolved Hide resolved
}

/// UTILS

/// gets the path to a wasm binary given it's name
Expand Down
Loading