Skip to content

Commit

Permalink
add contract flag to new and init
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 8, 2023
1 parent aa40bce commit 6e2549a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 13 additions & 3 deletions crates/nargo_cli/src/cli/init_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ pub(crate) struct InitCommand {
name: Option<String>,

/// Use a library template
#[arg(long, conflicts_with = "bin")]
#[arg(long, conflicts_with = "bin", conflicts_with = "contract")]
pub(crate) lib: bool,

/// Use a binary template [default]
#[arg(long, conflicts_with = "lib")]
#[arg(long, conflicts_with = "lib", conflicts_with = "contract")]
pub(crate) bin: bool,

/// Use a contract template
#[arg(long, conflicts_with = "lib", conflicts_with = "bin")]
pub(crate) contract: bool,
}

const BIN_EXAMPLE: &str = r#"fn main(x : Field, y : pub Field) {
Expand Down Expand Up @@ -67,7 +71,13 @@ pub(crate) fn run<B: Backend>(
.name
.unwrap_or_else(|| config.program_dir.file_name().unwrap().to_str().unwrap().to_owned());

let package_type = if args.lib { PackageType::Library } else { PackageType::Binary };
let package_type = if args.lib {
PackageType::Library
} else if args.contract {
PackageType::Contract
} else {
PackageType::Binary
};
initialize_project(config.program_dir, &package_name, package_type);
Ok(())
}
Expand Down
16 changes: 13 additions & 3 deletions crates/nargo_cli/src/cli/new_cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ pub(crate) struct NewCommand {
name: Option<String>,

/// Use a library template
#[arg(long, conflicts_with = "bin")]
#[arg(long, conflicts_with = "bin", conflicts_with = "contract")]
pub(crate) lib: bool,

/// Use a binary template [default]
#[arg(long, conflicts_with = "lib")]
#[arg(long, conflicts_with = "lib", conflicts_with = "contract")]
pub(crate) bin: bool,

/// Use a contract template
#[arg(long, conflicts_with = "lib", conflicts_with = "bin")]
pub(crate) contract: bool,
}

pub(crate) fn run<B: Backend>(
Expand All @@ -39,7 +43,13 @@ pub(crate) fn run<B: Backend>(

let package_name =
args.name.unwrap_or_else(|| args.path.file_name().unwrap().to_str().unwrap().to_owned());
let package_type = if args.lib { PackageType::Library } else { PackageType::Binary };
let package_type = if args.lib {
PackageType::Library
} else if args.contract {
PackageType::Contract
} else {
PackageType::Binary
};
initialize_project(package_dir, &package_name, package_type);
Ok(())
}

0 comments on commit 6e2549a

Please sign in to comment.