1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use crate::{cli::init::Command as InitCommand, ops::forc_init::init};
use anyhow::{bail, Result};
use clap::Parser;
use std::path::Path;
#[derive(Debug, Parser)]
pub struct Command {
#[clap(long)]
pub contract: bool,
#[clap(long)]
pub script: bool,
#[clap(long)]
pub predicate: bool,
#[clap(long)]
pub library: bool,
#[clap(long)]
pub name: Option<String>,
pub path: String,
}
pub(crate) fn exec(command: Command) -> Result<()> {
let Command {
contract,
script,
predicate,
library,
name,
path,
} = command;
let dir_path = Path::new(&path);
if dir_path.exists() {
bail!(
"Directory \"{}\" already exists.\nIf you wish to initialise a forc project inside \
this directory, consider using `forc init --path {}`",
dir_path.canonicalize()?.display(),
dir_path.display(),
);
} else {
std::fs::create_dir_all(dir_path)?;
}
let init_cmd = InitCommand {
path: Some(path),
contract,
script,
predicate,
library,
name,
};
init(init_cmd)
}