Skip to content

Commit

Permalink
allow specification of custom aleo registry
Browse files Browse the repository at this point in the history
  • Loading branch information
evan-schott committed Dec 8, 2023
1 parent 015cc05 commit feaceff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
16 changes: 7 additions & 9 deletions leo/cli/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ pub struct CLI {

#[clap(long, global = true, help = "Optional path to Leo program root folder")]
path: Option<PathBuf>,

#[clap(long, global = true, help = "Optional path to aleo program registry.")]
pub home: Option<PathBuf>,
}

///Leo compiler and package manager
Expand Down Expand Up @@ -105,7 +108,7 @@ pub fn run_with_args(cli: CLI) -> Result<()> {

// Get custom root folder and create context for it.
// If not specified, default context will be created in cwd.
let context = handle_error(Context::new(cli.path));
let context = handle_error(Context::new(cli.path, cli.home));

match cli.command {
Commands::Account { command } => command.try_execute(context),
Expand Down Expand Up @@ -137,26 +140,21 @@ pub fn run_with_args(cli: CLI) -> Result<()> {
#[test]
pub fn build_nested_test() -> Result<()> {
use leo_span::symbol::create_session_if_not_set_then;
use std::env;

const BUILD_DIRECTORY: &str = "utils/tmp/nested";
const HOME_DIRECTORY: &str = "utils/tmp/.aleo/registry";

let cli = CLI {
debug: false,
quiet: false,
command: Commands::Build { command: Build { options: Default::default() } },
path: Some(PathBuf::from(BUILD_DIRECTORY)),
home: Some(PathBuf::from(HOME_DIRECTORY)),
};

// Set $HOME to tmp directory so that tests do not modify users real home directory
let original_home = env::var("HOME").unwrap();
env::set_var("HOME", "utils/tmp");

create_session_if_not_set_then(|_| {
run_with_args(cli).expect("Failed to run build command");
});

// Reset $HOME
env::set_var("HOME", original_home);

Ok(())
}
16 changes: 14 additions & 2 deletions leo/cli/helpers/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.

use super::*;
use aleo_std;
use leo_errors::{CliError, PackageError, Result};
use leo_package::build::{BuildDirectory, BUILD_DIRECTORY_NAME};

use snarkvm::file::Manifest;

use aleo_std::aleo_dir;
use std::{
env::current_dir,
fs::File,
Expand All @@ -33,11 +35,13 @@ use std::{
pub struct Context {
/// Path at which the command is called, None when default
pub path: Option<PathBuf>,
/// Path to use for the Aleo registry, None when default
pub home: Option<PathBuf>,
}

impl Context {
pub fn new(path: Option<PathBuf>) -> Result<Context> {
Ok(Context { path })
pub fn new(path: Option<PathBuf>, home: Option<PathBuf>) -> Result<Context> {
Ok(Context { path, home })
}

/// Returns the path to the Leo package.
Expand All @@ -48,6 +52,14 @@ impl Context {
}
}

/// Returns the path to the Aleo registry directory.
pub fn home(&self) -> Result<PathBuf> {
match &self.home {
Some(path) => Ok(path.clone()),
None => Ok(aleo_dir()),
}
}

/// Returns the package name as a String.
/// Opens the manifest file `program.json` and creates the build directory if it doesn't exist.
pub fn open_manifest(&self) -> Result<Manifest<CurrentNetwork>> {
Expand Down

0 comments on commit feaceff

Please sign in to comment.