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 synthesize;
58pub use synthesize::LeoSynthesize;
59
60mod test;
61pub use test::LeoTest;
62
63mod update;
64pub use update::LeoUpdate;
65
66pub mod upgrade;
67pub use upgrade::LeoUpgrade;
68
69use super::*;
70use crate::cli::{helpers::context::*, query::QueryCommands};
71
72use leo_errors::{CliError, Handler, PackageError, Result};
73use snarkvm::{
74 console::network::Network,
75 prelude::{Address, Ciphertext, Plaintext, PrivateKey, Record, Value, ViewKey, block::Transaction},
76};
77
78use clap::{Args, Parser};
79use colored::Colorize;
80use dialoguer::{Confirm, theme::ColorfulTheme};
81use std::{iter, str::FromStr};
82use tracing::span::Span;
83use ureq::http::Uri;
84
85pub trait Command {
87 type Input;
91
92 type Output;
96
97 fn log_span(&self) -> Span {
102 tracing::span!(tracing::Level::INFO, "Leo")
103 }
104
105 fn prelude(&self, context: Context) -> Result<Self::Input>
107 where
108 Self: std::marker::Sized;
109
110 fn apply(self, context: Context, input: Self::Input) -> Result<Self::Output>
113 where
114 Self: std::marker::Sized;
115
116 fn execute(self, context: Context) -> Result<Self::Output>
119 where
120 Self: std::marker::Sized,
121 {
122 let input = self.prelude(context.clone())?;
123
124 let span = self.log_span();
126 let span = span.enter();
127
128 let out = self.apply(context, input);
130
131 drop(span);
132
133 out
134 }
135
136 fn try_execute(self, context: Context) -> Result<()>
140 where
141 Self: std::marker::Sized,
142 {
143 self.execute(context).map(|_| Ok(()))?
144 }
145}
146
147pub fn parse_input<N: Network>(input: &str, private_key: &PrivateKey<N>) -> Result<Value<N>> {
149 let input = input.trim();
151 if input.starts_with("record1") {
153 let view_key = ViewKey::<N>::try_from(private_key)
155 .map_err(|e| CliError::custom(format!("Failed to view key from the private key: {e}")))?;
156 Record::<N, Ciphertext<N>>::from_str(input)
158 .and_then(|ciphertext| ciphertext.decrypt(&view_key))
159 .map(Value::Record)
160 .map_err(|e| CliError::custom(format!("Failed to parse input as record: {e}")).into())
161 } else {
162 Value::from_str(input).map_err(|e| CliError::custom(format!("Failed to parse input: {e}")).into())
163 }
164}