Skip to content

Commit

Permalink
feat: add clap value hints for improved completion (gakonst#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
clifton authored Jan 11, 2022
1 parent 1dd55d6 commit 5f0aed1
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 26 deletions.
32 changes: 21 additions & 11 deletions cli/src/cmd/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{

use crate::{cmd::Cmd, opts::forge::CompilerArgs, utils};

use clap::Parser;
use clap::{Parser, ValueHint};
#[cfg(feature = "evmodin-evm")]
use evmodin::util::mocked_host::MockedHost;
#[cfg(feature = "sputnik-evm")]
Expand All @@ -26,27 +26,38 @@ use sputnik::backend::MemoryVicinity;
pub struct BuildArgs {
#[clap(
help = "the project's root path. By default, this is the root directory of the current Git repository or the current working directory if it is not part of a Git repository",
long
long,
value_hint = ValueHint::DirPath
)]
pub root: Option<PathBuf>,

#[clap(
env = "DAPP_SRC",
help = "the directory relative to the root under which the smart contracts are",
long,
short
short,
value_hint = ValueHint::DirPath
)]
#[clap(env = "DAPP_SRC")]
pub contracts: Option<PathBuf>,

#[clap(help = "the remappings", long, short)]
pub remappings: Vec<ethers::solc::remappings::Remapping>,
#[clap(long = "remappings-env", env = "DAPP_REMAPPINGS")]
pub remappings_env: Option<String>,

#[clap(help = "the paths where your libraries are installed", long)]
#[clap(
help = "the paths where your libraries are installed",
long,
value_hint = ValueHint::DirPath
)]
pub lib_paths: Vec<PathBuf>,

#[clap(help = "path to where the contract artifacts are stored", long = "out", short)]
#[clap(
help = "path to where the contract artifacts are stored",
long = "out",
short,
value_hint = ValueHint::DirPath
)]
pub out_path: Option<PathBuf>,

#[clap(flatten)]
Expand Down Expand Up @@ -279,15 +290,14 @@ pub struct Env {
#[clap(
help = "the tx.origin value during EVM execution",
long,
default_value = "0x0000000000000000000000000000000000000000"
default_value_t = Address::zero()
)]
pub tx_origin: Address,

#[clap(
help = "the block.coinbase value during EVM execution",
long,
// TODO: It'd be nice if we could use Address::zero() here.
default_value = "0x0000000000000000000000000000000000000000"
help = "the block.coinbase value during EVM execution",
long,
default_value_t = Address::zero()
)]
pub block_coinbase: Address,
#[clap(
Expand Down
14 changes: 11 additions & 3 deletions cli/src/cmd/remappings.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
//! remappings command
use crate::cmd::Cmd;
use clap::Parser;
use clap::{Parser, ValueHint};
use ethers::solc::{remappings::Remapping, ProjectPathsConfig};
use std::path::PathBuf;

/// Command to list remappings
#[derive(Debug, Clone, Parser)]
pub struct RemappingArgs {
#[clap(help = "the project's root path, default being the current working directory", long)]
#[clap(
help = "the project's root path, default being the current working directory",
long,
value_hint = ValueHint::DirPath
)]
root: Option<PathBuf>,
#[clap(help = "the paths where your libraries are installed", long)]
#[clap(
help = "the paths where your libraries are installed",
long,
value_hint = ValueHint::DirPath
)]
lib_paths: Vec<PathBuf>,
}

