mirror of
https://github.com/ProvableHQ/leo.git
synced 2024-11-28 01:01:53 +03:00
adds --api argument to leo binary
This commit is contained in:
parent
4eac040178
commit
6e68444e59
@ -100,7 +100,7 @@ impl Api {
|
||||
};
|
||||
|
||||
// only one error is possible here
|
||||
let res = res.send().map_err(|_| anyhow!("Unable to connect to Aleo PM"))?;
|
||||
let res = res.send().map_err(|_| anyhow!("Unable to connect to Aleo PM. Check URL if you specified custom API endpoint"))?;
|
||||
|
||||
// where magic begins
|
||||
route.process(res)
|
||||
|
@ -48,19 +48,19 @@ impl Context {
|
||||
}
|
||||
|
||||
/// Create a new context for the current directory.
|
||||
pub fn create_context(path: PathBuf) -> Result<Context> {
|
||||
pub fn create_context(path: PathBuf, api_url: Option<String>) -> Result<Context> {
|
||||
let token = config::read_token().ok();
|
||||
|
||||
let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token);
|
||||
let api = Api::new(api_url.unwrap_or(PACKAGE_MANAGER_URL.to_string()), token);
|
||||
|
||||
Ok(Context { api, path: Some(path) })
|
||||
}
|
||||
|
||||
/// Returns project context.
|
||||
pub fn get_context() -> Result<Context> {
|
||||
pub fn get_context(api_url: Option<String>) -> Result<Context> {
|
||||
let token = config::read_token().ok();
|
||||
|
||||
let api = Api::new(PACKAGE_MANAGER_URL.to_string(), token);
|
||||
let api = Api::new(api_url.unwrap_or(PACKAGE_MANAGER_URL.to_string()), token);
|
||||
|
||||
Ok(Context { api, path: None })
|
||||
}
|
||||
|
11
leo/main.rs
11
leo/main.rs
@ -55,6 +55,13 @@ struct Opt {
|
||||
#[structopt(subcommand)]
|
||||
command: CommandOpts,
|
||||
|
||||
#[structopt(
|
||||
long,
|
||||
global = true,
|
||||
help = "Aleo PM API Url"
|
||||
)]
|
||||
api: Option<String>,
|
||||
|
||||
#[structopt(
|
||||
long,
|
||||
global = true,
|
||||
@ -192,8 +199,8 @@ fn main() {
|
||||
// Get custom root folder and create context for it.
|
||||
// If not specified, default context will be created in cwd.
|
||||
let context = handle_error(match opt.path {
|
||||
Some(path) => context::create_context(path),
|
||||
None => context::get_context(),
|
||||
Some(path) => context::create_context(path, opt.api),
|
||||
None => context::get_context(opt.api),
|
||||
});
|
||||
|
||||
handle_error(match opt.command {
|
||||
|
Loading…
Reference in New Issue
Block a user