Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDK-607 feat: replace using IDs on the command line with project name #145

Merged
merged 6 commits into from
Nov 12, 2019

Conversation

hansl
Copy link
Contributor

@hansl hansl commented Nov 7, 2019

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

@hansl hansl requested a review from a team as a code owner November 7, 2019 03:40
@hansl
Copy link
Contributor Author

hansl commented Nov 8, 2019

@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.
@hansl hansl changed the title feat: replace using IDs on the command line with project name SDK-503 feat: replace using IDs on the command line with project name Nov 10, 2019
@hansl hansl changed the title SDK-503 feat: replace using IDs on the command line with project name SDK-607 feat: replace using IDs on the command line with project name Nov 10, 2019
@@ -56,7 +50,7 @@ impl UserMessage {

// dfx build
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this category then? create a misc one.

@paulyoung
Copy link
Contributor

SDK-607 feat: replace using IDs on the command line with project name

I'm guessing this probably uses canister names rather project name

std::fs::write(&output_wasm_path, wasm)?;

// Write the CID.
canister_info.create_canister_id()?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we do something like this?

eprint!("Request ID: ");
println!("0x{}", String::from(request_id));

I'm hoping this would read Request ID: 0x...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same with other places we print the ID.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Should we pipe things to different stdout and stderr? Why don't we use the same (stderr)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


@test "build outputs the canister ID" {
assert_command dfx build
[[ -f canisters/hello/_canister.id ]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post this PR: Perhaps we should have a random name project test.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(|| {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also was done in #147 😁

👍

canister_info.get_canister_id_path(),
canister_info.generate_canister_id()?.into_blob().0,
)
.map_err(DfxError::from)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@hansl hansl requested a review from paulyoung November 12, 2019 00:14
// Generate a random u64.
let time_since_the_epoch = SystemTime::now()
.duration_since(UNIX_EPOCH)
.expect("Time went backwards.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😁 It can happen actually.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need the time here actually?

https://docs.rs/rand/0.6.1/rand/rngs/struct.ThreadRng.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we get a u64?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

@@ -66,6 +67,9 @@ impl UserMessage {
UserMessage::StartNode => "Starts the local network client.",
UserMessage::NodeAddress => "Specifies the host name and port number to bind the frontend to.",
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.",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hansl looks like this needs updating because of the change to require a canister name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

.arg(
Arg::with_name("all")
.long("all")
.required_unless("canister_name")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need a similar change for the canister_name argument to say it's required unless the all flag is passed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apparently it doesn't matter.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How so?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The message to the user is the same. ¯_(ツ)_/¯

@mergify mergify bot merged commit 931f65f into master Nov 12, 2019
@mergify mergify bot deleted the hansl/canister-names branch November 12, 2019 01:09
paulyoung pushed a commit that referenced this pull request Nov 15, 2019
…#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants