mirror of
https://github.com/jht5945/prettyjson.git
synced 2025-12-29 18:30:05 +08:00
add verbose
This commit is contained in:
11
src/main.rs
11
src/main.rs
@@ -28,7 +28,7 @@ Written by Hatter Jiang
|
|||||||
"#, VERSION, &GIT_HASH[0..7]);
|
"#, VERSION, &GIT_HASH[0..7]);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn read_to_string(read: &mut Read) -> XResult<String> {
|
fn read_to_string(read: &mut dyn Read) -> XResult<String> {
|
||||||
let mut buffer = String::new();
|
let mut buffer = String::new();
|
||||||
read.read_to_string(&mut buffer)?;
|
read.read_to_string(&mut buffer)?;
|
||||||
Ok(buffer)
|
Ok(buffer)
|
||||||
@@ -36,6 +36,7 @@ fn read_to_string(read: &mut Read) -> XResult<String> {
|
|||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
version: bool,
|
version: bool,
|
||||||
|
verbose: bool,
|
||||||
replace_file: bool,
|
replace_file: bool,
|
||||||
tab_width: u16,
|
tab_width: u16,
|
||||||
file: String,
|
file: String,
|
||||||
@@ -44,6 +45,7 @@ struct Options {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let mut options = Options {
|
let mut options = Options {
|
||||||
version: false,
|
version: false,
|
||||||
|
verbose: false,
|
||||||
replace_file: false,
|
replace_file: false,
|
||||||
tab_width: 4u16,
|
tab_width: 4u16,
|
||||||
file: String::new(),
|
file: String::new(),
|
||||||
@@ -52,12 +54,17 @@ fn main() {
|
|||||||
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 options.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 options.version).add_option(&["-V", "--version"], StoreTrue, "Print version");
|
||||||
|
ap.refer(&mut options.verbose).add_option(&["-v", "--verbose"], StoreTrue, "Verbose");
|
||||||
ap.refer(&mut options.replace_file).add_option(&["-R", "--replace-file"], StoreTrue, "Replace file");
|
ap.refer(&mut options.replace_file).add_option(&["-R", "--replace-file"], StoreTrue, "Replace file");
|
||||||
ap.refer(&mut options.file).add_argument("FILE", Store, "FILE");
|
ap.refer(&mut options.file).add_argument("FILE", Store, "FILE");
|
||||||
ap.parse_args_or_exit();
|
ap.parse_args_or_exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if options.verbose {
|
||||||
|
print_message(MessageType::DEBUG, &format!("prettyjson version: {}, git hash: {}", VERSION, GIT_HASH));
|
||||||
|
}
|
||||||
|
|
||||||
if options.version {
|
if options.version {
|
||||||
print_version();
|
print_version();
|
||||||
return;
|
return;
|
||||||
|
|||||||
Reference in New Issue
Block a user