From b55ec7db4d6365c3df3ade4b778d23a8fd0c8568 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Tue, 4 Oct 2022 20:38:53 +0800 Subject: [PATCH 1/5] Upgrade clap to 3.2.8 Upgrade to the latest version of v3 before upgrading to v4 --- meilisearch-http/Cargo.toml | 2 +- meilisearch-lib/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index cabb6ed48..704686876 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -31,7 +31,7 @@ async-trait = "0.1.57" bstr = "1.0.1" byte-unit = { version = "4.0.14", default-features = false, features = ["std", "serde"] } bytes = "1.2.1" -clap = { version = "3.1.6", features = ["derive", "env"] } +clap = { version = "3.2.8", features = ["derive", "env"] } crossbeam-channel = "0.5.6" either = "1.8.0" env_logger = "0.9.1" diff --git a/meilisearch-lib/Cargo.toml b/meilisearch-lib/Cargo.toml index c1af2f00f..5cf6fa0e9 100644 --- a/meilisearch-lib/Cargo.toml +++ b/meilisearch-lib/Cargo.toml @@ -11,7 +11,7 @@ async-trait = "0.1.57" atomic_refcell = "0.1.8" byte-unit = { version = "4.0.14", default-features = false, features = ["std", "serde"] } bytes = "1.2.1" -clap = { version = "3.1.6", features = ["derive", "env"] } +clap = { version = "3.2.8", features = ["derive", "env"] } crossbeam-channel = "0.5.6" csv = "1.1.6" derivative = "2.2.0" From 6285c5949cf998f5862afcd607affa2506e64ecc Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Tue, 4 Oct 2022 20:59:57 +0800 Subject: [PATCH 2/5] Fix clap v4 deprecation warning Following the 3. stap of [clap v4 migration instructions](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#migrating) The result for 'cargo check --features clap/deprecated' is https://user-images.githubusercontent.com/12410942/193825216-ac680574-f53b-49c0-88c4-8bc42c4c6381.png --- meilisearch-http/src/option.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index a47a2b211..f4678d725 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -82,7 +82,7 @@ pub struct Opt { pub master_key: Option, /// Configures the instance's environment. Value must be either `production` or `development`. - #[clap(long, env = MEILI_ENV, default_value_t = default_env(), possible_values = &POSSIBLE_ENV)] + #[clap(long, env = MEILI_ENV, default_value_t = default_env(), value_parser = POSSIBLE_ENV)] #[serde(default = "default_env")] pub env: String, @@ -115,24 +115,24 @@ pub struct Opt { /// Sets the server's SSL certificates. #[serde(skip_serializing)] - #[clap(long, env = MEILI_SSL_CERT_PATH, parse(from_os_str))] + #[clap(long, env = MEILI_SSL_CERT_PATH, value_parser)] pub ssl_cert_path: Option, /// Sets the server's SSL key files. #[serde(skip_serializing)] - #[clap(long, env = MEILI_SSL_KEY_PATH, parse(from_os_str))] + #[clap(long, env = MEILI_SSL_KEY_PATH, value_parser)] pub ssl_key_path: Option, /// Enables client authentication in the specified path. #[serde(skip_serializing)] - #[clap(long, env = MEILI_SSL_AUTH_PATH, parse(from_os_str))] + #[clap(long, env = MEILI_SSL_AUTH_PATH, value_parser)] pub ssl_auth_path: Option, /// Sets the server's OCSP file. *Optional* /// /// Reads DER-encoded OCSP response from OCSPFILE and staple to certificate. #[serde(skip_serializing)] - #[clap(long, env = MEILI_SSL_OCSP_PATH, parse(from_os_str))] + #[clap(long, env = MEILI_SSL_OCSP_PATH, value_parser)] pub ssl_ocsp_path: Option, /// Makes SSL authentication mandatory. From 9e5ef8eb696c31536262997fe7cfa7cf3f3a8c29 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Tue, 4 Oct 2022 21:46:27 +0800 Subject: [PATCH 3/5] Upgrade clap to v4 Close #2846 4.0.0 changelog: 'https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#400---2022-09-28' I followed the [Migrating steps](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#migrating) and the only issue I encountered are: 1. The typo problem in previous commit "Fix clap ArgGroup typo" 2. I can't say I am 100% sure every [Subtle changes](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#breaking-changes) is fine for our use case, but at least after a quick read I didn't notice anything actionable. --- Cargo.lock | 53 +++++++++++++++++++++++++++++++------ meilisearch-http/Cargo.toml | 2 +- meilisearch-lib/Cargo.toml | 2 +- 3 files changed, 47 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b26636a01..37edcbc6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -711,8 +711,8 @@ checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ "atty", "bitflags", - "clap_derive", - "clap_lex", + "clap_derive 3.2.18", + "clap_lex 0.2.4", "indexmap", "once_cell", "strsim", @@ -720,6 +720,21 @@ dependencies = [ "textwrap", ] +[[package]] +name = "clap" +version = "4.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30607dd93c420c6f1f80b544be522a0238a7db35e6a12968d28910983fee0df0" +dependencies = [ + "atty", + "bitflags", + "clap_derive 4.0.9", + "clap_lex 0.3.0", + "once_cell", + "strsim", + "termcolor", +] + [[package]] name = "clap_derive" version = "3.2.18" @@ -733,6 +748,19 @@ dependencies = [ "syn 1.0.101", ] +[[package]] +name = "clap_derive" +version = "4.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4a307492e1a34939f79d3b6b9650bd2b971513cd775436bf2b78defeb5af00b" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2 1.0.46", + "quote 1.0.21", + "syn 1.0.101", +] + [[package]] name = "clap_lex" version = "0.2.4" @@ -742,6 +770,15 @@ dependencies = [ "os_str_bytes", ] +[[package]] +name = "clap_lex" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "concat-arrays" version = "0.1.2" @@ -1793,7 +1830,7 @@ dependencies = [ "anyhow", "bincode", "byteorder", - "clap", + "clap 3.2.22", "csv", "encoding", "env_logger", @@ -1868,7 +1905,7 @@ dependencies = [ "anyhow", "bincode", "byteorder", - "clap", + "clap 3.2.22", "encoding", "env_logger", "glob", @@ -1888,7 +1925,7 @@ dependencies = [ "anyhow", "bincode", "byteorder", - "clap", + "clap 3.2.22", "csv", "encoding", "env_logger", @@ -1908,7 +1945,7 @@ dependencies = [ "anyhow", "bincode", "byteorder", - "clap", + "clap 3.2.22", "csv", "encoding", "env_logger", @@ -2049,7 +2086,7 @@ dependencies = [ "byte-unit", "bytes", "cargo_toml", - "clap", + "clap 4.0.9", "crossbeam-channel", "either", "env_logger", @@ -2121,7 +2158,7 @@ dependencies = [ "atomic_refcell", "byte-unit", "bytes", - "clap", + "clap 4.0.9", "crossbeam-channel", "csv", "derivative", diff --git a/meilisearch-http/Cargo.toml b/meilisearch-http/Cargo.toml index 704686876..a41f82d24 100644 --- a/meilisearch-http/Cargo.toml +++ b/meilisearch-http/Cargo.toml @@ -31,7 +31,7 @@ async-trait = "0.1.57" bstr = "1.0.1" byte-unit = { version = "4.0.14", default-features = false, features = ["std", "serde"] } bytes = "1.2.1" -clap = { version = "3.2.8", features = ["derive", "env"] } +clap = { version = "4.0.9", features = ["derive", "env"] } crossbeam-channel = "0.5.6" either = "1.8.0" env_logger = "0.9.1" diff --git a/meilisearch-lib/Cargo.toml b/meilisearch-lib/Cargo.toml index 5cf6fa0e9..c48a7bdf7 100644 --- a/meilisearch-lib/Cargo.toml +++ b/meilisearch-lib/Cargo.toml @@ -11,7 +11,7 @@ async-trait = "0.1.57" atomic_refcell = "0.1.8" byte-unit = { version = "4.0.14", default-features = false, features = ["std", "serde"] } bytes = "1.2.1" -clap = { version = "3.2.8", features = ["derive", "env"] } +clap = { version = "4.0.9", features = ["derive", "env"] } crossbeam-channel = "0.5.6" csv = "1.1.6" derivative = "2.2.0" From da25328c2bf2ad184f4db951d3ff808d5bf18cbc Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Fri, 7 Oct 2022 00:32:08 +0800 Subject: [PATCH 4/5] Fix clap ArgGroup typos Not sure why but the compiler didn't catch this until clap is upgraded to v4. Follwoing are the error from 'cargo test': running 2 tests test routes::indexes::search::test::test_fix_sort_query_parameters ... ok test option::test::test_valid_opt ... FAILED failures: ---- option::test::test_valid_opt stdout ---- thread 'option::test::test_valid_opt' panicked at 'Command meilisearch-http: Argument or group 'import-snapshot' specified in 'requires*' for 'ignore_missing_snapshot' does not exist', /Users/ychou/.cargo/registry/src/github.com-1ecc6299db9ec823/clap-4.0.9/src/builder/debug_asserts.rs:152:13 note: run with environment variable to display a backtrace failures: option::test::test_valid_opt test result: FAILED. 1 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s --- meilisearch-http/src/option.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index f4678d725..0445bf2ca 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -161,7 +161,7 @@ pub struct Opt { #[clap( long, env = MEILI_IGNORE_MISSING_SNAPSHOT, - requires = "import-snapshot" + requires = "import_snapshot" )] #[serde(default)] pub ignore_missing_snapshot: bool, @@ -174,7 +174,7 @@ pub struct Opt { #[clap( long, env = MEILI_IGNORE_SNAPSHOT_IF_DB_EXISTS, - requires = "import-snapshot" + requires = "import_snapshot" )] #[serde(default)] pub ignore_snapshot_if_db_exists: bool, @@ -196,14 +196,14 @@ pub struct Opt { /// Imports the dump file located at the specified path. Path must point to a `.dump` file. /// If a database already exists, Meilisearch will throw an error and abort launch. - #[clap(long, env = MEILI_IMPORT_DUMP, conflicts_with = "import-snapshot")] + #[clap(long, env = MEILI_IMPORT_DUMP, conflicts_with = "import_snapshot")] pub import_dump: Option, /// Prevents Meilisearch from throwing an error when `--import-dump` does not point to /// a valid dump file. Instead, Meilisearch will start normally without importing any dump. /// /// This option will trigger an error if `--import-dump` is not defined. - #[clap(long, env = MEILI_IGNORE_MISSING_DUMP, requires = "import-dump")] + #[clap(long, env = MEILI_IGNORE_MISSING_DUMP, requires = "import_dump")] #[serde(default)] pub ignore_missing_dump: bool, @@ -212,7 +212,7 @@ pub struct Opt { /// launch using the existing database. /// /// This option will trigger an error if `--import-dump` is not defined. - #[clap(long, env = MEILI_IGNORE_DUMP_IF_DB_EXISTS, requires = "import-dump")] + #[clap(long, env = MEILI_IGNORE_DUMP_IF_DB_EXISTS, requires = "import_dump")] #[serde(default)] pub ignore_dump_if_db_exists: bool, From 5dafdd9a2332e66a7c2e0379bcb9013009b561f2 Mon Sep 17 00:00:00 2001 From: Lawrence Chou Date: Fri, 14 Oct 2022 16:43:01 +0800 Subject: [PATCH 5/5] Preserve --help output ordering after upgrade Clap to 4.0 From the [4.0 breaking change][1]: ... * (help) Make DeriveDisplayOrder the default and removed the setting. To sort help, set next_display_order(None) (#2808) ... [1]: https://github.com/clap-rs/clap/blob/master/CHANGELOG.md#breaking-changes --- meilisearch-http/src/option.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meilisearch-http/src/option.rs b/meilisearch-http/src/option.rs index 0445bf2ca..c7b157fd0 100644 --- a/meilisearch-http/src/option.rs +++ b/meilisearch-http/src/option.rs @@ -63,7 +63,7 @@ const DEFAULT_DUMPS_DIR: &str = "dumps/"; const DEFAULT_LOG_LEVEL: &str = "INFO"; #[derive(Debug, Clone, Parser, Serialize, Deserialize)] -#[clap(version)] +#[clap(version, next_display_order = None)] #[serde(rename_all = "snake_case", deny_unknown_fields)] pub struct Opt { /// Designates the location where database files will be created and retrieved.