Skip to content

Commit 5528dc5

Browse files
feat: add support for basic vyper project using forge init --vyper
1 parent c609884 commit 5528dc5

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

crates/forge/bin/cmd/init.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,17 @@ pub struct InitArgs {
3737
#[arg(long, conflicts_with = "template")]
3838
pub vscode: bool,
3939

40+
/// Initialize a Vyper project template
41+
#[arg(long, conflicts_with = "template")]
42+
pub vyper: bool,
43+
4044
#[command(flatten)]
4145
pub install: DependencyInstallOpts,
4246
}
4347

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

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

60+
// If vyper flag is set, use the Vyper template
61+
let template = if vyper {
62+
Some("https://github.com/Patronum-Labs/foundry-vyper".to_string())
63+
} else {
64+
template
65+
};
66+
5667
// if a template is provided, then this command initializes a git repo,
5768
// fetches the template repo, and resets the git history to the head of the fetched
5869
// repo with no other history

crates/forge/tests/cli/cmd.rs

+23
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,29 @@ Warning: Target directory is not empty, but `--force` was specified
281281
let _config: BasicConfig = parse_with_profile(&s).unwrap().unwrap().1;
282282
});
283283

284+
// checks that init works with vyper flag
285+
forgetest!(can_init_vyper_project, |prj, cmd| {
286+
prj.wipe();
287+
288+
cmd.args(["init", "--vyper"]).arg(prj.root()).assert_success().stdout_eq(str![[r#"
289+
Initializing [..] from https://github.com/Patronum-Labs/foundry-vyper...
290+
Initialized forge project
291+
292+
"#]]);
293+
294+
// Check that the Vyper template repository was cloned correctly
295+
assert!(prj.root().join(".git").exists());
296+
assert!(prj.root().join("foundry.toml").exists());
297+
assert!(prj.root().join("lib/forge-std").exists());
298+
assert!(prj.root().join(".git/modules").exists());
299+
assert!(prj.root().join("src").exists());
300+
assert!(prj.root().join("test").exists());
301+
assert!(prj.root().join("src").read_dir().unwrap().any(|entry| {
302+
let path = entry.unwrap().path();
303+
path.to_string_lossy().ends_with(".vy") || path.to_string_lossy().ends_with(".vpy")
304+
}));
305+
});
306+
284307
// Checks that a forge project fails to initialise if dir is already git repo and dirty
285308
forgetest!(can_detect_dirty_git_status_on_init, |prj, cmd| {
286309
prj.wipe();

0 commit comments

Comments
 (0)