Skip to content

Commit

Permalink
fix(gcli): command meta
Browse files Browse the repository at this point in the history
  • Loading branch information
clearloop committed Dec 19, 2023
1 parent c67d24b commit 1486ac6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
8 changes: 4 additions & 4 deletions gcli/src/cmd/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Command `program`.
use crate::{meta::Meta, result::Result, utils, App};
use crate::{meta::Meta, result::Result, App};
use clap::Parser;
use gsdk::{ext::sp_core::H256, Api};
use std::{fs, path::PathBuf};
Expand All @@ -33,8 +33,8 @@ pub enum Program {
///
/// - "*.meta.txt" describes the metadata of the program
/// - "*.meta.wasm" describes the wasm exports of the program
#[arg(short, long)]
meta: Option<PathBuf>,
#[cfg_attr(feature = "embed", clap(skip))]
meta: PathBuf,
/// Overridden metadata binary if feature embed is enabled.
#[clap(skip)]
meta_override: Vec<u8>,
Expand Down Expand Up @@ -98,7 +98,7 @@ impl Program {
meta_override,
} => {
let meta = if meta_override.is_empty() {
Self::resolve_meta(&utils::meta_path(meta.clone(), "meta")?)
Self::resolve_meta(meta)
} else {
Meta::decode_wasm(meta_override)
}?;
Expand Down
22 changes: 1 addition & 21 deletions gcli/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
use crate::result::Result;
use anyhow::anyhow;
use std::{env, fs, path::PathBuf};
use std::{fs, path::PathBuf};

/// home directory of cli `gear`
pub fn home() -> PathBuf {
Expand All @@ -33,26 +33,6 @@ pub fn home() -> PathBuf {
home
}

/// Parse the metadata path with result.
pub fn meta_path(meta: Option<PathBuf>, opt: &str) -> Result<PathBuf> {
if let Some(meta) = meta {
return Ok(meta);
}

let cwd = env::current_dir()?;
for entry in fs::read_dir(&cwd)? {
let file = entry?.path();
if file.ends_with(".meta.wasm") {
return Ok(file);
}
}

Err(anyhow!(
"Could not find any *.meta.wasm in {cwd:?}, please specify the metadata path with --{opt}",
)
.into())
}

pub trait Hex {
fn to_vec(&self) -> Result<Vec<u8>>;
fn to_hash(&self) -> Result<[u8; 32]>;
Expand Down
2 changes: 1 addition & 1 deletion gcli/tests/gear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ mod common;
#[tokio::test]
async fn api_timeout() {
assert!(matches!(
Api::new_with_timeout(None, Some(1)).await.err(),
Api::new_with_timeout(None, Some(0)).await.err(),
Some(Error::SubxtRpc(jsonrpsee::core::Error::Transport(..)))
));
}
Expand Down

0 comments on commit 1486ac6

Please sign in to comment.