diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/format-table/Cargo.toml | 12 | ||||
-rw-r--r-- | src/format-table/README.md | 13 | ||||
-rw-r--r-- | src/format-table/lib.rs (renamed from src/util/formater.rs) | 17 | ||||
-rw-r--r-- | src/garage/Cargo.toml | 1 | ||||
-rw-r--r-- | src/garage/admin.rs | 2 | ||||
-rw-r--r-- | src/garage/cli/cmd.rs | 2 | ||||
-rw-r--r-- | src/garage/cli/layout.rs | 2 | ||||
-rw-r--r-- | src/garage/cli/util.rs | 2 | ||||
-rw-r--r-- | src/k2v-client/Cargo.toml | 5 | ||||
-rw-r--r-- | src/k2v-client/bin/k2v-cli.rs | 2 | ||||
-rw-r--r-- | src/util/lib.rs | 1 |
11 files changed, 50 insertions, 9 deletions
diff --git a/src/format-table/Cargo.toml b/src/format-table/Cargo.toml new file mode 100644 index 00000000..b2f074d7 --- /dev/null +++ b/src/format-table/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "format_table" +version = "0.1.0" +authors = ["Alex Auvolat <alex@adnab.me>"] +edition = "2018" +license = "AGPL-3.0" +description = "Format tables with a stupid API" +repository = "https://git.deuxfleurs.fr/Deuxfleurs/garage" +readme = "README.md" + +[lib] +path = "lib.rs" diff --git a/src/format-table/README.md b/src/format-table/README.md new file mode 100644 index 00000000..d918bdf4 --- /dev/null +++ b/src/format-table/README.md @@ -0,0 +1,13 @@ +# `format_table` + +Format tables with a stupid API. [Documentation](https://docs.rs/format_table). + +Example: + +```rust +let mut table = vec!["product\tquantity\tprice".to_string()]; +for (p, q, r) in [("tomato", 12, 15), ("potato", 10, 20), ("rice", 5, 12)] { + table.push(format!("{}\t{}\t{}", p, q, r)); +} +format_table::format_table(table); +``` diff --git a/src/util/formater.rs b/src/format-table/lib.rs index 2ea53ebb..72fd10b2 100644 --- a/src/util/formater.rs +++ b/src/format-table/lib.rs @@ -1,3 +1,19 @@ +//! Format tables with a stupid API. +//! +//! Example: +//! +//! ```rust +//! let mut table = vec!["product\tquantity\tprice".to_string()]; +//! for (p, q, r) in [("tomato", 12, 15), ("potato", 10, 20), ("rice", 5, 12)] { +//! table.push(format!("{}\t{}\t{}", p, q, r)); +//! } +//! format_table::format_table(table); +//! ``` +//! +//! A table to be formatted is a `Vec<String>`, containing one string per line. +//! Table columns in each line are separated by a `\t` character. + +/// Format a table and return the result as a string. pub fn format_table_to_string(data: Vec<String>) -> String { let data = data .iter() @@ -27,6 +43,7 @@ pub fn format_table_to_string(data: Vec<String>) -> String { out } +/// Format a table and print the result to stdout. pub fn format_table(data: Vec<String>) { print!("{}", format_table_to_string(data)); } diff --git a/src/garage/Cargo.toml b/src/garage/Cargo.toml index 2b366ff1..e188cd2a 100644 --- a/src/garage/Cargo.toml +++ b/src/garage/Cargo.toml @@ -21,6 +21,7 @@ path = "tests/lib.rs" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +format_table.workspace = true garage_db.workspace = true garage_api.workspace = true garage_block.workspace = true diff --git a/src/garage/admin.rs b/src/garage/admin.rs index 34141cb2..36fdf1d0 100644 --- a/src/garage/admin.rs +++ b/src/garage/admin.rs @@ -5,11 +5,11 @@ use std::sync::Arc; use async_trait::async_trait; use serde::{Deserialize, Serialize}; +use format_table::format_table_to_string; use garage_util::background::BackgroundRunner; use garage_util::crdt::*; use garage_util::data::*; use garage_util::error::Error as GarageError; -use garage_util::formater::format_table_to_string; use garage_util::time::*; use garage_table::replication::*; diff --git a/src/garage/cli/cmd.rs b/src/garage/cli/cmd.rs index 0d735885..cb7a898c 100644 --- a/src/garage/cli/cmd.rs +++ b/src/garage/cli/cmd.rs @@ -1,8 +1,8 @@ use std::collections::HashSet; use std::time::Duration; +use format_table::format_table; use garage_util::error::*; -use garage_util::formater::format_table; use garage_rpc::layout::*; use garage_rpc::system::*; diff --git a/src/garage/cli/layout.rs b/src/garage/cli/layout.rs index 3884bb92..dc5315a1 100644 --- a/src/garage/cli/layout.rs +++ b/src/garage/cli/layout.rs @@ -1,6 +1,6 @@ +use format_table::format_table; use garage_util::crdt::Crdt; use garage_util::error::*; -use garage_util::formater::format_table; use garage_rpc::layout::*; use garage_rpc::system::*; diff --git a/src/garage/cli/util.rs b/src/garage/cli/util.rs index 2c6be2f4..7d93efe3 100644 --- a/src/garage/cli/util.rs +++ b/src/garage/cli/util.rs @@ -1,11 +1,11 @@ use std::collections::HashMap; use std::time::Duration; +use format_table::format_table; use garage_util::background::*; use garage_util::crdt::*; use garage_util::data::*; use garage_util::error::*; -use garage_util::formater::format_table; use garage_util::time::*; use garage_block::manager::BlockResyncErrorInfo; diff --git a/src/k2v-client/Cargo.toml b/src/k2v-client/Cargo.toml index 293ad8b7..4212a00a 100644 --- a/src/k2v-client/Cargo.toml +++ b/src/k2v-client/Cargo.toml @@ -23,12 +23,11 @@ tokio = { version = "1.0", default-features = false, features = ["rt", "rt-multi # cli deps clap = { version = "4.1", optional = true, features = ["derive", "env"] } -garage_util = { workspace = true, optional = true } -garage_db = { workspace = true, optional = true } +format_table = { workspace = true, optional = true } [features] -cli = ["clap", "tokio/fs", "tokio/io-std", "garage_util", "garage_db/sled"] +cli = ["clap", "tokio/fs", "tokio/io-std", "format_table"] [lib] path = "lib.rs" diff --git a/src/k2v-client/bin/k2v-cli.rs b/src/k2v-client/bin/k2v-cli.rs index e771fe26..76388752 100644 --- a/src/k2v-client/bin/k2v-cli.rs +++ b/src/k2v-client/bin/k2v-cli.rs @@ -6,7 +6,7 @@ use base64::prelude::*; use k2v_client::*; -use garage_util::formater::format_table; +use format_table::format_table; use rusoto_core::credential::AwsCredentials; use rusoto_core::Region; diff --git a/src/util/lib.rs b/src/util/lib.rs index c9110fb2..15f0f829 100644 --- a/src/util/lib.rs +++ b/src/util/lib.rs @@ -10,7 +10,6 @@ pub mod crdt; pub mod data; pub mod encode; pub mod error; -pub mod formater; pub mod forwarded_headers; pub mod metrics; pub mod migrate; |