Skip to content

Commit

Permalink
fix: use std::fs wherever possible
Browse files Browse the repository at this point in the history
  • Loading branch information
megatank58 authored Jun 22, 2022
1 parent 8923830 commit 047d2b6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 20 deletions.
21 changes: 15 additions & 6 deletions src/installers/linux.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::{shell_command};
use std::fs::{copy, metadata, remove_file, create_dir};
use crate::shell_command;
use regex::Regex;

pub fn install_l() {
Expand All @@ -23,12 +24,20 @@ pub fn install_l() {

println!("Unpacking release...");

shell_command("tar", vec!["-xf", "oxido*.tar.gz"]);
shell_command("tar", vec!["-xf", "oxido-linux.tar.gz"]);

println!("Moving to $HOME/.oxido...");

shell_command("mkdir", vec!["$HOME/.oxido"]);
shell_command("mv", vec!["oxido* $HOME/.oxido"]);

println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
}
copy(
"oxido",
format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()),
)
.unwrap();
remove_file("oxido").unwrap();
remove_file("oxido-linux.tar.gz").unwrap();

println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it");
}
22 changes: 15 additions & 7 deletions src/installers/macos.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{shell_command};
use std::fs::{copy, metadata, remove_file, create_dir};
use crate::shell_command;
use regex::Regex;

pub fn install_m() {
let mut s = shell_command(
"curl",
Expand All @@ -23,12 +23,20 @@ pub fn install_m() {

println!("Unpacking release...");

shell_command("unzip", vec!["oxido*.darwin.zip"]);
shell_command("unzip", vec!["oxido-darwin.zip"]);

println!("Moving to $HOME/.oxido...");

shell_command("mkdir", vec!["$HOME/.oxido"]);
shell_command("mv", vec!["oxido* $HOME/.oxido"]);

println!("Oxup installed successfully!\nRun echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc and restart your terminal to use it");
if !metadata(format!("{}/.oxido", std::env::var("HOME").unwrap())).is_ok() {
create_dir(format!("{}/.oxido", std::env::var("HOME").unwrap())).unwrap();
}
copy(
"oxido",
format!("{}/.oxido/oxido", std::env::var("HOME").unwrap()),
)
.unwrap();
remove_file("oxido").unwrap();
remove_file("oxido-darwin.zip").unwrap();

println!("Oxup installed successfully!\nRun 'echo \"export PATH=\"$HOME/.oxido:$PATH\"\" >> $HOME/.bashrc' and restart your terminal to use it");
}
2 changes: 1 addition & 1 deletion src/installers/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn install_w() {

shell_command("wget", vec![&s]);

shell_command("unzip", vec!["oxido*.gnu.zip"]);
shell_command("unzip", vec!["oxido-windows.gnu.zip"]);

shell_command("mkdir", vec![r"C:\bin"]);

Expand Down
4 changes: 1 addition & 3 deletions src/uninstallers/linux.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::shell_command;

pub fn uninstall_l() {
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap();
}
4 changes: 1 addition & 3 deletions src/uninstallers/macos.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::shell_command;

pub fn uninstall_m() {
shell_command("rm", vec!["-rf", "$HOME/.oxido/oxido"]);
std::fs::remove_file(format!("{}/.oxido/oxido", std::env::var("HOME").unwrap())).unwrap();
}

0 comments on commit 047d2b6

Please sign in to comment.