Add feature for wrapping output
This commit is contained in:
parent
91a72709f8
commit
e80bf7b57d
3 changed files with 27 additions and 2 deletions
|
@ -32,6 +32,7 @@ libimagstore = { version = "0.8.0", path = "../../../lib/core/libimagstore"
|
|||
libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" }
|
||||
libimagerror = { version = "0.8.0", path = "../../../lib/core/libimagerror" }
|
||||
libimagentryview = { version = "0.8.0", path = "../../../lib/entry/libimagentryview" }
|
||||
libimagutil = { version = "0.8.0", path = "../../../lib/etc/libimagutil" }
|
||||
|
||||
[dependencies.clap]
|
||||
version = "^2.29"
|
||||
|
|
|
@ -43,7 +43,9 @@ extern crate libimagentryview;
|
|||
extern crate libimagerror;
|
||||
#[macro_use] extern crate libimagrt;
|
||||
extern crate libimagstore;
|
||||
extern crate libimagutil;
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::collections::BTreeMap;
|
||||
use std::io::Write;
|
||||
use std::io::Read;
|
||||
|
@ -82,7 +84,6 @@ fn main() {
|
|||
let view_header = rt.cli().is_present("view-header");
|
||||
let hide_content = rt.cli().is_present("not-view-content");
|
||||
|
||||
|
||||
if rt.cli().is_present("in") {
|
||||
let files = entry_ids
|
||||
.into_iter()
|
||||
|
@ -170,7 +171,19 @@ fn main() {
|
|||
|
||||
drop(files);
|
||||
} else {
|
||||
let viewer = StdoutViewer::new(view_header, !hide_content);
|
||||
let mut viewer = StdoutViewer::new(view_header, !hide_content);
|
||||
|
||||
if rt.cli().is_present("autowrap") {
|
||||
let width = rt.cli().value_of("autowrap").unwrap(); // ensured by clap
|
||||
let width = usize::from_str(width).unwrap_or_else(|e| {
|
||||
error!("Failed to parse argument to number: autowrap = {:?}",
|
||||
rt.cli().value_of("autowrap").map(String::from));
|
||||
error!("-> {:?}", e);
|
||||
::std::process::exit(1)
|
||||
});
|
||||
|
||||
viewer.wrap_at(width);
|
||||
}
|
||||
|
||||
entry_ids
|
||||
.into_iter()
|
||||
|
|
|
@ -40,6 +40,17 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
|||
.args(&["id", "entries-from-stdin"])
|
||||
.required(true))
|
||||
|
||||
.arg(Arg::with_name("autowrap")
|
||||
.long("autowrap")
|
||||
.short("w")
|
||||
.takes_value(true)
|
||||
.required(false)
|
||||
.multiple(false)
|
||||
.value_name("WIDTH")
|
||||
.default_value("80")
|
||||
.validator(::libimagutil::cli_validators::is_integer)
|
||||
.help("Automatically wrap long lines. Has only an effect when using stdout as output."))
|
||||
|
||||
.arg(Arg::with_name("view-header")
|
||||
.long("header")
|
||||
.short("h")
|
||||
|
|
Loading…
Reference in a new issue