bytecodealliance / wasmtime

A fast and secure runtime for WebAssembly
https://wasmtime.dev/
Apache License 2.0
15.3k stars 1.29k forks source link

Wasmtime Settings Machine Readable Output #5404

Open martindevans opened 1 year ago

martindevans commented 1 year ago

Feature

currently running wasmtime settings displays a human readable output. I propose adding a switch --machine_readable which changes the output to something more convenient to parse (e.g. JSON).

Benefit

If wasmtime is being used by other processes (e.g. our usecase has the Unity editor invoking wasmtime to precompile wasm) a machine readable output would be much more convenient to work with.

Implementation

Add this:

/// Switch output format to machine readable
#[clap(long)]
machine_readable: bool,

into the SettingsCommand struct. Modify SettingsCommand.execute to use a different display system if true.

I'm willing to open a PR for this, if it's a feature that would be accepted.

alexcrichton commented 1 year ago

Seems reasonable to me to add! I might recommend a --json argument to explicitly specify the format but otherwise the idea seems fine to add through a PR.

martindevans commented 1 year ago

Thanks. I'll try to submit a PR for a --json flag this weekend 👍

martindevans commented 1 year ago

Is serde available to use within this crate, or can it be added? I'm not sure what the process is for managing dependencies in wasmtime.

If that's not feasible I can just emit the JSON by hand, it's not a very complicated dataset!

alexcrichton commented 1 year ago

Yep we've got a lot of usage of serde already, so it can be added.