diff --git a/src/cmd/build.rs b/src/cmd/build.rs index 7848b30131e8351deb416eb15c7672887b3c5173..4fa2011b6abad37714227bed29cce0675383be28 100644 --- a/src/cmd/build.rs +++ b/src/cmd/build.rs @@ -291,7 +291,7 @@ pub(crate) fn execute_with_metadata( #[cfg(feature = "test-ci-only")] #[cfg(test)] mod tests { - use crate::{cmd, util::tests::with_tmp_dir, workspace::ManifestPath, UnstableFlags}; + use crate::{cmd, util::tests::with_tmp_dir, ManifestPath, UnstableFlags}; #[test] fn build_template() { diff --git a/src/cmd/metadata.rs b/src/cmd/metadata.rs index 8b658d3fe33139a9cc5c04a19fa76de5b9ce019e..15393910e3c48e5da36e52a0077fb40e2f91ed20 100644 --- a/src/cmd/metadata.rs +++ b/src/cmd/metadata.rs @@ -192,8 +192,7 @@ pub(crate) fn execute( #[cfg(test)] mod tests { use crate::{ - cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, workspace::ManifestPath, - UnstableFlags, + cmd, crate_metadata::CrateMetadata, util::tests::with_tmp_dir, ManifestPath, UnstableFlags, }; use blake2::digest::{Update as _, VariableOutput as _}; use contract_metadata::*; diff --git a/src/crate_metadata.rs b/src/crate_metadata.rs index 82469dfc186adbbb0e4605b6d920d5d327eafbfa..60837b73dfcf5f4a63f6b53bab025336fbf9a71e 100644 --- a/src/crate_metadata.rs +++ b/src/crate_metadata.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with cargo-contract. If not, see . -use crate::workspace::ManifestPath; +use crate::ManifestPath; use anyhow::{Context, Result}; use cargo_metadata::{Metadata as CargoMetadata, MetadataCommand, Package}; use semver::Version; diff --git a/src/main.rs b/src/main.rs index 1e721a4ba99e522c98d42af8efefc2d0594a64f1..d6698c2bb5de60479382266a6fa175c3c24e96e6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -19,6 +19,8 @@ mod crate_metadata; mod util; mod workspace; +use self::workspace::ManifestPath; + #[cfg(feature = "extrinsics")] use sp_core::{crypto::Pair, sr25519, H256}; use std::{ @@ -163,6 +165,9 @@ enum Command { /// Compiles the smart contract #[structopt(name = "build")] Build { + /// Path to the Cargo.toml of the contract to build + #[structopt(long, parse(from_os_str))] + manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, #[structopt(flatten)] @@ -171,6 +176,9 @@ enum Command { /// Generate contract metadata artifacts #[structopt(name = "generate-metadata")] GenerateMetadata { + /// Path to the Cargo.toml of the contract for which to generate metadata + #[structopt(long, parse(from_os_str))] + manifest_path: Option, #[structopt(flatten)] verbosity: VerbosityFlags, #[structopt(flatten)] @@ -239,10 +247,11 @@ fn exec(cmd: Command) -> Result { match &cmd { Command::New { name, target_dir } => cmd::new::execute(name, target_dir.as_ref()), Command::Build { + manifest_path, verbosity, unstable_options, } => { - let manifest_path = Default::default(); + let manifest_path = ManifestPath::try_from(manifest_path.as_ref())?; let dest_wasm = cmd::build::execute( &manifest_path, verbosity.try_into()?, @@ -254,11 +263,13 @@ fn exec(cmd: Command) -> Result { )) } Command::GenerateMetadata { + manifest_path, verbosity, unstable_options, } => { + let manifest_path = ManifestPath::try_from(manifest_path.as_ref())?; let metadata_file = cmd::metadata::execute( - Default::default(), + manifest_path, verbosity.try_into()?, unstable_options.try_into()?, )?; diff --git a/src/workspace/manifest.rs b/src/workspace/manifest.rs index bf41a8e9e47b12ca8e8e6c1637606ce192e57d33..3cc851b9f232404cf5c8c3029d9c000ef5db9de0 100644 --- a/src/workspace/manifest.rs +++ b/src/workspace/manifest.rs @@ -76,6 +76,17 @@ impl TryFrom<&PathBuf> for ManifestPath { } } +impl TryFrom> for ManifestPath +where + P: AsRef, +{ + type Error = anyhow::Error; + + fn try_from(value: Option) -> Result { + value.map_or(Ok(Default::default()), ManifestPath::new) + } +} + impl Default for ManifestPath { fn default() -> ManifestPath { ManifestPath::new(MANIFEST_FILE).expect("it's a valid manifest file")
TryFrom> for ManifestPath +where + P: AsRef, +{ + type Error = anyhow::Error; + + fn try_from(value: Option) -> Result { + value.map_or(Ok(Default::default()), ManifestPath::new) + } +} + impl Default for ManifestPath { fn default() -> ManifestPath { ManifestPath::new(MANIFEST_FILE).expect("it's a valid manifest file")
) -> Result { + value.map_or(Ok(Default::default()), ManifestPath::new) + } +} + impl Default for ManifestPath { fn default() -> ManifestPath { ManifestPath::new(MANIFEST_FILE).expect("it's a valid manifest file")