Skip to content

Commit

Permalink
added upgrade feature
Browse files Browse the repository at this point in the history
  • Loading branch information
KCaverly committed Dec 21, 2022
1 parent 6b1364a commit a8e64ac
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,48 @@ mod projects;
mod tmux;

use clap::{Parser, Subcommand};
use std::io;
use std::process::{Command, Stdio};
use std::str;

#[derive(Parser)]
#[clap(about, version, author)]
struct Value {
#[clap(subcommand)]
command: Commands,
commands: Commands,
}

#[derive(Subcommand)]
enum Commands {
/// Run projects fuzzy finder
Projects {},
/// Upgrade peaches to latest version available on github
Upgrade {},
}

fn run_upgrade() {
println!("Getting new install script from peaches repository.\n");

let get_script = Command::new("wget")
.args(vec![
"https://raw.githubusercontent.com/KCaverly/peaches/main/install.sh",
"-O",
"-",
])
.stdout(Stdio::piped())
.spawn()
.unwrap();

println!("Installing new version of peaches\n");

let install_script = Command::new("sh")
.stdin(Stdio::from(get_script.stdout.unwrap()))
.spawn()
.unwrap();

let output = install_script.wait_with_output().unwrap();
let result = str::from_utf8(&output.stdout).unwrap();
println!("{}", result);
}

fn run_projects() {
Expand All @@ -32,9 +62,12 @@ fn run_projects() {
fn main() {
let value = Value::parse();

match &value.command {
match &value.commands {
Commands::Projects {} => {
run_projects();
}
Commands::Upgrade {} => {
run_upgrade();
}
}
}

0 comments on commit a8e64ac

Please sign in to comment.