Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cli): add
lagon link
command (#275)
- Loading branch information
Showing
5 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@lagon/cli': minor | ||
--- | ||
|
||
Add `lagon link` command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use anyhow::{anyhow, Result}; | ||
use std::path::PathBuf; | ||
|
||
use dialoguer::Select; | ||
|
||
use crate::{ | ||
commands::deploy::{FunctionsResponse, OrganizationsResponse}, | ||
utils::{ | ||
debug, get_function_config, success, validate_code_file, write_function_config, Config, | ||
DeploymentConfig, TrpcClient, | ||
}, | ||
}; | ||
|
||
pub async fn link(file: PathBuf) -> Result<()> { | ||
let config = Config::new()?; | ||
|
||
if config.token.is_none() { | ||
return Err(anyhow!( | ||
"You are not logged in. Please login with `lagon login`", | ||
)); | ||
} | ||
|
||
validate_code_file(&file)?; | ||
|
||
match get_function_config(&file)? { | ||
None => { | ||
println!("{}", debug("No deployment config found...")); | ||
println!(); | ||
|
||
let trpc_client = TrpcClient::new(&config); | ||
let response = trpc_client | ||
.query::<(), OrganizationsResponse>("organizationsList", None) | ||
.await?; | ||
let organizations = response.result.data; | ||
|
||
let index = Select::new().items(&organizations).default(0).interact()?; | ||
let organization = &organizations[index]; | ||
|
||
let response = trpc_client | ||
.query::<(), FunctionsResponse>("functionsList", None) | ||
.await?; | ||
|
||
let index = Select::new() | ||
.items(&response.result.data) | ||
.default(0) | ||
.interact()?; | ||
let function = &response.result.data[index]; | ||
|
||
write_function_config( | ||
&file, | ||
DeploymentConfig { | ||
function_id: function.id.clone(), | ||
organization_id: organization.id.clone(), | ||
}, | ||
)?; | ||
|
||
println!("{}", success("Function linked!")); | ||
println!(); | ||
|
||
Ok(()) | ||
} | ||
Some(_) => Err(anyhow!("This file is already linked to a Function.")), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
mod build; | ||
mod deploy; | ||
mod dev; | ||
mod link; | ||
mod login; | ||
mod logout; | ||
mod rm; | ||
|
||
pub use build::build; | ||
pub use deploy::deploy; | ||
pub use dev::dev; | ||
pub use link::link; | ||
pub use login::login; | ||
pub use logout::logout; | ||
pub use rm::rm; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters