From a100f547cf6b622bb71fed0827f8cc864719b9ea Mon Sep 17 00:00:00 2001 From: Cesar Rodas Date: Thu, 22 Feb 2024 12:24:03 -0300 Subject: [PATCH] Less magic Call forc_util::cli::register() explicitly instead of doing some dark magic behind through cli_examples macro --- Cargo.lock | 1 + forc-plugins/forc-client/src/bin/deploy.rs | 3 +- forc-plugins/forc-client/src/bin/run.rs | 3 +- forc-plugins/forc-client/src/bin/submit.rs | 3 +- forc-plugins/forc-crypto/src/main.rs | 3 +- forc-plugins/forc-debug/Cargo.toml | 1 + forc-plugins/forc-debug/src/main.rs | 3 +- forc-plugins/forc-doc/src/main.rs | 3 +- forc-plugins/forc-fmt/src/main.rs | 6 +- forc-plugins/forc-tx/src/lib.rs | 6 +- forc-util/src/cli.rs | 66 +++++----------------- forc/src/cli/commands/completions.rs | 10 ++-- 12 files changed, 40 insertions(+), 68 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0bedcb6e00..06769edeafb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2083,6 +2083,7 @@ dependencies = [ "escargot", "forc-pkg", "forc-test", + "forc-util", "fuel-core-client", "fuel-types", "fuel-vm", diff --git a/forc-plugins/forc-client/src/bin/deploy.rs b/forc-plugins/forc-client/src/bin/deploy.rs index 030db172bc3..45378539e00 100644 --- a/forc-plugins/forc-client/src/bin/deploy.rs +++ b/forc-plugins/forc-client/src/bin/deploy.rs @@ -1,8 +1,9 @@ -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_tracing::{init_tracing_subscriber, println_error}; #[tokio::main] async fn main() { + forc_util::cli::register(forc_client::cmd::Deploy::into_app()); init_tracing_subscriber(Default::default()); let command = forc_client::cmd::Deploy::parse(); if let Err(err) = forc_client::op::deploy(command).await { diff --git a/forc-plugins/forc-client/src/bin/run.rs b/forc-plugins/forc-client/src/bin/run.rs index 77305f90bfa..387d728d0c8 100644 --- a/forc-plugins/forc-client/src/bin/run.rs +++ b/forc-plugins/forc-client/src/bin/run.rs @@ -1,8 +1,9 @@ -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_tracing::{init_tracing_subscriber, println_error}; #[tokio::main] async fn main() { + forc_util::cli::register(forc_client::cmd::Run::into_app()); init_tracing_subscriber(Default::default()); let command = forc_client::cmd::Run::parse(); if let Err(err) = forc_client::op::run(command).await { diff --git a/forc-plugins/forc-client/src/bin/submit.rs b/forc-plugins/forc-client/src/bin/submit.rs index cb0155a1c62..9f5973c963e 100644 --- a/forc-plugins/forc-client/src/bin/submit.rs +++ b/forc-plugins/forc-client/src/bin/submit.rs @@ -1,8 +1,9 @@ -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_tracing::{init_tracing_subscriber, println_error}; #[tokio::main] async fn main() { + forc_util::cli::register(forc_client::cmd::Submit::into_app()); init_tracing_subscriber(Default::default()); let command = forc_client::cmd::Submit::parse(); if let Err(err) = forc_client::op::submit(command).await { diff --git a/forc-plugins/forc-crypto/src/main.rs b/forc-plugins/forc-crypto/src/main.rs index b872264d4f6..1592b194b60 100644 --- a/forc-plugins/forc-crypto/src/main.rs +++ b/forc-plugins/forc-crypto/src/main.rs @@ -2,7 +2,7 @@ use anyhow::Result; use atty::Stream; -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_tracing::{init_tracing_subscriber, println_error}; use std::{ default::Default, @@ -57,6 +57,7 @@ fn main() { } fn run() -> Result<()> { + forc_util::cli::register(Command::into_app()); let app = Command::parse(); let content = match app { Command::Keccak256(arg) => keccak256::hash(arg)?, diff --git a/forc-plugins/forc-debug/Cargo.toml b/forc-plugins/forc-debug/Cargo.toml index cda0f48c948..30977ea6390 100644 --- a/forc-plugins/forc-debug/Cargo.toml +++ b/forc-plugins/forc-debug/Cargo.toml @@ -15,6 +15,7 @@ dap = "0.4.1-alpha1" forc-pkg = { version = "0.50.0", path = "../../forc-pkg" } forc-test = { version = "0.50.0", path = "../../forc-test" } fuel-core-client = { workspace = true } +forc-util = { version = "0.50.0", path = "../../forc-util" } fuel-types = { workspace = true, features = ["serde"] } fuel-vm = { workspace = true, features = ["serde"] } rayon = "1.7.0" diff --git a/forc-plugins/forc-debug/src/main.rs b/forc-plugins/forc-debug/src/main.rs index 946d3b4d285..02c49e8cbf4 100644 --- a/forc-plugins/forc-debug/src/main.rs +++ b/forc-plugins/forc-debug/src/main.rs @@ -1,4 +1,4 @@ -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_debug::{ names::{register_index, register_name}, server::DapServer, @@ -20,6 +20,7 @@ pub struct Opt { #[tokio::main] async fn main() -> Result<(), Box> { + forc_util::cli::register(Opt::into_app()); let config = Opt::parse(); if config.serve { diff --git a/forc-plugins/forc-doc/src/main.rs b/forc-plugins/forc-doc/src/main.rs index b9d3c79fba2..88b83e30e0f 100644 --- a/forc-plugins/forc-doc/src/main.rs +++ b/forc-plugins/forc-doc/src/main.rs @@ -4,7 +4,7 @@ use crate::{ search::write_search_index, }; use anyhow::{bail, Result}; -use clap::Parser; +use clap::{IntoApp, Parser}; use cli::Command; use colored::*; use forc_pkg as pkg; @@ -51,6 +51,7 @@ struct ProgramInfo<'a> { } pub fn main() -> Result<()> { + forc_util::cli::register(Command::into_app()); let build_instructions = Command::parse(); let (doc_path, pkg_manifest) = compile_html(&build_instructions, &get_doc_dir)?; diff --git a/forc-plugins/forc-fmt/src/main.rs b/forc-plugins/forc-fmt/src/main.rs index d88a38ffd9e..a8fbbdd10e8 100644 --- a/forc-plugins/forc-fmt/src/main.rs +++ b/forc-plugins/forc-fmt/src/main.rs @@ -1,7 +1,7 @@ //! A `forc` plugin for running the Sway code formatter. use anyhow::{bail, Result}; -use clap::Parser; +use clap::{IntoApp, Parser}; use forc_pkg::{ manifest::{GenericManifestFile, ManifestFile}, WorkspaceManifestFile, @@ -51,7 +51,8 @@ pub struct App { pub path: Option, #[clap(short, long)] /// Formats a single .sw file with the default settings. - /// If not specified, current working directory will be formatted using a Forc.toml configuration. + /// If not specified, current working directory will be formatted using a Forc.toml + /// configuration. pub file: Option, } @@ -65,6 +66,7 @@ fn main() { } fn run() -> Result<()> { + forc_util::cli::register(App::into_app()); let app = App::parse(); let dir = match app.path.as_ref() { diff --git a/forc-plugins/forc-tx/src/lib.rs b/forc-plugins/forc-tx/src/lib.rs index 088fe8808f8..d51ec78100f 100644 --- a/forc-plugins/forc-tx/src/lib.rs +++ b/forc-plugins/forc-tx/src/lib.rs @@ -13,9 +13,6 @@ use std::path::PathBuf; use thiserror::Error; forc_util::cli_examples! { - { - None - } { // This parser has a custom parser super::Command::try_parse_from_args @@ -728,7 +725,8 @@ impl TryFrom