Add separate utils module
This commit is contained in:
parent
1aa85bd989
commit
faf0f30d36
28
src/main.rs
28
src/main.rs
|
@ -5,7 +5,6 @@
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
use std::io::{self, Write};
|
use std::io::{self, Write};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::process::exit;
|
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
use time_format::strftime_utc;
|
use time_format::strftime_utc;
|
||||||
|
|
||||||
|
@ -15,20 +14,8 @@ mod datasets;
|
||||||
use datasets::*;
|
use datasets::*;
|
||||||
mod sync;
|
mod sync;
|
||||||
use sync::*;
|
use sync::*;
|
||||||
|
mod util;
|
||||||
const SECS_IN_HR: u64 = 3600;
|
use util::*;
|
||||||
const SECS_IN_DAY: u64 = SECS_IN_HR * 24;
|
|
||||||
const SECS_IN_WEEK: u64 = SECS_IN_DAY * 7;
|
|
||||||
|
|
||||||
pub fn error(msg: &str, code: i32) -> ! {
|
|
||||||
println!("\nERROR: {}", msg);
|
|
||||||
exit(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn issue(msg: &str, code: i32) -> ! {
|
|
||||||
println!("\n{}", msg);
|
|
||||||
exit(code)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// ## CLI Structs
|
/// ## CLI Structs
|
||||||
|
|
||||||
|
@ -190,17 +177,6 @@ fn dataset_list() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_string() -> String {
|
|
||||||
let mut line = String::new();
|
|
||||||
io::stdout()
|
|
||||||
.flush()
|
|
||||||
.unwrap_or_else(|_| error("Could not access stdout", 2));
|
|
||||||
io::stdin()
|
|
||||||
.read_line(&mut line)
|
|
||||||
.unwrap_or_else(|_| error("Could not read from stdin", 2));
|
|
||||||
line.trim().to_owned()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn dataset_new(name: Option<String>, auth_token: Option<String>) {
|
fn dataset_new(name: Option<String>, auth_token: Option<String>) {
|
||||||
let config_dir = dirs::config_dir().expect("Could not determine config directory");
|
let config_dir = dirs::config_dir().expect("Could not determine config directory");
|
||||||
|
|
||||||
|
|
27
src/util.rs
Normal file
27
src/util.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use std::io::{self, Write};
|
||||||
|
use std::process::exit;
|
||||||
|
|
||||||
|
pub const SECS_IN_HR: u64 = 3600;
|
||||||
|
pub const SECS_IN_DAY: u64 = SECS_IN_HR * 24;
|
||||||
|
pub const SECS_IN_WEEK: u64 = SECS_IN_DAY * 7;
|
||||||
|
|
||||||
|
pub fn error(msg: &str, code: i32) -> ! {
|
||||||
|
println!("\nERROR: {}", msg);
|
||||||
|
exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn issue(msg: &str, code: i32) -> ! {
|
||||||
|
println!("\n{}", msg);
|
||||||
|
exit(code)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn read_string() -> String {
|
||||||
|
let mut line = String::new();
|
||||||
|
io::stdout()
|
||||||
|
.flush()
|
||||||
|
.unwrap_or_else(|_| error("Could not access stdout", 2));
|
||||||
|
io::stdin()
|
||||||
|
.read_line(&mut line)
|
||||||
|
.unwrap_or_else(|_| error("Could not read from stdin", 2));
|
||||||
|
line.trim().to_owned()
|
||||||
|
}
|
Loading…
Reference in a new issue