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" }
|
libimagrt = { version = "0.8.0", path = "../../../lib/core/libimagrt" }
|
||||||
libimagerror = { version = "0.8.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.8.0", path = "../../../lib/core/libimagerror" }
|
||||||
libimagentryview = { version = "0.8.0", path = "../../../lib/entry/libimagentryview" }
|
libimagentryview = { version = "0.8.0", path = "../../../lib/entry/libimagentryview" }
|
||||||
|
libimagutil = { version = "0.8.0", path = "../../../lib/etc/libimagutil" }
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "^2.29"
|
version = "^2.29"
|
||||||
|
|
|
@ -43,7 +43,9 @@ extern crate libimagentryview;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
#[macro_use] extern crate libimagrt;
|
#[macro_use] extern crate libimagrt;
|
||||||
extern crate libimagstore;
|
extern crate libimagstore;
|
||||||
|
extern crate libimagutil;
|
||||||
|
|
||||||
|
use std::str::FromStr;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
|
@ -82,7 +84,6 @@ fn main() {
|
||||||
let view_header = rt.cli().is_present("view-header");
|
let view_header = rt.cli().is_present("view-header");
|
||||||
let hide_content = rt.cli().is_present("not-view-content");
|
let hide_content = rt.cli().is_present("not-view-content");
|
||||||
|
|
||||||
|
|
||||||
if rt.cli().is_present("in") {
|
if rt.cli().is_present("in") {
|
||||||
let files = entry_ids
|
let files = entry_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
@ -170,7 +171,19 @@ fn main() {
|
||||||
|
|
||||||
drop(files);
|
drop(files);
|
||||||
} else {
|
} 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
|
entry_ids
|
||||||
.into_iter()
|
.into_iter()
|
||||||
|
|
|
@ -40,6 +40,17 @@ pub fn build_ui<'a>(app: App<'a, 'a>) -> App<'a, 'a> {
|
||||||
.args(&["id", "entries-from-stdin"])
|
.args(&["id", "entries-from-stdin"])
|
||||||
.required(true))
|
.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")
|
.arg(Arg::with_name("view-header")
|
||||||
.long("header")
|
.long("header")
|
||||||
.short("h")
|
.short("h")
|
||||||
|
|
Loading…
Reference in a new issue