Skip to content

Commit

Permalink
Add a way to force installing the last version from the main branch o…
Browse files Browse the repository at this point in the history
…f the GitHub repository
  • Loading branch information
Sellig6792 committed Aug 26, 2023
1 parent 291cb95 commit e1880fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ pub struct Cli {
// Update option (if no path is given)
#[arg(short = 'U', long = "update", help = "Update the program")]
pub update: bool,

#[arg(long= "update-force", help="Force to install the last version from the main branch of the Github repository ", visible_aliases=["uf", "fu", "force-update"])]
pub update_force: bool,
}

pub fn run(path: &path::PathBuf, optimize: bool) -> Result<(), Box<dyn std::error::Error>> {
Expand Down
4 changes: 2 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

let args = Cli::parse();

if args.update {
update::update()?;
if args.update || args.update_force {
update::update(args.update_force)?;
} else if let Some(path) = args.path {
cli::run(&path, args.optimize)?;
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use colored::Colorize;
use reqwest::header::{HeaderMap, HeaderValue, USER_AGENT};
use serde_json::Value;
use std::io::Write;
use std::ops::Not;
use std::{env, fs};

use crate::version::Version;
Expand Down Expand Up @@ -45,7 +46,7 @@ fn get_api_json(endpoint: &str) -> Value {
json
}

pub fn update() -> Result<(), Box<dyn std::error::Error>> {
pub fn update(force_update: bool) -> Result<(), Box<dyn std::error::Error>> {
#[cfg(not(fuckbf_updatable))]
{
println!(
Expand All @@ -66,7 +67,7 @@ pub fn update() -> Result<(), Box<dyn std::error::Error>> {
.unwrap(),
);
let current_version = Version::parse(env!("CARGO_PKG_VERSION"));
if current_version >= version {
if current_version >= version && force_update.not() {
println!(" {} up-to-date", "Already".green().bold());
std::process::exit(0);
}
Expand Down

0 comments on commit e1880fd

Please sign in to comment.