mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 12:12:00 -06:00
Fmt
This commit is contained in:
parent
a32d3aef87
commit
54018f9773
3 changed files with 18 additions and 7 deletions
|
|
@ -68,7 +68,12 @@ impl Execute for Download {
|
||||||
fn pre_check(&self) -> Result<()> {
|
fn pre_check(&self) -> Result<()> {
|
||||||
if has_ffmpeg() {
|
if has_ffmpeg() {
|
||||||
debug!("FFmpeg detected")
|
debug!("FFmpeg detected")
|
||||||
} else if PathBuf::from(&self.output).extension().unwrap_or_default().to_string_lossy() != "ts" {
|
} else if PathBuf::from(&self.output)
|
||||||
|
.extension()
|
||||||
|
.unwrap_or_default()
|
||||||
|
.to_string_lossy()
|
||||||
|
!= "ts"
|
||||||
|
{
|
||||||
bail!("File extension is not '.ts'. If you want to use a custom file format, please install ffmpeg")
|
bail!("File extension is not '.ts'. If you want to use a custom file format, please install ffmpeg")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,13 @@ use std::{env, fs};
|
||||||
mod cli;
|
mod cli;
|
||||||
mod utils;
|
mod utils;
|
||||||
|
|
||||||
pub use cli::{archive::Archive, download::Download, login::Login};
|
pub use cli::{archive::Archive, download::Download, login::Login, search::Search};
|
||||||
|
|
||||||
#[async_trait::async_trait(?Send)]
|
#[async_trait::async_trait(?Send)]
|
||||||
trait Execute {
|
trait Execute {
|
||||||
fn pre_check(&self) -> Result<()> { Ok(()) }
|
fn pre_check(&self) -> Result<()> {
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
async fn execute(self, ctx: Context) -> Result<()>;
|
async fn execute(self, ctx: Context) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -57,6 +59,7 @@ enum Command {
|
||||||
Archive(Archive),
|
Archive(Archive),
|
||||||
Download(Download),
|
Download(Download),
|
||||||
Login(Login),
|
Login(Login),
|
||||||
|
Search(Search),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Parser)]
|
#[derive(Debug, Parser)]
|
||||||
|
|
@ -153,7 +156,7 @@ pub async fn cli_entrypoint() {
|
||||||
debug!("Created ctrl-c handler");
|
debug!("Created ctrl-c handler");
|
||||||
|
|
||||||
match cli.command {
|
match cli.command {
|
||||||
Command::Archive(archive) => execute_executor(archive,ctx).await,
|
Command::Archive(archive) => execute_executor(archive, ctx).await,
|
||||||
Command::Download(download) => execute_executor(download, ctx).await,
|
Command::Download(download) => execute_executor(download, ctx).await,
|
||||||
Command::Login(login) => {
|
Command::Login(login) => {
|
||||||
if login.remove {
|
if login.remove {
|
||||||
|
|
@ -162,6 +165,7 @@ pub async fn cli_entrypoint() {
|
||||||
execute_executor(login, ctx).await
|
execute_executor(login, ctx).await
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Command::Search(search) => execute_executor(search, ctx).await,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
|
||||||
let ext = path.extension().unwrap().to_string_lossy();
|
let ext = path.extension().unwrap().to_string_lossy();
|
||||||
let mut filename = path.file_stem().unwrap().to_str().unwrap();
|
let mut filename = path.file_stem().unwrap().to_str().unwrap();
|
||||||
|
|
||||||
if filename.ends_with(&format!(" ({})", i-1)) {
|
if filename.ends_with(&format!(" ({})", i - 1)) {
|
||||||
filename = filename.strip_suffix(&format!(" ({})", i-1)).unwrap();
|
filename = filename.strip_suffix(&format!(" ({})", i - 1)).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
|
path.set_file_name(format!("{} ({}).{}", filename, i, ext))
|
||||||
|
|
@ -55,5 +55,7 @@ pub fn free_file(mut path: PathBuf) -> PathBuf {
|
||||||
|
|
||||||
/// Sanitizes the given path to not contain any invalid file character.
|
/// Sanitizes the given path to not contain any invalid file character.
|
||||||
pub fn sanitize_file(path: PathBuf) -> PathBuf {
|
pub fn sanitize_file(path: PathBuf) -> PathBuf {
|
||||||
path.with_file_name(sanitize_filename::sanitize(path.file_name().unwrap().to_string_lossy()))
|
path.with_file_name(sanitize_filename::sanitize(
|
||||||
|
path.file_name().unwrap().to_string_lossy(),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue