Skip to content

Commit

Permalink
add init command
Browse files Browse the repository at this point in the history
  • Loading branch information
rauljordan committed Aug 12, 2024
1 parent 570e7af commit ac00d0c
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 2 deletions.
11 changes: 10 additions & 1 deletion check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,20 @@ struct Opts {

#[derive(Parser, Debug, Clone)]
enum Apis {
/// Create a new Rust project.
/// Create a new Stylus project.
New {
/// Project name.
name: PathBuf,
/// Create a minimal contract.
#[arg(long)]
minimal: bool,
},
/// Initializes a Stylus project in the current directory.
Init {
/// Create a minimal contract.
#[arg(long)]
minimal: bool,
},
/// Export a Solidity ABI.
ExportAbi {
/// The output file (defaults to stdout).
Expand Down Expand Up @@ -296,6 +302,9 @@ async fn main_impl(args: Opts) -> Result<()> {
Apis::New { name, minimal } => {
run!(new::new(&name, minimal), "failed to open new project");
}
Apis::Init { minimal } => {
run!(new::init(minimal), "failed to initialize project");
}
Apis::ExportAbi { json, output } => {
run!(export_abi::export_abi(output, json), "failed to export abi");
}
Expand Down
39 changes: 39 additions & 0 deletions check/src/new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,42 @@ pub fn new(name: &Path, minimal: bool) -> Result<()> {
println!("{GREY}new project at: {}", path.to_string_lossy().mint());
Ok(())
}

pub fn init(minimal: bool) -> Result<()> {
let current_dir = current_dir().wrap_err("no current dir")?;
let repo = if minimal {
GITHUB_TEMPLATE_REPO_MINIMAL
} else {
GITHUB_TEMPLATE_REPO
};

let output = sys::new_command("git")
.arg("clone")
.arg("--depth")
.arg("1")
.arg("--no-checkout")
.arg(repo)
.arg(".")
.output()
.wrap_err("git clone failed")?;

if !output.status.success() {
bail!("git clone command failed");
}

let output = sys::new_command("git")
.arg("checkout")
.arg(".")
.output()
.wrap_err("git checkout failed")?;

if !output.status.success() {
bail!("git checkout command failed");
}

println!(
"{GREY}initialized project in: {}",
current_dir.to_string_lossy().mint()
);
Ok(())
}
7 changes: 6 additions & 1 deletion main/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ struct Opts {
#[derive(Parser, Debug, Clone)]
enum Subcommands {
#[command(alias = "n")]
/// Create a new Rust project.
/// Create a new Stylus project.
New,
#[command(alias = "i")]
/// Initializes a Stylus project in the current directory.
Init,
#[command(alias = "x")]
/// Export a Solidity ABI.
ExportAbi,
Expand Down Expand Up @@ -69,13 +72,15 @@ const COMMANDS: &[Binary] = &[
name: "cargo-stylus-check",
apis: &[
"new",
"init",
"activate",
"export-abi",
"cache",
"check",
"deploy",
"verify",
"a",
"i",
"n",
"x",
"c",
Expand Down

0 comments on commit ac00d0c

Please sign in to comment.