Skip to content

Commit

Permalink
Read install arg from file
Browse files Browse the repository at this point in the history
  • Loading branch information
bitdivine committed Nov 3, 2023
1 parent abc51b1 commit 6145e16
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
14 changes: 12 additions & 2 deletions e2e/tests-dfx/install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,17 @@ teardown() {
assert_contains db07e7e24f6f8ddf53c33a610713259a7c1eb71c270b819ebd311e2d223267f0
}

@test "installing one canister with an argument succeeds" {
assert_command dfx canister install e2e_project_backend --argument '()'
}

@test "installing with an argument in a file succeeds" {
TMPFILE="$(mktemp)"
echo '()' >"$TMPFILE"
assert_command dfx canister install e2e_project_backend --argument-file "$TMPFILE"
}

@test "installing multiple canisters with arguments fails" {
assert_command_fail dfx canister install --all --argument hello
assert_command_fail dfx canister install --all --argument '()'
assert_contains "error: the argument '--all' cannot be used with '--argument <ARGUMENT>'"
}
}
17 changes: 16 additions & 1 deletion src/dfx/src/commands/canister/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,17 @@ pub struct CanisterInstallOpts {
upgrade_unchanged: bool,

/// Specifies the argument to pass to the method.
#[arg(long)]
#[arg(long, conflicts_with("argument_file"))]
argument: Option<String>,

/// Specifies the file from which to read the argument to pass to the method.
#[arg(
long,
value_parser = file_or_stdin_parser,
conflicts_with("argument")
)]
argument_file: Option<PathBuf>,

/// Specifies the data type for the argument when making the call using an argument.
#[arg(long, requires("argument"), value_parser = ["idl", "raw"])]
argument_type: Option<String>,
Expand Down Expand Up @@ -107,7 +115,14 @@ pub async fn exec(

let canister_id =
Principal::from_text(canister).or_else(|_| canister_id_store.get(canister))?;

let arguments_from_file = opts
.argument_file
.map(|v| arguments_from_file(&v))
.transpose()?;
let arguments = opts.argument.as_deref();
let arguments = arguments_from_file.as_deref().or(arguments);

let arg_type = opts.argument_type.as_deref();
let canister_info = config.as_ref()
.ok_or_else(|| anyhow!("Cannot find dfx configuration file in the current working directory. Did you forget to create one?"))
Expand Down

0 comments on commit 6145e16

Please sign in to comment.