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: add support for basic vyper project using forge init --vyper #9930

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
13 changes: 12 additions & 1 deletion crates/forge/bin/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,17 @@ pub struct InitArgs {
#[arg(long, conflicts_with = "template")]
pub vscode: bool,

/// Initialize a Vyper project template
#[arg(long, conflicts_with = "template")]
pub vyper: bool,

#[command(flatten)]
pub install: DependencyInstallOpts,
}

impl InitArgs {
pub fn run(self) -> Result<()> {
let Self { root, template, branch, install, offline, force, vscode } = self;
let Self { root, template, branch, install, offline, force, vscode, vyper } = self;
let DependencyInstallOpts { shallow, no_git, commit } = install;

// create the root dir if it does not exist
Expand All @@ -53,6 +57,13 @@ impl InitArgs {
let root = dunce::canonicalize(root)?;
let git = Git::new(&root).shallow(shallow);

// If vyper flag is set, use the Vyper template
let template = if vyper {
Some("https://github.com/Patronum-Labs/foundry-vyper".to_string())
} else {
template
};

// if a template is provided, then this command initializes a git repo,
// fetches the template repo, and resets the git history to the head of the fetched
// repo with no other history
Expand Down
23 changes: 23 additions & 0 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,29 @@ Warning: Target directory is not empty, but `--force` was specified
let _config: BasicConfig = parse_with_profile(&s).unwrap().unwrap().1;
});

// checks that init works with vyper flag
forgetest!(can_init_vyper_project, |prj, cmd| {
prj.wipe();

cmd.args(["init", "--vyper"]).arg(prj.root()).assert_success().stdout_eq(str![[r#"
Initializing [..] from https://github.com/Patronum-Labs/foundry-vyper...
Initialized forge project

"#]]);

// Check that the Vyper template repository was cloned correctly
assert!(prj.root().join(".git").exists());
assert!(prj.root().join("foundry.toml").exists());
assert!(prj.root().join("lib/forge-std").exists());
assert!(prj.root().join(".git/modules").exists());
assert!(prj.root().join("src").exists());
assert!(prj.root().join("test").exists());
assert!(prj.root().join("src").read_dir().unwrap().any(|entry| {
let path = entry.unwrap().path();
path.to_string_lossy().ends_with(".vy") || path.to_string_lossy().ends_with(".vpy")
}));
});

// Checks that a forge project fails to initialise if dir is already git repo and dirty
forgetest!(can_detect_dirty_git_status_on_init, |prj, cmd| {
prj.wipe();
Expand Down
Loading