add basepath cmdline flag
this allows a basepath to be set via commandline where ncspot will place configuration and cache files. fixes #65
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -1560,6 +1560,7 @@ dependencies = [
|
||||
"failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"fern 0.5.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"librespot 0.1.0 (git+https://github.com/librespot-org/librespot.git?rev=14721f4)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
||||
@@ -22,6 +22,7 @@ directories = "1.0"
|
||||
failure = "0.1.3"
|
||||
fern = "0.5"
|
||||
futures = "0.1"
|
||||
lazy_static = "1.3.0"
|
||||
log = "0.4.0"
|
||||
#rspotify = "0.4.0"
|
||||
serde = "1.0"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use std::collections::HashMap;
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::RwLock;
|
||||
|
||||
use directories::ProjectDirs;
|
||||
|
||||
@@ -33,8 +34,17 @@ pub struct ConfigTheme {
|
||||
pub cmdline_bg: Option<String>,
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
pub static ref BASE_PATH: RwLock<Option<PathBuf>> = RwLock::new(None);
|
||||
}
|
||||
|
||||
fn proj_dirs() -> ProjectDirs {
|
||||
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths")
|
||||
match *BASE_PATH.read().expect("can't readlock BASE_PATH") {
|
||||
Some(ref basepath) => ProjectDirs::from_path(basepath.clone()).expect("invalid basepath"),
|
||||
None => {
|
||||
ProjectDirs::from("org", "affekt", "ncspot").expect("can't determine project paths")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn config_path(file: &str) -> PathBuf {
|
||||
|
||||
20
src/main.rs
20
src/main.rs
@@ -6,6 +6,8 @@ extern crate clipboard;
|
||||
extern crate directories;
|
||||
extern crate failure;
|
||||
extern crate futures;
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
extern crate librespot;
|
||||
extern crate rspotify;
|
||||
extern crate tokio;
|
||||
@@ -30,7 +32,9 @@ extern crate fern;
|
||||
extern crate rand;
|
||||
|
||||
use std::fs;
|
||||
use std::path::PathBuf;
|
||||
use std::process;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use clap::{App, Arg};
|
||||
@@ -120,12 +124,28 @@ fn main() {
|
||||
.help("Enable debug logging to the specified file")
|
||||
.takes_value(true),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("basepath")
|
||||
.short("b")
|
||||
.long("basepath")
|
||||
.value_name("PATH")
|
||||
.help("custom basepath to config/cache files")
|
||||
.takes_value(true),
|
||||
)
|
||||
.get_matches();
|
||||
|
||||
if let Some(filename) = matches.value_of("debug") {
|
||||
setup_logging(filename).expect("can't setup logging");
|
||||
}
|
||||
|
||||
if let Some(basepath) = matches.value_of("basepath") {
|
||||
let path = PathBuf::from_str(basepath).expect("invalid path");
|
||||
if !path.exists() {
|
||||
fs::create_dir(&path).expect("could not create basepath directory");
|
||||
}
|
||||
*config::BASE_PATH.write().unwrap() = Some(path);
|
||||
}
|
||||
|
||||
// Things here may cause the process to abort; we must do them before creating curses windows
|
||||
// otherwise the error message will not be seen by a user
|
||||
let cfg: ::config::Config = {
|
||||
|
||||
Reference in New Issue
Block a user