diff --git a/errors/src/errors/cli/cli_errors.rs b/errors/src/errors/cli/cli_errors.rs
index 1c1e8c86cb..6ce16a05f2 100644
--- a/errors/src/errors/cli/cli_errors.rs
+++ b/errors/src/errors/cli/cli_errors.rs
@@ -116,6 +116,13 @@ create_messages!(
help: None,
}
+ @backtraced
+ failed_to_execute_aleo_deploy {
+ args: (error: impl Display),
+ msg: format!("Failed to execute the `aleo deploy` command.\nSnarkVM Error: {}", error),
+ help: None,
+ }
+
@backtraced
failed_to_parse_aleo_new {
args: (error: impl Display),
@@ -136,4 +143,11 @@ create_messages!(
msg: format!("Failed to parse the `aleo node` command.\nSnarkVM Error: {}", error),
help: None,
}
+
+ @backtraced
+ failed_to_parse_aleo_deploy {
+ args: (error: impl Display),
+ msg: format!("Failed to parse the `aleo deploy` command.\nSnarkVM Error: {}", error),
+ help: None,
+ }
);
diff --git a/leo/commands/deploy.rs b/leo/commands/deploy.rs
new file mode 100644
index 0000000000..38f6679299
--- /dev/null
+++ b/leo/commands/deploy.rs
@@ -0,0 +1,61 @@
+// Copyright (C) 2019-2022 Aleo Systems Inc.
+// This file is part of the Leo library.
+
+// The Leo library is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// The Leo library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with the Leo library. If not, see .
+
+use crate::commands::ALEO_CLI_COMMAND;
+use crate::{commands::Command, context::Context};
+use leo_errors::{CliError, PackageError, Result};
+use leo_package::build::BuildDirectory;
+
+use aleo::commands::Deploy as AleoDeploy;
+
+use clap::StructOpt;
+use tracing::span::Span;
+
+/// Deploys an Aleo program.
+#[derive(StructOpt, Debug)]
+pub struct Deploy;
+
+impl Command for Deploy {
+ type Input = ();
+ type Output = ();
+
+ fn log_span(&self) -> Span {
+ tracing::span!(tracing::Level::INFO, "Deploy")
+ }
+
+ fn prelude(&self, _: Context) -> Result {
+ Ok(())
+ }
+
+ fn apply(self, context: Context, _: Self::Input) -> Result {
+ // Open the Leo build/ directory
+ let path = context.dir()?;
+ let build_directory = BuildDirectory::open(&path).map_err(|_| CliError::needs_leo_build())?;
+
+ // Change the cwd to the Leo build/ directory to deploy aleo files.
+ std::env::set_current_dir(&build_directory)
+ .map_err(|err| PackageError::failed_to_set_cwd(build_directory.display(), err))?;
+
+ // Call the `aleo node` command from the Aleo SDK.
+ let command = AleoDeploy::try_parse_from(&[ALEO_CLI_COMMAND]).map_err(CliError::failed_to_parse_aleo_node)?;
+ let res = command.parse().map_err(CliError::failed_to_execute_aleo_node)?;
+
+ // Log the output of the `aleo node` command.
+ tracing::info!("{}", res);
+
+ Ok(())
+ }
+}
diff --git a/leo/commands/mod.rs b/leo/commands/mod.rs
index 67a9ec5188..5e08631781 100644
--- a/leo/commands/mod.rs
+++ b/leo/commands/mod.rs
@@ -21,6 +21,9 @@ pub use build::Build;
pub mod clean;
pub use clean::Clean;
+pub mod deploy;
+pub use deploy::Deploy;
+
pub mod new;
pub use new::New;
diff --git a/leo/commands/node.rs b/leo/commands/node.rs
index fad9138b7e..b83d387bad 100644
--- a/leo/commands/node.rs
+++ b/leo/commands/node.rs
@@ -43,11 +43,11 @@ impl Command for Node {
tracing::span!(tracing::Level::INFO, "Node")
}
- fn prelude(&self, _context: Context) -> Result {
+ fn prelude(&self, _: Context) -> Result {
Ok(())
}
- fn apply(self, context: Context, _input: Self::Input) -> Result {
+ fn apply(self, context: Context, _: Self::Input) -> Result {
// Compose the `aleo node` command.
let mut arguments = vec![ALEO_CLI_COMMAND.to_string()];
diff --git a/leo/main.rs b/leo/main.rs
index 68dbbed58c..891284029d 100644
--- a/leo/main.rs
+++ b/leo/main.rs
@@ -84,6 +84,12 @@ enum Commands {
},
#[structopt(subcommand)]
Node(Node),
+
+ #[structopt(about = "Deploy a program")]
+ Deploy {
+ #[structopt(flatten)]
+ command: Deploy,
+ },
}
fn set_panic_hook() {
@@ -143,12 +149,12 @@ pub fn run_with_args(cli: CLI) -> Result<()> {
let context = handle_error(Context::new(cli.path));
match cli.command {
- // CommandOpts::Init { command } => command.try_execute(context),
Commands::New { command } => command.try_execute(context),
Commands::Build { command } => command.try_execute(context),
Commands::Clean { command } => command.try_execute(context),
Commands::Run { command } => command.try_execute(context),
Commands::Node(command) => command.try_execute(context),
+ Commands::Deploy { command } => command.try_execute(context),
}
}