leo_lang/cli/commands/
new.rs1use super::*;
18
19use leo_package::{NetworkName, Package};
20
21#[derive(Parser, Debug)]
23pub struct LeoNew {
24 #[clap(name = "NAME", help = "Set package name")]
25 pub(crate) name: String,
26 #[clap(short = 'n', long, help = "Name of the network to use", default_value = "testnet")]
27 pub(crate) network: String,
28 #[clap(
29 short = 'e',
30 long,
31 help = "Endpoint to retrieve network state from.",
32 default_value = "https://api.explorer.provable.com/v1"
33 )]
34 pub(crate) endpoint: String,
35}
36
37impl Command for LeoNew {
38 type Input = ();
39 type Output = ();
40
41 fn log_span(&self) -> Span {
42 tracing::span!(tracing::Level::INFO, "Leo")
43 }
44
45 fn prelude(&self, _: Context) -> Result<Self::Input> {
46 Ok(())
47 }
48
49 fn apply(self, context: Context, _: Self::Input) -> Result<Self::Output> {
50 let network: NetworkName = self.network.parse()?;
52
53 let package_path = context.parent_dir()?;
55
56 std::env::set_current_dir(&package_path)
58 .map_err(|err| PackageError::failed_to_set_cwd(package_path.display(), err))?;
59
60 let full_path = Package::initialize(&self.name, &package_path, network, &self.endpoint)?;
61
62 println!("Created program {} at `{}`.", self.name.bold(), full_path.display());
63
64 Ok(())
65 }
66}