aboutsummaryrefslogtreecommitdiff
path: root/src/util
diff options
context:
space:
mode:
authortrinity-1686a <trinity.pointard@gmail.com>2022-05-18 22:24:09 +0200
committerAlex <alex@adnab.me>2022-05-18 22:24:09 +0200
commit64c193e3dbb536d5d3c2881bc9aebbb3e4e6272e (patch)
tree40f2b00ecaa0f1b14a1e08fbc7883c5305fe9552 /src/util
parentc692f55d5ce2c3ed08db7fbc4844debcc0aeb134 (diff)
downloadgarage-64c193e3dbb536d5d3c2881bc9aebbb3e4e6272e.tar.gz
garage-64c193e3dbb536d5d3c2881bc9aebbb3e4e6272e.zip
Add a K2V client library and CLI (#303)
lib.rs could use getting split in modules, but I'm not sure how exactly Co-authored-by: trinity-1686a <trinity@deuxfleurs.fr> Reviewed-on: https://git.deuxfleurs.fr/Deuxfleurs/garage/pulls/303 Co-authored-by: trinity-1686a <trinity.pointard@gmail.com> Co-committed-by: trinity-1686a <trinity.pointard@gmail.com>
Diffstat (limited to 'src/util')
-rw-r--r--src/util/formater.rs28
-rw-r--r--src/util/lib.rs1
2 files changed, 29 insertions, 0 deletions
diff --git a/src/util/formater.rs b/src/util/formater.rs
new file mode 100644
index 00000000..95324f9a
--- /dev/null
+++ b/src/util/formater.rs
@@ -0,0 +1,28 @@
+pub fn format_table(data: Vec<String>) {
+ let data = data
+ .iter()
+ .map(|s| s.split('\t').collect::<Vec<_>>())
+ .collect::<Vec<_>>();
+
+ let columns = data.iter().map(|row| row.len()).fold(0, std::cmp::max);
+ let mut column_size = vec![0; columns];
+
+ let mut out = String::new();
+
+ for row in data.iter() {
+ for (i, col) in row.iter().enumerate() {
+ column_size[i] = std::cmp::max(column_size[i], col.chars().count());
+ }
+ }
+
+ for row in data.iter() {
+ for (col, col_len) in row[..row.len() - 1].iter().zip(column_size.iter()) {
+ out.push_str(col);
+ (0..col_len - col.chars().count() + 2).for_each(|_| out.push(' '));
+ }
+ out.push_str(row[row.len() - 1]);
+ out.push('\n');
+ }
+
+ print!("{}", out);
+}
diff --git a/src/util/lib.rs b/src/util/lib.rs
index e83fc2e6..d8ffdd0b 100644
--- a/src/util/lib.rs
+++ b/src/util/lib.rs
@@ -8,6 +8,7 @@ pub mod config;
pub mod crdt;
pub mod data;
pub mod error;
+pub mod formater;
pub mod metrics;
pub mod persister;
pub mod sled_counter;