add opt.rs
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -2,19 +2,30 @@ extern crate sequoia_openpgp as openpgp;
|
|||||||
pub mod oss_util;
|
pub mod oss_util;
|
||||||
pub mod pgp_util;
|
pub mod pgp_util;
|
||||||
pub mod config_util;
|
pub mod config_util;
|
||||||
|
pub mod opt;
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
use rust_util::{
|
use rust_util::{
|
||||||
XResult,
|
XResult,
|
||||||
|
util_msg::*,
|
||||||
};
|
};
|
||||||
use config_util::*;
|
use config_util::*;
|
||||||
// use pgp_util::OpenPGPTool;
|
// use pgp_util::OpenPGPTool;
|
||||||
|
use opt::{
|
||||||
|
Options,
|
||||||
|
};
|
||||||
|
|
||||||
// https://docs.sequoia-pgp.org/sequoia_openpgp/serialize/stream/struct.Encryptor.html
|
// https://docs.sequoia-pgp.org/sequoia_openpgp/serialize/stream/struct.Encryptor.html
|
||||||
// https://gitlab.com/sequoia-pgp/sequoia/blob/master/openpgp/examples/generate-encrypt-decrypt.rs
|
// https://gitlab.com/sequoia-pgp/sequoia/blob/master/openpgp/examples/generate-encrypt-decrypt.rs
|
||||||
fn main() -> XResult<()> {
|
fn main() -> XResult<()> {
|
||||||
|
let options = Options::new_and_parse_args()?;
|
||||||
|
if options.version {
|
||||||
|
print_message(MessageType::INFO, "VERSION!!!");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
|
||||||
println!("{}", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
|
println!("{}", SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap().as_secs());
|
||||||
|
|||||||
37
src/opt.rs
Normal file
37
src/opt.rs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
use rust_util::XResult;
|
||||||
|
use argparse::{ArgumentParser, StoreTrue, Store};
|
||||||
|
|
||||||
|
pub struct Options {
|
||||||
|
pub version: bool,
|
||||||
|
pub verbose: bool,
|
||||||
|
pub config: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Options {
|
||||||
|
pub fn new() -> Options {
|
||||||
|
Options {
|
||||||
|
version: false,
|
||||||
|
verbose: false,
|
||||||
|
config: "".to_string(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn parse_args(&mut self) -> XResult<()> {
|
||||||
|
{
|
||||||
|
let mut ap = ArgumentParser::new();
|
||||||
|
ap.set_description("oss_backupd - command line OSS backup tool.");
|
||||||
|
ap.refer(&mut self.version).add_option(&["-V", "--version"], StoreTrue, "Print version");
|
||||||
|
ap.refer(&mut self.verbose).add_option(&["-v", "--verbose"], StoreTrue, "Verbose");
|
||||||
|
ap.refer(&mut self.config).add_option(&["-c", "--config"], Store, "Config file");
|
||||||
|
ap.parse_args_or_exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_and_parse_args() -> XResult<Options> {
|
||||||
|
let mut options = Options::new();
|
||||||
|
options.parse_args()?;
|
||||||
|
Ok(options)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user