mirror of
https://github.com/jht5945/prettyjson.git
synced 2025-12-30 03:00:05 +08:00
modify options
This commit is contained in:
26
src/main.rs
26
src/main.rs
@@ -42,24 +42,32 @@ struct Options {
|
|||||||
file: String,
|
file: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
impl Options {
|
||||||
let mut options = Options {
|
pub fn new() -> Options {
|
||||||
|
Options {
|
||||||
version: false,
|
version: false,
|
||||||
verbose: false,
|
verbose: false,
|
||||||
replace_file: false,
|
replace_file: false,
|
||||||
tab_width: 4u16,
|
tab_width: 4u16,
|
||||||
file: String::new(),
|
file: String::new(),
|
||||||
};
|
}
|
||||||
{
|
}
|
||||||
|
|
||||||
|
pub fn parse_args(&mut self) {
|
||||||
let mut ap = ArgumentParser::new();
|
let mut ap = ArgumentParser::new();
|
||||||
ap.set_description("prettyjson - command line JSON pretty tool.");
|
ap.set_description("prettyjson - command line JSON pretty tool.");
|
||||||
ap.refer(&mut options.tab_width).add_option(&["-w", "--tab-width"], Store, "Tab width, default 4");
|
ap.refer(&mut self.tab_width).add_option(&["-w", "--tab-width"], Store, "Tab width, default 4");
|
||||||
ap.refer(&mut options.version).add_option(&["-V", "--version"], StoreTrue, "Print version");
|
ap.refer(&mut self.version).add_option(&["-V", "--version"], StoreTrue, "Print version");
|
||||||
ap.refer(&mut options.verbose).add_option(&["-v", "--verbose"], StoreTrue, "Verbose");
|
ap.refer(&mut self.verbose).add_option(&["-v", "--verbose"], StoreTrue, "Verbose");
|
||||||
ap.refer(&mut options.replace_file).add_option(&["-R", "--replace-file"], StoreTrue, "Replace file");
|
ap.refer(&mut self.replace_file).add_option(&["-R", "--replace-file"], StoreTrue, "Replace file");
|
||||||
ap.refer(&mut options.file).add_argument("FILE", Store, "FILE");
|
ap.refer(&mut self.file).add_argument("FILE", Store, "FILE");
|
||||||
ap.parse_args_or_exit();
|
ap.parse_args_or_exit();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let mut options = Options::new();
|
||||||
|
options.parse_args();
|
||||||
|
|
||||||
if options.verbose {
|
if options.verbose {
|
||||||
print_message(MessageType::DEBUG, &format!("prettyjson version: {}, git hash: {}", VERSION, GIT_HASH));
|
print_message(MessageType::DEBUG, &format!("prettyjson version: {}, git hash: {}", VERSION, GIT_HASH));
|
||||||
|
|||||||
Reference in New Issue
Block a user