Use structopt instead of docopt.

This commit refactors the Wasmtime CLI tools to use `structopt` instead of
`docopt`.

The `wasmtime` tool now has the following subcommands:

* `config new` - creates a new Wasmtime configuration file.
* `run` - runs a WebAssembly module.
* `wasm2obj` - translates a Wasm module to native object file.
* `wast` - runs a test script file.

If no subcommand is specified, the `run` subcommand is used. Thus,
`wasmtime foo.wasm` should continue to function as expected.

The `wasm2obj` and `wast` tools still exist, but delegate to the same
implementation as the `wasmtime` subcommands.  The standalone `wasm2obj` and
`wast` tools may be removed in the future in favor of simply using `wasmtime`.

Included in this commit is a breaking change to the default Wasmtime
configuration file: it has been renamed from `wasmtime-cache-config.toml` to
simply `config.toml`.  The new name is less specific which will allow for
additional (non-cache-related) settings in the future.

There are some breaking changes to improve command line UX:

* The `--cache-config` option has been renamed to `--config`.
* The `--create-config-file` option has moved to the `config new` subcommand.
As a result, the `wasm2obj` and `wast` tools cannot be used to create a new
config file.
* The short form of the `--optimize` option has changed from
`-o` to `-O` for consistency.
* The `wasm2obj` command takes the output object file as a
required positional argument rather than the former required output *option*
(e.g. `wasmtime wasm2obj foo.wasm foo.obj`).
This commit is contained in:
Peter Huene
2019-12-17 15:38:00 -05:00
parent d142a39113
commit 59258730c2
14 changed files with 900 additions and 891 deletions

49
src/commands/config.rs Normal file
View File

@@ -0,0 +1,49 @@
//! The module that implements the `wasmtime config` command.
use anyhow::{anyhow, Result};
use structopt::StructOpt;
use wasmtime_environ::cache_create_new_config;
const CONFIG_NEW_AFTER_HELP: &str =
"If no file path is specified, the system configuration file path will be used.";
/// Controls Wasmtime configuration settings
#[derive(StructOpt)]
#[structopt(name = "run")]
pub enum ConfigCommand {
/// Creates a new Wasmtime configuration file
#[structopt(after_help = CONFIG_NEW_AFTER_HELP)]
New(ConfigNewCommand),
}
impl ConfigCommand {
/// Executes the command.
pub fn execute(&self) -> Result<()> {
match self {
Self::New(c) => c.execute(),
}
}
}
/// Creates a new Wasmtime configuration file
#[derive(StructOpt)]
#[structopt(name = "new", after_help = CONFIG_NEW_AFTER_HELP)]
pub struct ConfigNewCommand {
/// The path of the new configuration file
#[structopt(index = 1, value_name = "FILE_PATH")]
path: Option<String>,
}
impl ConfigNewCommand {
/// Executes the command.
pub fn execute(&self) -> Result<()> {
let path = cache_create_new_config(self.path.as_ref()).map_err(|e| anyhow!(e))?;
println!(
"Successfully created a new configuation file at '{}'.",
path.display()
);
Ok(())
}
}