-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a `bindings` subcommand, which just generates the bindings.rs file. And make the `new` subcommand auto-generate the bindings.rs file too, so that the tree is fully set up after a `new`. Fixes #362.
- Loading branch information
1 parent
7749434
commit 130438f
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
//! Commands for the `cargo-component` CLI. | ||
mod add; | ||
mod bindings; | ||
mod new; | ||
mod publish; | ||
mod update; | ||
|
||
pub use self::add::*; | ||
pub use self::bindings::*; | ||
pub use self::new::*; | ||
pub use self::publish::*; | ||
pub use self::update::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use anyhow::Result; | ||
use cargo_component_core::command::CommonOptions; | ||
use clap::Args; | ||
|
||
use crate::{ | ||
config::Config, generate_bindings, load_component_metadata, load_metadata, CargoArguments, | ||
}; | ||
|
||
/// Just update the generated bindings. | ||
/// | ||
/// The generated bindings are generated automatically by subcommands like | ||
/// `cargo component build`; `cargo component bindings` is for when one wishes | ||
/// to just generate the bindings without doing any other work. | ||
#[derive(Args)] | ||
#[clap(disable_version_flag = true)] | ||
pub struct BindingsCommand { | ||
/// The common command options. | ||
#[clap(flatten)] | ||
pub common: CommonOptions, | ||
} | ||
|
||
impl BindingsCommand { | ||
/// Executes the command. | ||
pub async fn exec(self) -> Result<()> { | ||
log::debug!("generating bindings"); | ||
|
||
let config = Config::new(self.common.new_terminal(), self.common.config.clone()).await?; | ||
|
||
let client = config.client(self.common.cache_dir.clone(), false).await?; | ||
|
||
let cargo_args = CargoArguments::parse()?; | ||
let metadata = load_metadata(None)?; | ||
let packages = | ||
load_component_metadata(&metadata, cargo_args.packages.iter(), cargo_args.workspace)?; | ||
let _import_name_map = | ||
generate_bindings(client, &config, &metadata, &packages, &cargo_args).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters