Skip to content

Commit

Permalink
refactor files and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
santhosh-chinnasamy committed Jun 16, 2024
1 parent 64876df commit 46dd047
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 32 deletions.
32 changes: 1 addition & 31 deletions src/alias.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
use std::{
fs,
process::{exit, Command},
};
use std::{fs, process::exit};

use toml::Table;

const MACOS: &str = "open";
const LINUX: &str = "xdg-open";
const CONFIG_FOLDER: &'static str = ".config/cliq";
const CONFIG_FILE: &'static str = "cliq.toml";
const DEFAULT_CONFIG: &'static str = "
Expand All @@ -16,16 +11,6 @@ hub = \"https://github.com\"
lab = \"https://gitlab.com\"
";

fn program() -> String {
let os: &str = std::env::consts::OS;
let _program: &str = match os {
"macos" => MACOS,
_ => LINUX,
};

return _program.to_string();
}

fn config_file() -> String {
let home_dir = dirs::home_dir().unwrap().to_str().unwrap().to_string();
let cliq_config = format!("{}/{}/{}", home_dir, CONFIG_FOLDER, CONFIG_FILE);
Expand Down Expand Up @@ -80,18 +65,3 @@ pub fn link(alias: String) -> String {

return link.to_string();
}

pub fn open(url: String) {
let binding = program();
let command_name = binding.as_str();

println!("Opening {}", url);

Command::new(command_name)
.arg(url)
.spawn()
.unwrap_or_else(|_| {
eprintln!("{} command not found", command_name);
exit(127);
});
}
26 changes: 26 additions & 0 deletions src/heimdall.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use std::process::{exit, Command};

const MACOS: &str = "open";
const LINUX: &str = "xdg-open";

fn program() -> String {
let os: &str = std::env::consts::OS;
let _program: &str = match os {
"macos" => MACOS,
_ => LINUX,
};

return _program.to_string();
}

pub fn open(url: String) {
let binding = program();
let command = binding.as_str();

println!("Opening {}", url);

Command::new(command).arg(url).spawn().unwrap_or_else(|_| {
eprintln!("{} command not found", command);
exit(127);
});
}
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use clap::{Parser, Subcommand};
mod alias;
mod heimdall;

#[derive(Parser)]
#[command(name = "cliq", version, about, author, long_about = None)]
Expand Down Expand Up @@ -29,7 +30,7 @@ fn main() {
Commands::Options(args) => {
let input = args.join(" ");
let url = alias::link(input);
alias::open(url);
heimdall::open(url);
}
}
}

0 comments on commit 46dd047

Please sign in to comment.