Expand Down
4 changes: 2 additions & 2 deletions cli/src/cmd/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::{
cmd::{build::BuildArgs, compile, manual_compile, Cmd},
opts::forge::EvmOpts,
};
use clap::Parser;
use clap::{Parser, ValueHint};
use ethers::abi::Abi;
use forge::ContractRunner;
use foundry_utils::IntoFunction;
Expand All @@ -24,7 +24,7 @@ use ethers::{

#[derive(Debug, Clone, Parser)]
pub struct RunArgs {
#[clap(help = "the path to the contract to run")]
#[clap(help = "the path to the contract to run", value_hint = ValueHint::FilePath)]
pub path: PathBuf,

#[clap(flatten)]
Expand Down
8 changes: 5 additions & 3 deletions cli/src/cmd/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::cmd::{
Cmd,
};
use ansi_term::Colour;
use clap::Parser;
use clap::{Parser, ValueHint};
use eyre::Context;
use forge::TestKindGas;
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -38,13 +38,15 @@ pub struct SnapshotArgs {
#[clap(
help = "Compare against a snapshot and display changes from the snapshot. Takes an optional snapshot file, [default: .gas-snapshot]",
conflicts_with = "snap",
long
long,
value_hint = ValueHint::FilePath
)]
diff: Option<Option<PathBuf>>,
#[clap(
help = "Run snapshot in 'check' mode and compares against an existing snapshot file, [default: .gas-snapshot]. Exits with 0 if snapshots match. Exits with 1 and prints a diff otherwise",
conflicts_with = "diff",
long
long,
value_hint = ValueHint::FilePath
)]
check: Option<Option<PathBuf>>,
#[clap(help = "How to format the output.", long)]
Expand Down
26 changes: 24 additions & 2 deletions cli/src/opts/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,29 @@ pub enum Subcommands {
#[clap(name = "etherscan-source")]
#[clap(about = "Prints the source code of a contract from Etherscan")]
EtherscanSource {
#[clap(long, env = "CHAIN", default_value = "mainnet")]
#[clap(
long,
env = "CHAIN",
default_value = "mainnet",
// if Chain implemented ArgEnum, we'd get this for free
possible_values = [
"mainnet",
"ropsten",
"rinkeby",
"goerli",
"kovan",
"x_dai",
"polygon",
"polygon_mumbai",
"avalanche",
"avalanche_fuji",
"sepolia",
"moonbeam",
"moonbeam_dev",
"moonriver",
"optimism",
"optimism_kovan"
])]
chain: Chain,
#[clap(help = "the contract address")]
address: String,
Expand All @@ -309,7 +331,7 @@ pub enum Subcommands {
},
#[clap(about = "generate shell completions script")]
Completions {
#[clap(help = "supported shells: bash, elvish, fish, powershell, zsh")]
#[clap(arg_enum)]
shell: clap_complete::Shell,
},
}
Expand Down
15 changes: 10 additions & 5 deletions cli/src/opts/forge.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use clap::{Parser, Subcommand};
use clap::{Parser, Subcommand, ValueHint};

use ethers::{solc::EvmVersion, types::Address};
use std::{path::PathBuf, str::FromStr};
Expand Down Expand Up @@ -31,7 +31,8 @@ pub enum Subcommands {
#[clap(alias = "u", about = "fetches all upstream lib changes")]
Update {
#[clap(
help = "the submodule name of the library you want to update (will update all if none is provided)"
help = "the submodule name of the library you want to update (will update all if none is provided)",
value_hint = ValueHint::DirPath
)]
lib: Option<PathBuf>,
},
Expand Down Expand Up @@ -68,23 +69,27 @@ pub enum Subcommands {

#[clap(alias = "i", about = "initializes a new forge sample repository")]
Init {
#[clap(help = "the project's root path, default being the current working directory")]
#[clap(
help = "the project's root path, default being the current working directory",
value_hint = ValueHint::DirPath
)]
root: Option<PathBuf>,
#[clap(help = "optional solidity template to start from", long, short)]
template: Option<String>,
},

#[clap(about = "generate shell completions script")]
Completions {
#[clap(help = "bash, elvish, fish, powershell, zsh")]
#[clap(arg_enum)]
shell: clap_complete::Shell,
},

#[clap(about = "removes the build artifacts and cache directories")]
Clean {
#[clap(
help = "the project's root path, default being the current working directory",
long
long,
value_hint = ValueHint::DirPath
)]
root: Option<PathBuf>,
},
Expand Down

0 comments on commit 5f0aed1

Please sign in to comment.