SDK-607 feat: replace using IDs on the command line with project name#145
SDK-607 feat: replace using IDs on the command line with project name#145mergify[bot] merged 6 commits intomasterfrom
Conversation
815a2d8 to
62000ff
Compare
|
@dfinity-lab/sdk ping |
This includes install which does not take a wasm path anymore. We have a new structure for getting any metadata related to a canister, CanisterInfo. It takes a config and a name. This should facilitate working with paths and IDs in general, inside the CLI.
f32cc03 to
5c8c301
Compare
| @@ -56,7 +50,7 @@ impl UserMessage { | |||
|
|
|||
| // dfx build | |||
There was a problem hiding this comment.
Can we remove this category then? create a misc one.
I'm guessing this probably uses canister names rather project name |
dfx/src/commands/build.rs
Outdated
| std::fs::write(&output_wasm_path, wasm)?; | ||
|
|
||
| // Write the CID. | ||
| canister_info.create_canister_id()?; |
There was a problem hiding this comment.
Could we rename the function rather than rely on a comment? I haven't looked yet but I assume that create_canister_id mutates canister_info or writes to dfx.json or both.
There was a problem hiding this comment.
It writes to build/<project_name>/canister.id. I'll refactor that.
| match runtime.block_on(request_status) { | ||
| Ok(ReadResponse::Pending) => { | ||
| eprintln!("Pending"); | ||
| println!("0x{}", String::from(request_id)); |
There was a problem hiding this comment.
Can we do something like this?
eprint!("Request ID: ");
println!("0x{}", String::from(request_id));I'm hoping this would read Request ID: 0x...
There was a problem hiding this comment.
Same with other places we print the ID.
There was a problem hiding this comment.
Sure. Note that this code hasn't been changed (copy-pasted) and we should most definitely rewrite it all when we move the client API to the http lib.
There was a problem hiding this comment.
Question: Should we pipe things to different stdout and stderr? Why don't we use the same (stderr)?
There was a problem hiding this comment.
STDOUT is scriptable. STDERR is human readable. This is a simplification, but in essence that's what it is. Like in our scripts we use STDOUT of a command to use request-status.
There was a problem hiding this comment.
Thanks for the clarification!
| print_idl_blob(&blob) | ||
| .map_err(|e| DfxError::InvalidData(format!("Invalid IDL blob: {}", e)))?; | ||
| // Install all canisters. | ||
| if let Some(canisters) = &config.get_config().canisters { |
There was a problem hiding this comment.
I think we should consider showing an error saying that a canister name or an --all flag is required. Installing all canisters when a name is omitted seems like an easy way to overwrite canisters by accident.
|
|
||
| @test "build outputs the canister ID" { | ||
| assert_command dfx build | ||
| [[ -f canisters/hello/_canister.id ]] |
There was a problem hiding this comment.
Post this PR: Perhaps we should have a random name project test.
There was a problem hiding this comment.
We will change the project name soon, so let's do that then.
|
|
||
| let canister_name = args.value_of("canister_name").unwrap(); | ||
| let canister_info = CanisterInfo::load(config, canister_name)?; | ||
| let canister_id = canister_info.get_canister_id().ok_or_else(|| { |
| canister_info.get_canister_id_path(), | ||
| canister_info.generate_canister_id()?.into_blob().0, | ||
| ) | ||
| .map_err(DfxError::from)?; |
| // Generate a random u64. | ||
| let time_since_the_epoch = SystemTime::now() | ||
| .duration_since(UNIX_EPOCH) | ||
| .expect("Time went backwards."); |
There was a problem hiding this comment.
😁 It can happen actually.
There was a problem hiding this comment.
Cannot happen with UNIX_EPOCH. Only if I take now()
| .duration_since(UNIX_EPOCH) | ||
| .expect("Time went backwards."); | ||
| let cid = u64::from(time_since_the_epoch.as_millis() as u32).shl(32) | ||
| + u64::from(thread_rng().gen::<u32>()); |
There was a problem hiding this comment.
Why do we need the time here actually?
There was a problem hiding this comment.
Because we want a monolithically increasing number that is different for each run, but in case 2 runs happen in the same millisecond we want different IDs (hence the randomness).
| UserMessage::StartBackground => "Exits the dfx leaving the client running. Will wait until the client replies before exiting.", | ||
|
|
||
| // misc | ||
| UserMessage::CanisterName => "Specifies the canister name. If you don't specify this argument, all canisters are processed.", |
There was a problem hiding this comment.
@hansl looks like this needs updating because of the change to require a canister name.
| .arg( | ||
| Arg::with_name("all") | ||
| .long("all") | ||
| .required_unless("canister_name") |
There was a problem hiding this comment.
Do we need a similar change for the canister_name argument to say it's required unless the all flag is passed?
There was a problem hiding this comment.
Apparently it doesn't matter.
There was a problem hiding this comment.
The message to the user is the same. ¯_(ツ)_/¯
…#145) * feat: replace using IDs on the command line with project name This includes install which does not take a wasm path anymore. We have a new structure for getting any metadata related to a canister, CanisterInfo. It takes a config and a name. This should facilitate working with paths and IDs in general, inside the CLI. * fixup, including fixing bash using stderr and stdout for request id * fixup: add --all * fixup
This includes install which does not take a wasm path anymore.
We have a new structure for getting any metadata related to a canister,
CanisterInfo. It takes a config and a name. This should facilitate
working with paths and IDs in general, inside the CLI.
Fixes SDK-607