diff --git a/Cargo.lock b/Cargo.lock index 9e2b3ec57d1..f4a2860be36 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -534,42 +534,43 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.25" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" +checksum = "90bc066a67923782aa8515dbaea16946c5bcc5addbd668bb80af688e53e548a0" dependencies = [ - "atty", - "bitflags 1.3.1", + "clap_builder", "clap_derive", +] + +[[package]] +name = "clap_builder" +version = "4.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +dependencies = [ + "anstream", + "anstyle", "clap_lex", - "indexmap 1.9.3", - "once_cell", - "strsim", - "termcolor", - "textwrap", + "strsim 0.11.1", ] [[package]] name = "clap_derive" -version = "3.2.25" +version = "4.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae6371b8bdc8b7d3959e9cf7b22d4435ef3e79e138688421ec654acf8c81b008" +checksum = "528131438037fd55894f62d6e9f068b8f45ac57ffa77517819645d10aed04f64" dependencies = [ - "heck 0.4.1", - "proc-macro-error", + "heck 0.5.0", "proc-macro2", "quote", - "syn 1.0.107", + "syn 2.0.58", ] [[package]] name = "clap_lex" -version = "0.2.2" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613" -dependencies = [ - "os_str_bytes", -] +checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "colorchoice" @@ -943,7 +944,7 @@ dependencies = [ "ident_case", "proc-macro2", "quote", - "strsim", + "strsim 0.10.0", "syn 2.0.58", ] @@ -1958,6 +1959,7 @@ dependencies = [ "fallible-iterator 0.3.0", "git-testament", "graph", + "graphql-parser", "hex", "itertools 0.12.1", "lazy_static", @@ -3199,12 +3201,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "os_str_bytes" -version = "6.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" - [[package]] name = "pad" version = "0.1.6" @@ -4538,6 +4534,12 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + [[package]] name = "strum_macros" version = "0.25.3" @@ -4750,12 +4752,6 @@ dependencies = [ "prost-types", ] -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" - [[package]] name = "thiserror" version = "1.0.57" diff --git a/Cargo.toml b/Cargo.toml index b6ec87989f3..b0b7a08e96e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ tonic = { version = "0.8.3", features = ["tls-roots", "gzip"] } tonic-build = { version = "0.8.4", features = ["prost"] } wasmtime = "15.0.1" wasmparser = "0.118.1" +clap = { version = "4.5.4", features = ["derive", "env"] } # Incremental compilation on Rust 1.58 causes an ICE on build. As soon as graph node builds again, these can be removed. [profile.test] diff --git a/graph/Cargo.toml b/graph/Cargo.toml index 2979bacaaaa..3fbaac24be0 100644 --- a/graph/Cargo.toml +++ b/graph/Cargo.toml @@ -95,7 +95,7 @@ csv = "1.3.0" object_store = { version = "0.9.1", features = ["gcp"] } [dev-dependencies] -clap = { version = "3.2.25", features = ["derive", "env"] } +clap.workspace = true maplit = "1.0.2" hex-literal = "0.4" diff --git a/graph/examples/stress.rs b/graph/examples/stress.rs index 5fbfb2f82ad..7e96d914fea 100644 --- a/graph/examples/stress.rs +++ b/graph/examples/stress.rs @@ -675,7 +675,7 @@ fn stress(opt: &Opt) { /// memory used on the heap since we started inserting into the cache to /// the target `cache_size` pub fn main() { - let opt = Opt::from_args(); + let opt = Opt::parse(); unsafe { PRINT_SAMPLES = opt.samples } // Use different Cacheables to see how the cache manages memory with diff --git a/graph/examples/validate.rs b/graph/examples/validate.rs index 96e544030c5..ed57feb1bec 100644 --- a/graph/examples/validate.rs +++ b/graph/examples/validate.rs @@ -114,6 +114,7 @@ struct Entry { schema: String, } +#[derive(Clone)] enum RunMode { Validate, Size, @@ -145,7 +146,10 @@ struct Opts { batch: bool, #[clap(long)] api: bool, - #[clap(short, long, default_value = "validate", possible_values = &["validate", "size"])] + #[clap( + short, long, default_value = "validate", + value_parser = clap::builder::PossibleValuesParser::new(&["validate", "size"]) + )] mode: RunMode, /// Subgraph schemas to validate #[clap(required = true)] diff --git a/node/Cargo.toml b/node/Cargo.toml index 9a2f31b6463..1fec3a39c5f 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -13,8 +13,8 @@ name = "graphman" path = "src/bin/manager.rs" [dependencies] -clap = { version = "3.2.25", features = ["derive", "env"] } env_logger = "0.11.3" +clap.workspace = true git-testament = "0.2" lazy_static = "1.2.0" url = "2.5.0" diff --git a/node/src/bin/manager.rs b/node/src/bin/manager.rs index f66519a3eae..5006cddde61 100644 --- a/node/src/bin/manager.rs +++ b/node/src/bin/manager.rs @@ -187,7 +187,7 @@ pub enum Command { long, short, default_value = "20", - parse(try_from_str = parse_duration_in_secs) + value_parser = parse_duration_in_secs )] sleep: Duration, }, @@ -205,7 +205,7 @@ pub enum Command { long, short, default_value = "20", - parse(try_from_str = parse_duration_in_secs) + value_parser = parse_duration_in_secs )] sleep: Duration, /// The block hash of the target block @@ -225,7 +225,7 @@ pub enum Command { )] block_number: Option, /// The deployments to rewind (see `help info`) - #[clap(required = true, min_values = 1)] + #[clap(required = true)] deployments: Vec, }, /// Deploy and run an arbitrary subgraph up to a certain block @@ -534,13 +534,13 @@ pub enum ChainCommand { #[clap(subcommand)] // Note that we mark a field as a subcommand method: CheckBlockMethod, /// Chain name (must be an existing chain, see 'chain list') - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] chain_name: String, }, /// Truncates the whole block cache for the given chain. Truncate { /// Chain name (must be an existing chain, see 'chain list') - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] chain_name: String, /// Skips confirmation prompt #[clap(long, short)] @@ -550,10 +550,10 @@ pub enum ChainCommand { /// Change the block cache shard for a chain ChangeShard { /// Chain name (must be an existing chain, see 'chain list') - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] chain_name: String, /// Shard name - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] shard: String, }, @@ -562,7 +562,7 @@ pub enum ChainCommand { #[clap(subcommand)] method: CallCacheCommand, /// Chain name (must be an existing chain, see 'chain list') - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] chain_name: String, }, } @@ -674,24 +674,24 @@ pub enum IndexCommand { /// This command may be time-consuming. Create { /// The deployment (see `help info`). - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] deployment: DeploymentSearch, /// The Entity name. /// /// Can be expressed either in upper camel case (as its GraphQL definition) or in snake case /// (as its SQL table name). - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] entity: String, /// The Field names. /// /// Each field can be expressed either in camel case (as its GraphQL definition) or in snake /// case (as its SQL colmun name). - #[clap(min_values = 1, required = true)] + #[clap(required = true)] fields: Vec, /// The index method. Defaults to `btree` in general, and to `gist` when the index includes the `block_range` column #[clap( - short, long, - possible_values = &["btree", "hash", "gist", "spgist", "gin", "brin"] + short, long, default_value = "btree", + value_parser = clap::builder::PossibleValuesParser::new(&["btree", "hash", "gist", "spgist", "gin", "brin"]) )] method: Option, @@ -718,23 +718,23 @@ pub enum IndexCommand { #[clap(long, requires = "sql")] if_not_exists: bool, /// The deployment (see `help info`). - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] deployment: DeploymentSearch, /// The Entity name. /// /// Can be expressed either in upper camel case (as its GraphQL definition) or in snake case /// (as its SQL table name). - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] entity: String, }, /// Drops an index for a given deployment, concurrently Drop { /// The deployment (see `help info`). - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] deployment: DeploymentSearch, /// The name of the index to be dropped - #[clap(empty_values = false)] + #[clap(value_parser = clap::builder::NonEmptyStringValueParser::new())] index_name: String, }, } diff --git a/node/src/opt.rs b/node/src/opt.rs index 06eb161c431..c2945959514 100644 --- a/node/src/opt.rs +++ b/node/src/opt.rs @@ -20,8 +20,8 @@ pub struct Opt { #[clap( long, env = "GRAPH_NODE_CONFIG", - conflicts_with_all = &["postgres-url", "postgres-secondary-hosts", "postgres-host-weights"], - required_unless = "postgres-url", + conflicts_with_all = &["postgres_url", "postgres_secondary_hosts", "postgres_host_weights"], + required_unless_present = "postgres_url", help = "the name of the configuration file", )] pub config: Option, @@ -48,14 +48,14 @@ pub struct Opt { value_name = "URL", env = "POSTGRES_URL", conflicts_with = "config", - required_unless = "config", + required_unless_present = "config", help = "Location of the Postgres database used for storing entities" )] pub postgres_url: Option, #[clap( long, value_name = "URL,", - use_delimiter = true, + use_value_delimiter = true, env = "GRAPH_POSTGRES_SECONDARY_HOSTS", conflicts_with = "config", help = "Comma-separated list of host names/IP's for read-only Postgres replicas, \ @@ -66,7 +66,7 @@ pub struct Opt { #[clap( long, value_name = "WEIGHT,", - use_delimiter = true, + use_value_delimiter = true, env = "GRAPH_POSTGRES_HOST_WEIGHTS", conflicts_with = "config", help = "Comma-separated list of relative weights for selecting the main database \ @@ -77,25 +77,26 @@ pub struct Opt { pub postgres_host_weights: Vec, #[clap( long, - min_values=0, - required_unless_one = &["ethereum-ws", "ethereum-ipc", "config"], - conflicts_with_all = &["ethereum-ws", "ethereum-ipc", "config"], + allow_negative_numbers = false, + required_unless_present_any = &["ethereum_ws", "ethereum_ipc", "config"], + conflicts_with_all = &["ethereum_ws", "ethereum_ipc", "config"], value_name="NETWORK_NAME:[CAPABILITIES]:URL", env="ETHEREUM_RPC", help= "Ethereum network name (e.g. 'mainnet'), optional comma-seperated capabilities (eg 'full,archive'), and an Ethereum RPC URL, separated by a ':'", )] pub ethereum_rpc: Vec, - #[clap(long, min_values=0, - required_unless_one = &["ethereum-rpc", "ethereum-ipc", "config"], - conflicts_with_all = &["ethereum-rpc", "ethereum-ipc", "config"], + #[clap(long, allow_negative_numbers = false, + required_unless_present_any = &["ethereum_rpc", "ethereum_ipc", "config"], + conflicts_with_all = &["ethereum_rpc", "ethereum_ipc", "config"], value_name="NETWORK_NAME:[CAPABILITIES]:URL", env="ETHEREUM_WS", help= "Ethereum network name (e.g. 'mainnet'), optional comma-seperated capabilities (eg 'full,archive`, and an Ethereum WebSocket URL, separated by a ':'", )] pub ethereum_ws: Vec, - #[clap(long, min_values=0, - required_unless_one = &["ethereum-rpc", "ethereum-ws", "config"], - conflicts_with_all = &["ethereum-rpc", "ethereum-ws", "config"], + #[clap(long, + allow_negative_numbers = false, + required_unless_present_any = &["ethereum_rpc", "ethereum_ws", "config"], + conflicts_with_all = &["ethereum_rpc", "ethereum_ws", "config"], value_name="NETWORK_NAME:[CAPABILITIES]:FILE", env="ETHEREUM_IPC", help= "Ethereum network name (e.g. 'mainnet'), optional comma-seperated capabilities (eg 'full,archive'), and an Ethereum IPC pipe, separated by a ':'", diff --git a/runtime/test/src/test.rs b/runtime/test/src/test.rs index a03127123ef..f25000ffae7 100644 --- a/runtime/test/src/test.rs +++ b/runtime/test/src/test.rs @@ -1485,8 +1485,6 @@ async fn test_store_set_id() { async fn test_store_set_invalid_fields() { const UID: &str = "u1"; const USER: &str = "User"; - // const BID: &str = "0xdeadbeef"; - // const BINARY: &str = "Binary"; let schema = " type User @entity { id: ID!, diff --git a/store/postgres/Cargo.toml b/store/postgres/Cargo.toml index b0f0966560f..1ed1cc2376c 100644 --- a/store/postgres/Cargo.toml +++ b/store/postgres/Cargo.toml @@ -32,4 +32,5 @@ hex = "0.4.3" pretty_assertions = "1.4.0" [dev-dependencies] -clap = "3.2.25" +clap.workspace = true +graphql-parser = "0.4.0"