From 232af9c402a0cd832a744170c5233d46d7a70443 Mon Sep 17 00:00:00 2001 From: Eric Swanson <64809312+ericswanson-dfinity@users.noreply.github.com> Date: Thu, 15 Feb 2024 12:04:51 -0800 Subject: [PATCH 1/4] refactor: extension run logic out of main (#3596) --- src/dfx/src/main.rs | 49 ++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/dfx/src/main.rs b/src/dfx/src/main.rs index 24543ad355..242dc3fdd1 100644 --- a/src/dfx/src/main.rs +++ b/src/dfx/src/main.rs @@ -2,6 +2,7 @@ use crate::config::{dfx_version, dfx_version_str}; use crate::lib::diagnosis::{diagnose, Diagnosis, NULL_DIAGNOSIS}; use crate::lib::environment::{Environment, EnvironmentImpl}; +use crate::lib::error::DfxResult; use crate::lib::logger::{create_root_logger, LoggingMode}; use crate::lib::warning::{is_warning_disabled, DfxWarning::VersionCheck}; use anyhow::Error; @@ -160,31 +161,33 @@ fn print_error_and_diagnosis(err: Error, error_diagnosis: Diagnosis) { } } -fn main() { +fn get_args_altered_for_extension_run() -> DfxResult> { let mut args = std::env::args_os().collect::>(); - let mut error_diagnosis: Diagnosis = NULL_DIAGNOSIS; + let em = ExtensionManager::new(dfx_version())?; - ExtensionManager::new(dfx_version()) - .and_then(|em| { - let installed_extensions = em.installed_extensions_as_clap_commands()?; - if !installed_extensions.is_empty() { - let mut app = CliOpts::command_for_update().subcommands(&installed_extensions); - sort_clap_commands(&mut app); - // here clap will display the help message if no subcommand was provided... - let app = app.get_matches(); - // ...therefore we can safely unwrap here because we know a subcommand was provided - let subcmd = app.subcommand().unwrap().0; - if em.is_extension_installed(subcmd) { - let idx = args.iter().position(|arg| arg == subcmd).unwrap(); - args.splice(idx..idx, ["extension", "run"].iter().map(OsString::from)); - } - } - Ok(()) - }) - .unwrap_or_else(|err| { - print_error_and_diagnosis(err.into(), error_diagnosis.clone()); - std::process::exit(255); - }); + let installed_extensions = em.installed_extensions_as_clap_commands()?; + if !installed_extensions.is_empty() { + let mut app = CliOpts::command_for_update().subcommands(&installed_extensions); + sort_clap_commands(&mut app); + // here clap will display the help message if no subcommand was provided... + let app = app.get_matches(); + // ...therefore we can safely unwrap here because we know a subcommand was provided + let subcmd = app.subcommand().unwrap().0; + if em.is_extension_installed(subcmd) { + let idx = args.iter().position(|arg| arg == subcmd).unwrap(); + args.splice(idx..idx, ["extension", "run"].iter().map(OsString::from)); + } + } + Ok(args) +} + +fn main() { + let args = get_args_altered_for_extension_run().unwrap_or_else(|err| { + print_error_and_diagnosis(err, NULL_DIAGNOSIS); + std::process::exit(255); + }); + + let mut error_diagnosis: Diagnosis = NULL_DIAGNOSIS; let cli_opts = CliOpts::parse_from(args); let (verbose_level, log) = setup_logging(&cli_opts); From 879f0cb00cf3496a086612b37b54968e71134add Mon Sep 17 00:00:00 2001 From: Jessie Mongeon <133128541+jessiemongeon1@users.noreply.github.com> Date: Fri, 16 Feb 2024 11:17:03 -0600 Subject: [PATCH 2/4] Update dfx-canister.md (#3597) --- docs/cli-reference/dfx-canister.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/cli-reference/dfx-canister.md b/docs/cli-reference/dfx-canister.md index dff2c4bf2f..dd7d58e072 100644 --- a/docs/cli-reference/dfx-canister.md +++ b/docs/cli-reference/dfx-canister.md @@ -113,7 +113,7 @@ You can use the following optional flags with the `dfx canister call` command. | Flag | Description | |------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `--async` | Specifies not to wait for the result of the call to be returned by polling the replica. Instead return a response ID. | -| `--query` | Sends a query request instead of an update request. For information about the difference between query and update calls, see [Canisters include both program and state](../../concepts/canisters-code.md#canister-state). | +| `--query` | Sends a query request instead of an update request. For information about the difference between query and update calls, see [Canisters include both program and state](/docs/current/concepts/canisters-code#canister-state). | | `--update` | Sends an update request to a canister. This is the default if the method is not a query method. | ### Options @@ -137,7 +137,7 @@ You can specify the following arguments for the `dfx canister call` command. |-----------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `canister_name` | Specifies the name of the canister to call. The canister name is a required argument and should match the name you have configured for a project in the `canisters` section of the `dfx.json` configuration file. | | `method_name` | Specifies the method name to call on the canister. The canister method is a required argument. | -| `argument` | Specifies the argument to pass to the method. Depending on your program logic, the argument can be a required or optional argument. You can specify a data format type using the `--type` option if you pass an argument to the canister. By default, you can specify arguments using the [Candid](../../developer-docs/backend/candid/index.md) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](../../developer-docs/backend/candid/candid-howto.md#idl-syntax) and [Supported types](../candid-ref.md). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | +| `argument` | Specifies the argument to pass to the method. Depending on your program logic, the argument can be a required or optional argument. You can specify a data format type using the `--type` option if you pass an argument to the canister. By default, you can specify arguments using the [Candid](/docs/current/developer-docs/backend/candid/index) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](/docs/current/developer-docs/backend/candid/candid-howto#idl-syntax) and [Supported types](/docs/current/references/candid-ref). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | ### Examples @@ -452,10 +452,10 @@ You can use the following options with the `dfx canister install` command. | Option | Description | |---------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `--argument ` | Specifies an argument to pass to the canister during installation. | -| `--argument-type ` | Specifies the data format for the argument when you install using the `--argument` option. The valid values are `idl` and `raw`. By default, you can specify arguments using the [Candid](../../developer-docs/backend/candid/index.md) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](../../developer-docs/backend/candid/candid-howto.md#idl-syntax) and [Supported types](../candid-ref.md). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | +| `--argument-type ` | Specifies the data format for the argument when you install using the `--argument` option. The valid values are `idl` and `raw`. By default, you can specify arguments using the [Candid](/docs/current/developer-docs/backend/candid/index) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](/docs/current/developer-docs/backend/candid/candid-howto#idl-syntax) and [Supported types](../candid-ref.md). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | | `-c`, `--compute-allocation ` | Defines a compute allocation—essentially the equivalent of setting a CPU allocation—for canister execution. You can set this value as a percentage in the range of 0 to 100. | | `--memory-allocation ` | Specifies how much memory the canister is allowed to use in total. You can set this value in the range of 0 to 8MB. | -| `-m`, `--mode ` | Specifies whether you want to `install`, `reinstall`, or `upgrade` canisters. Defaults to `install`. For more information about installation modes and canister management, see [Managing canisters](../../developer-docs/setup/manage-canisters.md). | +| `-m`, `--mode ` | Specifies whether you want to `install`, `reinstall`, or `upgrade` canisters. Defaults to `install`. For more information about installation modes and canister management, see [Managing canisters](/docs/current/developer-docs/setup/manage-canisters). | | `--wasm ` | Specifies a particular WASM file to install, bypassing the dfx.json project settings. | ### Arguments @@ -691,7 +691,7 @@ You can specify the following arguments for the `dfx canister sign` command. |-----------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `canister_name` | Specifies the name of the canister to call. The canister name is a required argument and should match the name you have configured for a project in the `canisters` section of the `dfx.json` configuration file. | | `method_name` | Specifies the method name to call on the canister. The canister method is a required argument. | -| `argument` | Specifies the argument to pass to the method. Depending on your program logic, the argument can be a required or optional argument. You can specify a data format type using the `--type` option if you pass an argument to the canister. By default, you can specify arguments using the [Candid](../candid-ref.md) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](../../developer-docs/backend/candid/candid-howto.md#idl-syntax) and [Supported types](../candid-ref#supported-types). You can use `raw` as the argument type if you want to pass raw bytes. | +| `argument` | Specifies the argument to pass to the method. Depending on your program logic, the argument can be a required or optional argument. You can specify a data format type using the `--type` option if you pass an argument to the canister. By default, you can specify arguments using the [Candid](/docs/current/references/candid-ref) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](/docs/current/developer-docs/backend/candid/candid-howto#idl-syntax) and [Supported types](/docs/current/candid-ref#supported-types). You can use `raw` as the argument type if you want to pass raw bytes. | ### Examples From 31a941f90b0589479281a8a0b37a42ea2ad6d0e3 Mon Sep 17 00:00:00 2001 From: Jessie Mongeon <133128541+jessiemongeon1@users.noreply.github.com> Date: Fri, 16 Feb 2024 12:09:59 -0600 Subject: [PATCH 3/4] Update dfx-canister.md (#3600) --- docs/cli-reference/dfx-canister.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli-reference/dfx-canister.md b/docs/cli-reference/dfx-canister.md index dd7d58e072..f68d9e3492 100644 --- a/docs/cli-reference/dfx-canister.md +++ b/docs/cli-reference/dfx-canister.md @@ -452,7 +452,7 @@ You can use the following options with the `dfx canister install` command. | Option | Description | |---------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `--argument ` | Specifies an argument to pass to the canister during installation. | -| `--argument-type ` | Specifies the data format for the argument when you install using the `--argument` option. The valid values are `idl` and `raw`. By default, you can specify arguments using the [Candid](/docs/current/developer-docs/backend/candid/index) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](/docs/current/developer-docs/backend/candid/candid-howto#idl-syntax) and [Supported types](../candid-ref.md). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | +| `--argument-type ` | Specifies the data format for the argument when you install using the `--argument` option. The valid values are `idl` and `raw`. By default, you can specify arguments using the [Candid](/docs/current/developer-docs/backend/candid/index) (`idl`) syntax for data values. For information about using Candid and its supported types, see [Interact with a service in a terminal](/docs/current/developer-docs/backend/candid/candid-howto#idl-syntax) and [Supported types](/docs/current/references/candid-ref). You can use `raw` as the argument type if you want to pass raw bytes to a canister. | | `-c`, `--compute-allocation ` | Defines a compute allocation—essentially the equivalent of setting a CPU allocation—for canister execution. You can set this value as a percentage in the range of 0 to 100. | | `--memory-allocation ` | Specifies how much memory the canister is allowed to use in total. You can set this value in the range of 0 to 8MB. | | `-m`, `--mode ` | Specifies whether you want to `install`, `reinstall`, or `upgrade` canisters. Defaults to `install`. For more information about installation modes and canister management, see [Managing canisters](/docs/current/developer-docs/setup/manage-canisters). | From e5c921110984111b2950ab6b0d915cb581c20cbe Mon Sep 17 00:00:00 2001 From: Kai Peacock Date: Fri, 16 Feb 2024 10:39:06 -0800 Subject: [PATCH 4/4] chore: promote 0.17.0 (#3601) --- public/manifest.json | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/public/manifest.json b/public/manifest.json index 4cfbbdb6b8..19503257ea 100644 --- a/public/manifest.json +++ b/public/manifest.json @@ -1,6 +1,6 @@ { "tags": { - "latest": "0.16.1" + "latest": "0.17.0" }, "versions": [ "0.5.0", @@ -63,6 +63,7 @@ "0.15.2", "0.15.3", "0.16.0", - "0.16.1" + "0.16.1", + "0.17.0" ] -} \ No newline at end of file +}