snarkvm_debug/cli/commands/new.rs
1// Copyright (C) 2019-2023 Aleo Systems Inc.
2// This file is part of the snarkVM library.
3
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at:
7// http://www.apache.org/licenses/LICENSE-2.0
8
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use super::*;
16
17/// Create a new Aleo package.
18#[derive(Debug, Parser)]
19pub struct New {
20 /// The program name.
21 name: String,
22}
23
24impl New {
25 /// Creates an Aleo package with the specified name.
26 pub fn parse(self) -> Result<String> {
27 // Derive the program directory path.
28 let mut path = std::env::current_dir()?;
29 path.push(&self.name);
30
31 // Create the program ID from the name.
32 let id = ProgramID::<CurrentNetwork>::from_str(&format!("{}.aleo", self.name))?;
33
34 // Create the package.
35 Package::create(&path, &id)?;
36
37 // Prepare the path string.
38 let path_string = format!("(in \"{}\")", path.display());
39
40 Ok(format!("✅ Created an Aleo program '{}' {}", self.name.bold(), path_string.dimmed()))
41 }
42}