summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Tay <sam.chong.tay@gmail.com>2020-06-06 01:34:54 -0700
committerSam Tay <sam.chong.tay@gmail.com>2020-06-06 19:56:12 -0700
commit735fd480e43d6037f3ae7890c2795fdf0e431fd7 (patch)
tree5c6992780a8cced58d4dac2775002df2416955c1
parentefb2e0908b7f71a3f6ee6678c423c72b105f99ab (diff)
Improve alignment when printing sites
-rw-r--r--TODO.md2
-rw-r--r--src/main.rs13
2 files changed, 12 insertions, 3 deletions
diff --git a/TODO.md b/TODO.md
index 380dea0..d3c904b 100644
--- a/TODO.md
+++ b/TODO.md
@@ -5,7 +5,7 @@
0. Implement --update-sites command
3. Parse markdown (`pulldown_cmark`)
4. Maybe default --validate-sites off (parsing 30k file a big hit)
-5. Print to stderr in style
+5. Print to stderr in [style](https://github.com/BurntSushi/termcolor)
### resources for later
0. [Intro to async rust](http://jamesmcm.github.io/blog/2020/05/06/a-practical-introduction-to-async-programming-in-rust/)
diff --git a/src/main.rs b/src/main.rs
index d5568cf..e9f0d99 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -17,8 +17,17 @@ fn main() {
}
if opts.list_sites {
- for s in ls.sites() {
- println!("{}: {}", s.api_site_parameter, s.site_url);
+ let sites = ls.sites();
+ match sites.into_iter().map(|s| s.api_site_parameter.len()).max() {
+ Some(max_w) => {
+ for s in ls.sites() {
+ println!("{:>w$}: {}", s.api_site_parameter, s.site_url, w = max_w);
+ }
+ }
+ None => {
+ // TODO stderr
+ println!("The site list is empty. Try running `so --update-sites`.");
+ }
}
return;
}