forc/cli/commands/
init.rs

1use crate::ops::forc_init;
2use clap::Parser;
3use forc_util::ForcResult;
4
5forc_util::cli_examples! {
6    crate::cli::Opt {
7        [Initialize a new Forc project => "forc init --path <PATH>"]
8        [Initialize a new Forc project as workspace => "forc init --path <PATH> --workspace"]
9        [Initialize a new Forc project with a predicate => "forc init --path <PATH> --predicate"]
10        [Initialize a new Forc library project => "forc init --path <PATH> --library"]
11    }
12}
13
14/// Create a new Forc project in an existing directory.
15#[derive(Debug, Parser)]
16#[clap(bin_name = "forc init", version, after_help = help())]
17pub struct Command {
18    /// The directory in which the forc project will be initialized.
19    #[clap(long)]
20    pub path: Option<String>,
21    /// The default program type, excluding all flags or adding this flag creates a basic contract program.
22    #[clap(long)]
23    pub contract: bool,
24    /// Create a package with a script target (src/main.sw).
25    #[clap(long)]
26    pub script: bool,
27    /// Create a package with a predicate target (src/predicate.rs).
28    #[clap(long)]
29    pub predicate: bool,
30    /// Create a package with a library target (src/lib.sw).
31    #[clap(long)]
32    pub library: bool,
33    /// Adding this flag creates an empty workspace.
34    #[clap(long)]
35    pub workspace: bool,
36    /// Set the package name. Defaults to the directory name
37    #[clap(long)]
38    pub name: Option<String>,
39}
40
41pub(crate) fn exec(command: Command) -> ForcResult<()> {
42    forc_init::init(command)?;
43    Ok(())
44}