aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjakobst1n <jakob.stendahl@outlook.com>2024-06-12 16:10:00 +0200
committerjakobst1n <jakob.stendahl@outlook.com>2024-06-12 16:10:00 +0200
commit6402d53121dfff681f1a5a7e08c3580c72851eb9 (patch)
tree9670bef41dd5b5473cc7c553f40fe5dcb25d18b8
parent42456f942a086823982f638f82f5f53a09e11a09 (diff)
downloadtextgraph-6402d53121dfff681f1a5a7e08c3580c72851eb9.tar.gz
textgraph-6402d53121dfff681f1a5a7e08c3580c72851eb9.zip
Add help text
-rw-r--r--src/parseopts.rs50
-rw-r--r--tg.132
2 files changed, 54 insertions, 28 deletions
diff --git a/src/parseopts.rs b/src/parseopts.rs
index 18b314c..2615ad2 100644
--- a/src/parseopts.rs
+++ b/src/parseopts.rs
@@ -72,10 +72,24 @@ impl OptsBuilder {
/// the program exited.
macro_rules! parseopts_panic {
($progname:expr) => {
+ println!("Usage: {} [OPTIONS] [INPUTFILE]\n", $progname);
+ println!("INPUTFILE:");
+ println!(" If provided, the data will be read from the file.");
+ println!(" If not provided, data will be read from STDIN.\n");
+ println!("OPTIONS:");
+ println!(" -h, --help Show this help text");
+ println!(" See also 'man tg'");
+ println!(" -s, --silent Disable distracting elements, such as axis");
+ println!(" -b, --braille Shorthand for -t braille");
+ println!(" -a, --ascii Shorthand for -t ascii");
println!(
- "Usage: {} [-h|--height <height>] [-w|--width <width>] [-t <star|ascii|braille>]",
- $progname
+ " -t TYPE Set graph type, valid options are 'star', 'ascii' or 'braille'"
);
+ println!(" -n, --last-n N Only include N samples in plot");
+ println!(" -c, --cut Special case of --last-n, where N is set to --width");
+ println!(" -w, --width WIDTH Set desired width of graph");
+ println!(" -h, --height HEIGHT Set desired height of graph");
+ println!(" --color ENABLE Enable or disable color, valid options are 'yes' or 'no'");
std::process::exit(1);
};
}
@@ -93,7 +107,7 @@ pub fn parseopt(opts: &mut OptsBuilder, arg: &str, value: Option<String>, progna
match arg {
"t" => {
let Some(graph_type) = value else {
- println!("Missing value for {}", arg);
+ println!("Missing value for {}\n", arg);
parseopts_panic!(progname);
};
match graph_type.as_str() {
@@ -108,7 +122,7 @@ pub fn parseopt(opts: &mut OptsBuilder, arg: &str, value: Option<String>, progna
}
t => {
println!(
- "Unknown type \"{}\", valid options are \"star\", \"ascii\" and \"braille\".",
+ "Unknown type \"{}\", valid options are \"star\", \"ascii\" and \"braille\".\n",
t
);
parseopts_panic!(progname);
@@ -117,22 +131,22 @@ pub fn parseopt(opts: &mut OptsBuilder, arg: &str, value: Option<String>, progna
}
"h" | "height" => {
let Some(height) = value else {
- println!("Missing value for {}", arg);
+ println!("Missing value for {}\n", arg);
parseopts_panic!(progname);
};
let Ok(height) = usize::from_str(&height) else {
- println!("Cannot parse integer from \"{}\"", height);
+ println!("Cannot parse integer from \"{}\"\n", height);
parseopts_panic!(progname);
};
opts.height = Some(height);
}
"n" | "last-n" => {
let Some(last_n) = value else {
- println!("Missing value for {}", arg);
+ println!("Missing value for {}\n", arg);
parseopts_panic!(progname);
};
let Ok(last_n) = u64::from_str(&last_n) else {
- println!("Cannot parse integer from \"{}\"", last_n);
+ println!("Cannot parse integer from \"{}\"\n", last_n);
parseopts_panic!(progname);
};
opts.last_n = Some(last_n);
@@ -151,31 +165,37 @@ pub fn parseopt(opts: &mut OptsBuilder, arg: &str, value: Option<String>, progna
}
"color" => {
let Some(color) = value else {
- println!("Missing value for {}", arg);
+ println!("Missing value for {}\n", arg);
parseopts_panic!(progname);
};
opts.color = match color.as_str() {
"yes" => Some(true),
"no" => Some(false),
t => {
- println!("Unknown type \"{}\", valid options are \"yes\", \"no\".", t);
+ println!(
+ "Unknown type \"{}\", valid options are \"yes\", \"no\".\n",
+ t
+ );
parseopts_panic!(progname);
}
}
}
"w" | "width" => {
let Some(width) = value else {
- println!("Missing value for {}", arg);
+ println!("Missing value for {}\n", arg);
parseopts_panic!(progname);
};
let Ok(width) = usize::from_str(&width) else {
- println!("Cannot parse integer from \"{}\"", width);
+ println!("Cannot parse integer from \"{}\"\n", width);
parseopts_panic!(progname);
};
opts.width = Some(width);
}
+ "help" => {
+ parseopts_panic!(progname);
+ }
opt => {
- println!("Unknown option \"{}\"", opt);
+ println!("Unknown option \"{}\"\n", opt);
parseopts_panic!(progname);
}
}
@@ -217,7 +237,7 @@ pub fn parseopts() -> OptsBuilder {
} else {
arg_name = arg.clone();
match arg_name.as_str() {
- "widht" | "height" | "last-n" | "color" => {
+ "width" | "height" | "last-n" | "color" => {
arg_value = it.next();
}
_ => (),
@@ -243,7 +263,7 @@ pub fn parseopts() -> OptsBuilder {
}
_ => {
println!(
- "No positional argument expected at position {} (\"{}\")",
+ "No positional argument expected at position {} (\"{}\")\n",
pos_arg, arg
);
parseopts_panic!(progname);
diff --git a/tg.1 b/tg.1
index 7e983b4..0bea23f 100644
--- a/tg.1
+++ b/tg.1
@@ -2,28 +2,19 @@
.SH name
tg \- TermGraph \- Text graphing utility
.SH SYNOPSIS
-.B tg
-[-s|--silent] [-l|--last-n \fIN\fR] [-h|--height \fIN\fR] [-w|--width \fIN\fR] [-t \fItype\fR]
+.B tg [OPTIONS] [\fIinput_file\fB]
.SH DESCRIPTION
.B tg
TermGraph is a utility for graphing
.SH OPTIONS
-.IP "\fB-h, --help\fR"
+.IP "\fB--help\fR"
Display help information.
.IP "\fB-s, --silent\fR"
Disable distracting elements, such as axis and non-graph text.
-.IP "\fB-a, --ascii\fR"
-Shorthand for -t ascii, if multiple options setting mode is specified,
-the last will likely be respected.
-
-.IP "\fB-b, --braille\fR"
-Shorthand for -t braille, if multiple options setting mode is specified,
-the last will likely be respected.
-
.IP "\fB-n, --last-n\fR \fIcount\fR"
If specified, only the newest \fIcount\fR samples will be plotted.
This can be useful if you want to follow the latest state of a graph that is piped in.
@@ -32,12 +23,27 @@ This can be useful if you want to follow the latest state of a graph that is pip
This is a special case of \fB--last-n\fR. Where the number of columns
\fB--width\fI will be used for the count.
-.IP "\fB-t\fR \fItype\fR"
+.IP "\fB-a, --ascii\fR"
+Shorthand for -t ascii, if multiple options setting mode is specified,
+the last will likely be respected.
+
+.IP "\fB-b, --braille\fR"
+Shorthand for -t braille, if multiple options setting mode is specified,
+the last will likely be respected.
+
+.IP "\fB-t\fR \fIstar\fR|\fIascii\fR|\fIbraille\fR"
The type of graph to draw,
it defaults to \fBstar\fR, which is the fastest one.
-Options are \fBstar\fR, \fBascii\fR and \fBbraille\fR.
+
+\fBstar\fR
+Scatter plot using only the '*' character.
+
+\fBascii\fR
Ascii is slightly prettier to look at.
+\fBbraille\fR
+This is the most scatter-plot-ish with the highest resolution, but also the most buggy.
+
.IP "\fB-w, --width\fR \fIwidth\fR"
Specify a width for the output.
If not specified, it will attempt to determine the TTY width and use that.