wash_cli/cmd/wit/
mod.rs

1use clap::Subcommand;
2use wash_lib::cli::CommandOutput;
3
4mod build;
5mod deps;
6mod publish;
7
8/// Commands for interacting with wit (`wash wit`)
9///
10/// These commands mirror the `wkg wit` subcommand, but are adapted for use with `wash`
11#[derive(Debug, Subcommand, Clone)]
12pub enum WitCommand {
13    /// Build a WIT package from a directory.
14    /// By default, this will fetch all dependencies needed and encode them
15    /// in the WIT package. This will generate a lock file that can be used to fetch
16    /// the dependencies in the future.
17    Build(build::BuildArgs),
18
19    /// Fetch dependencies for a component.
20    ///
21    /// This will read the package containing the world(s) you have defined in the
22    /// given wit directory (`wit` by default). It will then fetch the
23    /// dependencies and write them to the `deps` directory along with a lock file. If no lock file
24    /// exists, it will fetch all dependencies. If a lock file exists, it will fetch any
25    /// dependencies that are not in the lock file and update the lock file.
26    #[clap(alias = "fetch")]
27    Deps(deps::DepsArgs),
28
29    /// Publish a WIT package to a registry.
30    /// This will automatically infer the package name from the WIT package.
31    Publish(publish::PublishArgs),
32}
33
34/// Handle the `wash wit` subcommand
35pub async fn handle_command(cmd: WitCommand) -> anyhow::Result<CommandOutput> {
36    match cmd {
37        WitCommand::Build(args) => build::invoke(args).await,
38        WitCommand::Deps(args) => deps::invoke(args).await,
39        WitCommand::Publish(args) => publish::invoke(args).await,
40    }
41}