diff --git a/CHANGELOG.md b/CHANGELOG.md index df5de3bcd3..33f20a0441 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,15 @@ # 0.24.2 +### feat: all commands will use the DFX_NETWORK from the environment + +If `DFX_NETWORK` is set in the environment, all commands will use that network by default. +The `--network` parameter will take precedence if provided. + +### fix: dfx generate now honors the --network parameter +This fixes an issue where `dfx deploy --playground` would fail if the project +had not been previously built for the local network. + ### feat: Support canister log allowed viewer list Added support for the canister log allowed viewer list, enabling specified users to access a canister's logs without needing to be set as the canister's controller. diff --git a/docs/cli-reference/dfx-envars.mdx b/docs/cli-reference/dfx-envars.mdx index 4b9f0ea558..0c1b742f2f 100644 --- a/docs/cli-reference/dfx-envars.mdx +++ b/docs/cli-reference/dfx-envars.mdx @@ -40,6 +40,11 @@ Use the `DFX_INSTALLATION_ROOT` environment variable to specify a different loca The `.cache/dfinity/uninstall.sh` script uses this environment variable to identify the root directory for your SDK installation. +## DFX_NETWORK + +Use the `DFX_NETWORK` environment variable to specify the network that you want to use when you run `dfx` commands. +If you pass the `--network` option to a `dfx` command, the value of the `DFX_NETWORK` environment variable is ignored. + ## DFX_VERSION Use the `DFX_VERSION` environment variable to identify a specific version of the SDK that you want to install. diff --git a/e2e/tests-dfx/generate.bash b/e2e/tests-dfx/generate.bash index f007654f77..67955956d3 100755 --- a/e2e/tests-dfx/generate.bash +++ b/e2e/tests-dfx/generate.bash @@ -139,14 +139,13 @@ teardown() { assert_command dfx generate } -@test "dfx generate --network is still valid" { - # The option has no effect, but is still accepted to not break existing scripts +@test "dfx generate --network is accepted" { dfx_new hello assert_command dfx generate --network local + assert_file_exists ".dfx/local/canisters/hello_backend/service.did" - # Option is not advertised anymore - assert_command dfx generate --help - assert_not_contains "--network" + assert_command dfx generate --playground + assert_file_exists ".dfx/playground/canisters/hello_backend/service.did" } @test "dfx generate does not delete source candid file of Rust canister when bindings contains no did" { diff --git a/e2e/tests-dfx/playground.bash b/e2e/tests-dfx/playground.bash index 5d8d3630ff..f71d8d4ff2 100644 --- a/e2e/tests-dfx/playground.bash +++ b/e2e/tests-dfx/playground.bash @@ -71,6 +71,20 @@ setup_playground() { assert_command dfx canister --playground info "$CANISTER" } +@test "deploy fresh project to playground" { + cd .. + rm -rf hello + dfx_new_frontend hello + + [[ "$USE_POCKETIC" ]] && assert_command dfx canister create --all --playground + [[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_backend --playground + [[ "$USE_POCKETIC" ]] && assert_command dfx ledger fabricate-cycles --t 9999999 --canister hello_frontend --playground + + assert_command dfx deploy --playground + assert_command dfx canister --playground call hello_backend greet '("player")' + assert_match "Hello, player!" +} + @test "Handle timeout correctly" { assert_command dfx canister create hello_backend --playground -vv assert_match "Reserved canister 'hello_backend'" diff --git a/src/dfx/src/commands/generate.rs b/src/dfx/src/commands/generate.rs index 17992ef765..840958162d 100644 --- a/src/dfx/src/commands/generate.rs +++ b/src/dfx/src/commands/generate.rs @@ -4,6 +4,7 @@ use crate::lib::builders::BuildConfig; use crate::lib::environment::Environment; use crate::lib::error::DfxResult; use crate::lib::models::canister::CanisterPool; +use crate::lib::network::network_opt::NetworkOpt; use clap::Parser; use tokio::runtime::Runtime; @@ -14,14 +15,12 @@ pub struct GenerateOpts { /// If you do not specify a canister name, generates types for all canisters. canister_name: Option, - // Deprecated/hidden because it had/has no effect. - // Cannot use 'hide' on a flattened object - inlined the flattened network specifier - #[arg(long, global = true, hide = true)] - network: Option, + #[command(flatten)] + network: NetworkOpt, } pub fn exec(env: &dyn Environment, opts: GenerateOpts) -> DfxResult { - let env = create_anonymous_agent_environment(env, None)?; + let env = create_anonymous_agent_environment(env, opts.network.to_network_name())?; let log = env.get_logger(); // Read the config. diff --git a/src/dfx/src/lib/network/network_opt.rs b/src/dfx/src/lib/network/network_opt.rs index ab46426c9d..5e264f5bb1 100644 --- a/src/dfx/src/lib/network/network_opt.rs +++ b/src/dfx/src/lib/network/network_opt.rs @@ -9,7 +9,7 @@ pub struct NetworkOpt { /// A valid URL (starting with `http:` or `https:`) can be used here, and a special /// ephemeral network will be created specifically for this request. E.g. /// "http://localhost:12345/" is a valid network name. - #[arg(long, global(true), group = "network-select")] + #[arg(long, env = "DFX_NETWORK", global(true), group = "network-select")] network: Option, /// Shorthand for --network=playground.