-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #52 from thinkgos/feature-dl
feat: add downloads manager command
- Loading branch information
Showing
7 changed files
with
167 additions
and
41 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
use clap::Args; | ||
use clap::Subcommand; | ||
use dialoguer::theme::ColorfulTheme; | ||
use dialoguer::Confirm; | ||
use goup_version::Version; | ||
|
||
use super::Run; | ||
|
||
#[derive(Args, Debug, PartialEq)] | ||
pub struct Downloads { | ||
// outputs the completion content for given shell | ||
#[command(subcommand)] | ||
command: Command, | ||
} | ||
|
||
#[derive(Subcommand, Clone, Debug, PartialEq)] | ||
enum Command { | ||
/// Show download archive file | ||
Show(Show), | ||
/// Clean download archive file | ||
Clean, | ||
} | ||
|
||
#[derive(Args, Clone, Debug, PartialEq)] | ||
struct Show { | ||
#[arg(short, long, default_value_t = false)] | ||
contain_sha256: bool, | ||
} | ||
|
||
impl Run for Downloads { | ||
fn run(&self) -> Result<(), anyhow::Error> { | ||
match self.command { | ||
Command::Show(ref show) => { | ||
Version::list_dl(Some(show.contain_sha256))? | ||
.iter() | ||
.for_each(|v| { | ||
println!("{}", v); | ||
}); | ||
} | ||
Command::Clean => { | ||
let confirmation = Confirm::with_theme(&ColorfulTheme::default()) | ||
.with_prompt("Do you want to clean archive file?") | ||
.interact()?; | ||
if confirmation { | ||
Version::remove_dl()?; | ||
} else { | ||
log::info!("Cancelled"); | ||
} | ||
} | ||
} | ||
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