impl leo deploy

This commit is contained in:
collin 2022-08-29 10:15:06 +02:00
parent 0d039bfa3f
commit 99d73a6010
5 changed files with 87 additions and 3 deletions

View File

@ -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,
}
);

61
leo/commands/deploy.rs Normal file
View File

@ -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 <https://www.gnu.org/licenses/>.
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<Self::Input> {
Ok(())
}
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
// 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(())
}
}

View File

@ -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;

View File

@ -43,11 +43,11 @@ impl Command for Node {
tracing::span!(tracing::Level::INFO, "Node")
}
fn prelude(&self, _context: Context) -> Result<Self::Input> {
fn prelude(&self, _: Context) -> Result<Self::Input> {
Ok(())
}
fn apply(self, context: Context, _input: Self::Input) -> Result<Self::Output> {
fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
// Compose the `aleo node` command.
let mut arguments = vec![ALEO_CLI_COMMAND.to_string()];

View File

@ -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),
}
}