9 files changed
+154
-48
Cargo.lock
+74
-2
@@ -166,6 +166,12 @@ version = "3.17.0"
166
source = "registry+https://github.com/rust-lang/crates.io-index"
167
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
168
169
+[[package]]
170
+name = "bytecount"
171
+version = "0.6.8"
172
+source = "registry+https://github.com/rust-lang/crates.io-index"
173
+checksum = "5ce89b21cab1437276d2650d57e971f9d548a2d9037cc231abdc0562b97498ce"
174
+
175
[[package]]
176
name = "bytes"
177
version = "1.10.1"
@@ -269,7 +275,7 @@ dependencies = [
275
"encode_unicode",
276
"libc",
277
"once_cell",
272
- "unicode-width",
278
+ "unicode-width 0.2.0",
279
"windows-sys 0.59.0",
280
]
281
@@ -817,7 +823,7 @@ dependencies = [
823
"console",
824
"number_prefix",
825
"portable-atomic",
820
- "unicode-width",
826
+ "unicode-width 0.2.0",
827
"web-time",
828
]
829
@@ -1172,6 +1178,17 @@ version = "0.1.1"
1178
source = "registry+https://github.com/rust-lang/crates.io-index"
1179
checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39"
1180
1181
+[[package]]
1182
+name = "papergrid"
1183
+version = "0.11.0"
1184
+source = "registry+https://github.com/rust-lang/crates.io-index"
1185
+checksum = "9ad43c07024ef767f9160710b3a6773976194758c7919b17e63b863db0bdf7fb"
1186
+dependencies = [
1187
+ "bytecount",
1188
+ "fnv",
1189
+ "unicode-width 0.1.14",
1190
+]
1191
+
1192
[[package]]
1193
name = "parking_lot"
1194
version = "0.12.3"
@@ -1246,6 +1263,30 @@ version = "0.2.0"
1263
source = "registry+https://github.com/rust-lang/crates.io-index"
1264
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
1265
1266
+[[package]]
1267
+name = "proc-macro-error"
1268
+version = "1.0.4"
1269
+source = "registry+https://github.com/rust-lang/crates.io-index"
1270
+checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
1271
+dependencies = [
1272
+ "proc-macro-error-attr",
1273
+ "proc-macro2",
1274
+ "quote",
1275
+ "syn 1.0.109",
1276
+ "version_check",
1277
+]
1278
+
1279
+[[package]]
1280
+name = "proc-macro-error-attr"
1281
+version = "1.0.4"
1282
+source = "registry+https://github.com/rust-lang/crates.io-index"
1283
+checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
1284
+dependencies = [
1285
+ "proc-macro2",
1286
+ "quote",
1287
+ "version_check",
1288
+]
1289
+
1290
[[package]]
1291
name = "proc-macro2"
1292
version = "1.0.95"
@@ -1632,6 +1673,7 @@ dependencies = [
1673
"smbcloud-networking-project",
1674
"smbcloud-utils",
1675
"spinners",
1676
+ "tabled",
1677
"thiserror 2.0.12",
1678
"tokio",
1679
"toml",
@@ -1828,6 +1870,30 @@ dependencies = [
1870
"libc",
1871
]
1872
1873
+[[package]]
1874
+name = "tabled"
1875
+version = "0.15.0"
1876
+source = "registry+https://github.com/rust-lang/crates.io-index"
1877
+checksum = "4c998b0c8b921495196a48aabaf1901ff28be0760136e31604f7967b0792050e"
1878
+dependencies = [
1879
+ "papergrid",
1880
+ "tabled_derive",
1881
+ "unicode-width 0.1.14",
1882
+]
1883
+
1884
+[[package]]
1885
+name = "tabled_derive"
1886
+version = "0.7.0"
1887
+source = "registry+https://github.com/rust-lang/crates.io-index"
1888
+checksum = "4c138f99377e5d653a371cdad263615634cfc8467685dfe8e73e2b8e98f44b17"
1889
+dependencies = [
1890
+ "heck 0.4.1",
1891
+ "proc-macro-error",
1892
+ "proc-macro2",
1893
+ "quote",
1894
+ "syn 1.0.109",
1895
+]
1896
+
1897
[[package]]
1898
name = "tempfile"
1899
version = "3.20.0"
@@ -2183,6 +2249,12 @@ version = "1.0.18"
2249
source = "registry+https://github.com/rust-lang/crates.io-index"
2250
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
2251
2252
+[[package]]
2253
+name = "unicode-width"
2254
+version = "0.1.14"
2255
+source = "registry+https://github.com/rust-lang/crates.io-index"
2256
+checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af"
2257
+
2258
[[package]]
2259
name = "unicode-width"
2260
version = "0.2.0"
Cargo.toml
+7
-6
@@ -16,28 +16,29 @@ clap = "4.1.6"
16
clap_mangen = "0.2.10"
17
console = "0.15.0"
18
dialoguer = "0.11.0"
19
+dirs = "5.0"
20
git2 = "0.20.1"
21
home = "0.5.4"
22
+indicatif = "0.17.11"
23
log = "0.4.14"
24
maybe-async = "0.2"
25
open = "4.0"
26
regex = "1.11"
27
+reqwest = "0.12"
28
serde = "1"
29
serde_json = "1.0.82"
30
serde_repr = "0.1"
28
-smbcloud-networking-project = { version = "0.3.0", path = "crates/smbcloud-networking-project" }
29
-smbcloud-utils = { version = "0.3.0", path = "crates/smbcloud-utils" }
31
smbcloud-model = { version = "0.3", path = "crates/smbcloud-model" }
32
smbcloud-networking = { version = "0.3", path = "crates/smbcloud-networking" }
33
+smbcloud-networking-project = { version = "0.3.0", path = "crates/smbcloud-networking-project" }
34
+smbcloud-utils = { version = "0.3.0", path = "crates/smbcloud-utils" }
35
spinners = "4.1.0"
36
+tabled = "0.15"
37
thiserror = "2.0"
34
-toml = "0.8"
38
tokio = "1.44"
39
+toml = "0.8"
40
tracing = "0.1.35"
41
tracing-bunyan-formatter = "0.3.3"
42
tracing-subscriber = "0.3.14"
43
url = "2"
44
url-builder = "0.1.1"
41
-dirs = "5.0"
42
-reqwest = "0.12"
43
-indicatif = "0.17.11"
crates/cli/Cargo.toml
+3
-2
@@ -28,10 +28,10 @@ clap_mangen = { workspace = true }
28
console = { workspace = true }
29
dialoguer = { workspace = true }
30
dirs = { workspace = true }
31
+git2 = { workspace = true }
32
home = { workspace = true }
33
indicatif = { workspace = true }
34
log = { workspace = true }
34
-git2 = { workspace = true }
35
open = { workspace = true }
36
regex = { workspace = true }
37
reqwest = { workspace = true, features = ["json"] }
@@ -43,11 +43,12 @@ smbcloud-networking = { workspace = true }
43
smbcloud-networking-project = { workspace = true }
44
smbcloud-utils = { workspace = true }
45
spinners = { workspace = true }
46
+tabled = { workspace = true }
47
thiserror = { workspace = true }
48
tokio = { workspace = true, features = ["full"] }
49
toml = { workspace = true }
50
tracing = { workspace = true, features = ["log"] }
51
tracing-bunyan-formatter = { workspace = true }
52
tracing-subscriber = { workspace = true, features = ["registry", "env-filter"] }
52
-url-builder = { workspace = true }
53
url = { workspace = true, features = ["serde"] }
54
+url-builder = { workspace = true }
crates/cli/src/project/mod.rs
+38
-31
@@ -15,6 +15,21 @@ use smbcloud_networking::environment::Environment;
15
use smbcloud_networking_project::{delete_project, get_all, get_project};
16
use spinners::Spinner;
17
use std::{fs::OpenOptions, io::Write};
18
+use tabled::{Table, Tabled};
19
+
20
+#[derive(Tabled)]
21
+struct ProjectRow {
22
+ #[tabled(rename = "ID")]
23
+ id: i32,
24
+ #[tabled(rename = "Name")]
25
+ name: String,
26
+ #[tabled(rename = "Description")]
27
+ description: String,
28
+ #[tabled(rename = "Created at")]
29
+ created_at: String,
30
+ #[tabled(rename = "Updated at")]
31
+ updated_at: String,
32
+}
33
34
pub async fn process_project(env: Environment, commands: Commands) -> Result<CommandResult> {
35
match commands {
@@ -86,7 +101,7 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
101
.interact()
102
.unwrap();
103
89
- let mut spinner = Spinner::new(
104
+ let spinner = Spinner::new(
105
spinners::Spinners::SimpleDotsScrolling,
106
succeed_message("Deleting project"),
107
);
@@ -99,21 +114,16 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
114
});
115
}
116
match delete_project(env, id).await {
102
- Ok(_) => {
103
- spinner.stop_and_persist(&succeed_symbol(), succeed_message("Done."));
104
- Ok(CommandResult {
105
- spinner: Spinner::new(
106
- spinners::Spinners::SimpleDotsScrolling,
107
- succeed_message("Loading"),
108
- ),
109
- symbol: succeed_symbol(),
110
- msg: succeed_message("Project has been deleted."),
111
- })
112
- }
113
- Err(e) => {
114
- spinner.stop_and_persist(&fail_symbol(), fail_message("Failed."));
115
- Err(anyhow!("{e}"))
116
- }
117
+ Ok(_) => Ok(CommandResult {
118
+ spinner,
119
+ symbol: succeed_symbol(),
120
+ msg: succeed_message("Done. Project has been deleted."),
121
+ }),
122
+ Err(e) => Ok(CommandResult {
123
+ spinner,
124
+ symbol: fail_symbol(),
125
+ msg: fail_message(&e.to_string()),
126
+ }),
127
}
128
}
129
Commands::Use { id } => {
@@ -157,22 +167,19 @@ pub async fn process_project(env: Environment, commands: Commands) -> Result<Com
167
// Private functions
168
169
fn show_projects(projects: Vec<Project>) {
160
- // println!("Projects: {projects:#?}");
170
if projects.is_empty() {
171
return;
172
}
164
- println!(
165
- "{0: <5} | {1: <20} | {2: <30} | {3: <20} | {4: <20}",
166
- "ID", "Name", "Description", "Created at", "Updated at"
167
- );
168
- for project in projects {
169
- println!(
170
- "{0: <5} | {1: <20} | {2: <30} | {3: <20} | {4: <20}",
171
- project.id,
172
- project.name,
173
- project.description,
174
- project.created_at.date_naive(),
175
- project.updated_at.date_naive(),
176
- );
177
- }
173
+ let rows: Vec<ProjectRow> = projects
174
+ .into_iter()
175
+ .map(|p| ProjectRow {
176
+ id: p.id,
177
+ name: p.name,
178
+ description: p.description,
179
+ created_at: p.created_at.date_naive().to_string(),
180
+ updated_at: p.updated_at.date_naive().to_string(),
181
+ })
182
+ .collect();
183
+ let table = Table::new(rows);
184
+ println!("{table}");
185
}
crates/smbcloud-model/Cargo.toml
+7
-1
@@ -8,7 +8,13 @@ license = "Apache-2.0"
8
repository = "https://github.com/smbcloudXYZ/smbcloud-cli"
9
documentation = "https://docs.smbcloud.xyz/cli"
10
keywords = ["cli", "cloud", "web2", "web3", "smbcloud"]
11
-categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
11
+categories = [
12
+ "command-line-utilities",
13
+ "command-line-interface",
14
+ "cryptography::cryptocurrencies",
15
+ "development-tools",
16
+ "wasm",
17
+]
18
readme = "README.md"
19
20
[dependencies]
crates/smbcloud-networking-project/Cargo.toml
+7
-1
@@ -8,7 +8,13 @@ license = "Apache-2.0"
8
repository = "https://github.com/smbcloudXYZ/smbcloud-cli"
9
documentation = "https://docs.smbcloud.xyz/cli"
10
keywords = ["cli", "cloud", "web2", "web3", "smbcloud"]
11
-categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
11
+categories = [
12
+ "command-line-utilities",
13
+ "command-line-interface",
14
+ "cryptography::cryptocurrencies",
15
+ "development-tools",
16
+ "wasm",
17
+]
18
readme = "README.md"
19
20
[dependencies]
crates/smbcloud-networking-project/src/lib.rs
+4
-3
@@ -1,6 +1,6 @@
1
use anyhow::{anyhow, Result};
2
use log::debug;
3
-use reqwest::Client;
3
+use reqwest::{Client, StatusCode};
4
use smbcloud_model::{
5
self,
6
project::{Project, ProjectCreate},
@@ -81,11 +81,12 @@ pub async fn delete_project(env: Environment, id: String) -> Result<()> {
81
.await?;
82
83
match response.status() {
84
- reqwest::StatusCode::OK => {
84
+ StatusCode::OK => {
85
debug!("Project deleted.");
86
Ok(())
87
}
88
- _ => Err(anyhow!("Failed to delete a project.")),
88
+ StatusCode::NOT_FOUND => Err(anyhow!("Failed to delete a project: project not found.")),
89
+ _ => Err(anyhow!("Failed to delete a project: unknown error.")),
90
}
91
}
92
crates/smbcloud-networking/Cargo.toml
+7
-1
@@ -9,7 +9,13 @@ license = "Apache-2.0"
9
repository = "https://github.com/smbcloudXYZ/smbcloud-cli"
10
documentation = "https://docs.smbcloud.xyz/cli"
11
keywords = ["cli", "cloud", "web2", "web3", "smbcloud"]
12
-categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
12
+categories = [
13
+ "command-line-utilities",
14
+ "command-line-interface",
15
+ "cryptography::cryptocurrencies",
16
+ "development-tools",
17
+ "wasm",
18
+]
19
20
[dependencies]
21
anyhow = { workspace = true }
crates/smbcloud-utils/Cargo.toml
+7
-1
@@ -8,7 +8,13 @@ license = "Apache-2.0"
8
repository = "https://github.com/smbcloudXYZ/smbcloud-cli"
9
documentation = "https://docs.smbcloud.xyz/cli"
10
keywords = ["cli", "cloud", "web2", "web3", "smbcloud"]
11
-categories = ["command-line-utilities", "command-line-interface", "cryptography::cryptocurrencies", "development-tools", "wasm"]
11
+categories = [
12
+ "command-line-utilities",
13
+ "command-line-interface",
14
+ "cryptography::cryptocurrencies",
15
+ "development-tools",
16
+ "wasm",
17
+]
18
readme = "README.md"
19
20
[dependencies]