Use full path in config file
This commit is contained in:
parent
05f9b135da
commit
5ac60c85d6
10
README.md
10
README.md
|
@ -8,7 +8,7 @@ without needing a browser.
|
|||
It doesn't support icons or much of anything else right now.
|
||||
|
||||
A configuration file will be stored in `~/.config/tinymark/tinymark.toml`
|
||||
By default the database will be stored in `~/.local/share/tinymark`
|
||||
By default the databases will be stored in `~/.local/share/tinymark`
|
||||
|
||||
## Using
|
||||
List stored bookmarks:
|
||||
|
@ -34,3 +34,11 @@ Any command that returns a Bookmark will return a JSON serialized object of it.
|
|||
|
||||
Otherwise it will return a 'status' key of value 'success' or 'fail',
|
||||
along with a 'reason' value with a full-length output.
|
||||
|
||||
## Configuration
|
||||
There is only one configuration file, stored as a TOML file.
|
||||
The valid fields are:
|
||||
|
||||
`json`: Manually specify to output as JSON. Set to `true` or `false`
|
||||
|
||||
`storage_location`: The full path for where to store the databases.
|
||||
|
|
|
@ -115,16 +115,17 @@ pub fn env_err(json: bool, e: VarError) {
|
|||
}
|
||||
|
||||
pub fn export(file_path: PathBuf, json: bool, path: Option<PathBuf>) {
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": "unsupported command",
|
||||
}));
|
||||
} else {
|
||||
let file = match File::create(&file_path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": e.to_string(),
|
||||
}));
|
||||
} else {
|
||||
warn!("error opening file! {}", e);
|
||||
}
|
||||
std::process::exit(exitcode::DATAERR);
|
||||
},
|
||||
};
|
||||
|
@ -134,23 +135,29 @@ pub fn export(file_path: PathBuf, json: bool, path: Option<PathBuf>) {
|
|||
Some(bookmarks) => serde_json::to_writer(writer, &bookmarks).unwrap(),
|
||||
None => std::process::exit(exitcode::IOERR),
|
||||
}
|
||||
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "success",
|
||||
"reason": format!("exported bookmarks to {}", file_path.to_str().unwrap()),
|
||||
}));
|
||||
} else {
|
||||
info!("Succesfully exported bookmarks to {}!", file_path.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
|
||||
pub fn import(file_path: PathBuf, json: bool, store_path: Option<PathBuf>) {
|
||||
match json {
|
||||
true => {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": "unsupported command",
|
||||
}));
|
||||
},
|
||||
false => {
|
||||
let file = match File::open(&file_path) {
|
||||
Ok(f) => f,
|
||||
Err(e) => {
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": e.to_string(),
|
||||
}));
|
||||
} else {
|
||||
warn!("error opening file! {}", e);
|
||||
}
|
||||
std::process::exit(exitcode::DATAERR);
|
||||
}
|
||||
};
|
||||
|
@ -159,14 +166,26 @@ pub fn import(file_path: PathBuf, json: bool, store_path: Option<PathBuf>) {
|
|||
let bookmarks: Vec<Bookmark> = match serde_json::from_reader(reader) {
|
||||
Ok(contents) => contents,
|
||||
Err(e) => {
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": e.to_string(),
|
||||
}));
|
||||
} else {
|
||||
warn!("error serializing file! {}", e);
|
||||
}
|
||||
std::process::exit(exitcode::DATAERR);
|
||||
}
|
||||
};
|
||||
|
||||
database::insert_multiple(&bookmarks, json, store_path);
|
||||
info!("succesfully imported bookmarks from {}!", file_path.to_str().unwrap());
|
||||
|
||||
},
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "success",
|
||||
"reason": format!("imported bookmarks from {}", file_path.to_str().unwrap()),
|
||||
}));
|
||||
} else {
|
||||
info!("succesfully imported bookmarks from {}!", file_path.to_str().unwrap());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ fn open_database(json: bool, path: Option<PathBuf>) -> Option<sled::Db> {
|
|||
let mut tmp_path = PathBuf::new();
|
||||
tmp_path.push(val);
|
||||
tmp_path.push(".local/share/tinymark");
|
||||
tmp_path.push("bookmarks_db");
|
||||
tmp_path
|
||||
},
|
||||
Err(e) => {
|
||||
|
@ -74,8 +75,21 @@ pub fn insert_multiple(entries: &Vec<Bookmark>, json: bool, path: Option<PathBuf
|
|||
}
|
||||
|
||||
match db.apply_batch(batch) {
|
||||
Ok(_) => info!("succesfully applied batch insert"),
|
||||
Err(e) => warn!("error in applying batch insert: {}", e),
|
||||
Ok(_) => {
|
||||
if !json {
|
||||
info!("succesfully applied batch insert");
|
||||
}
|
||||
},
|
||||
Err(e) => {
|
||||
if json {
|
||||
println!("{}", json!({
|
||||
"status": "fail",
|
||||
"reason": e.to_string(),
|
||||
}));
|
||||
} else {
|
||||
warn!("error in applying batch insert: {}", e);
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -31,31 +31,12 @@ fn main() {
|
|||
json = args.json;
|
||||
}
|
||||
|
||||
let storage_path: Option<PathBuf> = match &cfg.storage_location {
|
||||
Some(path) => {
|
||||
let HOME = env::var("HOME");
|
||||
match HOME {
|
||||
Ok(val) => {
|
||||
let mut new_path = PathBuf::new();
|
||||
new_path.push(val);
|
||||
new_path.push(path);
|
||||
Some(new_path)
|
||||
},
|
||||
Err(e) => {
|
||||
commands::env_err(json, e);
|
||||
None
|
||||
},
|
||||
}
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
|
||||
match &args.command {
|
||||
Commands::Add { url, name, description, tags } => commands::add(url, name, description, tags, json, storage_path),
|
||||
Commands::Edit { url } => commands::edit(json, url, storage_path),
|
||||
Commands::Delete { url } => database::remove_entry(url, json, storage_path),
|
||||
Commands::List { } => commands::list(json, storage_path),
|
||||
Commands::Export { file } => commands::export(file.to_path_buf(), json, storage_path),
|
||||
Commands::Import { file } => commands::import(file.to_path_buf(), json, storage_path),
|
||||
Commands::Add { url, name, description, tags } => commands::add(url, name, description, tags, json, cfg.storage_location),
|
||||
Commands::Edit { url } => commands::edit(json, url, cfg.storage_location),
|
||||
Commands::Delete { url } => database::remove_entry(url, json, cfg.storage_location),
|
||||
Commands::List { } => commands::list(json, cfg.storage_location),
|
||||
Commands::Export { file } => commands::export(file.to_path_buf(), json, cfg.storage_location),
|
||||
Commands::Import { file } => commands::import(file.to_path_buf(), json, cfg.storage_location),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl fmt::Display for Bookmark {
|
|||
None => do_nothing(),
|
||||
};
|
||||
|
||||
print!("[");
|
||||
print!("Tags: [");
|
||||
for i in &self.tags {
|
||||
print!("{},", i);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue