Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(forge): add tree command #771

Merged
merged 6 commits into from
Mar 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions cli/src/cmd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ pub mod remappings;
pub mod run;
pub mod snapshot;
pub mod test;
pub mod tree;
pub mod verify;
pub mod watch;

Expand Down
34 changes: 34 additions & 0 deletions cli/src/cmd/tree.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//! tree command

use crate::cmd::{build::BuildArgs, Cmd};
use clap::Parser;
use ethers::solc::Graph;
use foundry_config::Config;

foundry_config::impl_figment_convert!(TreeArgs, opts);
use ethers::solc::resolver::{Charset, TreeOptions};

/// Command to display the project's dependency tree
#[derive(Debug, Clone, Parser)]
pub struct TreeArgs {
// TODO extract path related args from BuildArgs
#[clap(flatten)]
opts: BuildArgs,
#[clap(help = "Do not de-duplicate (repeats all shared dependencies)", long)]
no_dedupe: bool,
#[clap(help = "Character set to use in output: utf8, ascii", default_value = "utf8", long)]
charset: Charset,
}

impl Cmd for TreeArgs {
type Output = ();

fn run(self) -> eyre::Result<Self::Output> {
let config: Config = From::from(&self);
let graph = Graph::resolve(&config.project_paths())?;
let opts = TreeOptions { charset: self.charset, no_dedupe: self.no_dedupe };
graph.print_with_options(opts);

Ok(())
}
}
3 changes: 3 additions & 0 deletions cli/src/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ fn main() -> eyre::Result<()> {
Subcommands::Flatten(cmd) => {
cmd.run()?;
}
Subcommands::Tree(cmd) => {
cmd.run()?;
}
}

Ok(())
Expand Down
4 changes: 3 additions & 1 deletion cli/src/opts/forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::cmd::{
install::InstallArgs,
remappings::RemappingArgs,
run::RunArgs,
snapshot, test,
snapshot, test, tree,
verify::{VerifyArgs, VerifyCheckArgs},
};
use serde::Serialize;
Expand Down Expand Up @@ -116,6 +116,8 @@ pub enum Subcommands {
Flatten(flatten::FlattenArgs),
// #[clap(about = "formats Solidity source files")]
// Fmt(FmtArgs),
#[clap(about = "Display a tree visualization of the project's dependency graph")]
Tree(tree::TreeArgs),
}

// A set of solc compiler settings that can be set via command line arguments, which are intended
Expand Down