leo_lang/cli/commands/
mod.rs1mod add;
18pub use add::{DependencySource, LeoAdd};
19
20mod account;
21pub use account::Account;
22
23mod build;
24pub use build::LeoBuild;
25
26mod clean;
27pub use clean::LeoClean;
28
29mod common;
30pub use common::*;
31
32mod debug;
33pub use debug::LeoDebug;
34
35mod deploy;
36pub use deploy::LeoDeploy;
37use deploy::{Task, print_deployment_plan, print_deployment_stats};
38
39mod devnet;
40pub use devnet::LeoDevnet;
41
42mod execute;
43pub use execute::LeoExecute;
44
45pub mod query;
46pub use query::LeoQuery;
47
48mod new;
49pub use new::LeoNew;
50
51mod remove;
52pub use remove::LeoRemove;
53
54mod run;
55pub use run::LeoRun;
56
57mod test;
58pub use test::LeoTest;
59
60mod update;
61pub use update::LeoUpdate;
62
63pub mod upgrade;
64pub use upgrade::LeoUpgrade;
65
66use super::*;
67use crate::cli::{helpers::context::*, query::QueryCommands};
68
69use leo_errors::{CliError, Handler, PackageError, Result};
70use snarkvm::{
71 console::network::Network,
72 prelude::{Address, Ciphertext, Plaintext, PrivateKey, Record, Value, ViewKey, block::Transaction},
73};
74
75use clap::{Args, Parser};
76use colored::Colorize;
77use dialoguer::{Confirm, theme::ColorfulTheme};
78use std::{iter, str::FromStr};
79use tracing::span::Span;
80use ureq::http::Uri;
81
82pub trait Command {
84 type Input;
88
89 type Output;
93
94 fn log_span(&self) -> Span {
99 tracing::span!(tracing::Level::INFO, "Leo")
100 }
101
102 fn prelude(&self, context: Context) -> Result<Self::Input>
104 where
105 Self: std::marker::Sized;
106
107 fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output>
110 where
111 Self: std::marker::Sized;
112
113 fn execute(self, context: Context) -> Result<Self::Output>
116 where
117 Self: std::marker::Sized,
118 {
119 let input = self.prelude(context.clone())?;
120
121 let span = self.log_span();
123 let span = span.enter();
124
125 let out = self.apply(context, input);
127
128 drop(span);
129
130 out
131 }
132
133 fn try_execute(self, context: Context) -> Result<()>
137 where
138 Self: std::marker::Sized,
139 {
140 self.execute(context).map(|_| Ok(()))?
141 }
142}
143
144pub fn parse_input<N: Network>(input: &str, private_key: &PrivateKey<N>) -> Result<Value<N>> {
146 let input = input.trim();
148 if input.starts_with("record1") {
150 let view_key = ViewKey::<N>::try_from(private_key)
152 .map_err(|e| CliError::custom(format!("Failed to view key from the private key: {e}")))?;
153 Record::<N, Ciphertext<N>>::from_str(input)
155 .and_then(|ciphertext| ciphertext.decrypt(&view_key))
156 .map(Value::Record)
157 .map_err(|e| CliError::custom(format!("Failed to parse input as record: {e}")).into())
158 } else {
159 Value::from_str(input).map_err(|e| CliError::custom(format!("Failed to parse input: {e}")).into())
160 }
161}