-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add ability to get workspace by name and clear workspaces. as well as…
… cli param for --remote on list workspaces
- Loading branch information
Showing
11 changed files
with
268 additions
and
37 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
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,66 @@ | ||
use async_trait::async_trait; | ||
use clap::{ArgMatches, Command}; | ||
|
||
use dialoguer::Confirm; | ||
use liboxen::api; | ||
use liboxen::{error::OxenError, model::LocalRepository}; | ||
|
||
use crate::cmd::RunCmd; | ||
pub const NAME: &str = "clear"; | ||
pub struct WorkspaceClearCmd; | ||
|
||
#[async_trait] | ||
impl RunCmd for WorkspaceClearCmd { | ||
fn name(&self) -> &str { | ||
NAME | ||
} | ||
|
||
fn args(&self) -> Command { | ||
Command::new(NAME).about("Clears all workspaces").arg( | ||
clap::Arg::new("remote") | ||
.short('r') | ||
.long("remote") | ||
.help("Remote repository name") | ||
.required(false), | ||
) | ||
} | ||
|
||
async fn run(&self, args: &ArgMatches) -> Result<(), OxenError> { | ||
let repository = LocalRepository::from_current_dir()?; | ||
let remote_name = args.get_one::<String>("remote"); | ||
let remote_repo = match remote_name { | ||
Some(name) => { | ||
let remote = repository | ||
.get_remote(name) | ||
.ok_or(OxenError::remote_not_set(name))?; | ||
api::client::repositories::get_by_remote(&remote) | ||
.await? | ||
.ok_or(OxenError::remote_not_found(remote))? | ||
} | ||
None => api::client::repositories::get_default_remote(&repository).await?, | ||
}; | ||
|
||
match Confirm::new() | ||
.with_prompt(format!( | ||
"Are you sure you want to clear all workspaces for remote: {}?", | ||
remote_repo.name | ||
)) | ||
.interact() | ||
{ | ||
Ok(true) => { | ||
api::client::workspaces::clear(&remote_repo).await?; | ||
println!("All workspaces cleared"); | ||
} | ||
Ok(false) => { | ||
return Ok(()); | ||
} | ||
Err(e) => { | ||
return Err(OxenError::basic_str(format!( | ||
"Error confirming deletion: {e}" | ||
))); | ||
} | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
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
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
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
Oops, something went wrong.