Skip to content
This repository was archived by the owner on Sep 1, 2023. It is now read-only.

Commit 57ed021

Browse files
committed
feat: add all teams commands
1 parent 1c7d532 commit 57ed021

File tree

16 files changed

+106
-89
lines changed

16 files changed

+106
-89
lines changed

src/commands.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ pub mod remove;
1010
pub mod restart;
1111
pub mod start;
1212
pub mod stop;
13-
pub mod teams;
1413
pub mod upload;
1514
use colored::Colorize;
1615
use dialoguer::{theme::ColorfulTheme, Select};
@@ -100,16 +99,19 @@ mod tests {
10099
assert_eq!(super::format_warn("Some warnings"), out)
101100
}
102101
}
103-
pub fn ask_for_app(token: String, action: &str) -> Result<u128, FetchError> {
104-
let user = crate::entities::user::fetch_user(token.clone())?;
105-
match user.apps.len() {
102+
pub fn ask_for_app(token: String, action: &str, teams: bool) -> Result<u128, FetchError> {
103+
let apps = if teams {
104+
crate::entities::app::App::fetch_foreign_apps(token)
105+
} else {
106+
crate::entities::app::App::fetch_all(token)
107+
}?;
108+
match apps.len() {
106109
0 => {
107-
err("You don't have any apps. Use `discloud up` to upload one.");
108-
std::process::exit(1)
109-
}
110-
1 => Ok(user.apps[0].parse().unwrap()),
110+
format_err("You don't have any apps!");
111+
std::process::exit(1);
112+
},
113+
1 => Ok(apps[0].id.parse().unwrap()),
111114
_ => {
112-
let apps = crate::entities::app::App::fetch_all(token)?;
113115
let options = apps
114116
.iter()
115117
.map(|app| format!("{}: ({}) {}", app.name, app.lang, app.id))

src/commands/apps.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use colored::Colorize;
22

33
use crate::entities::FetchError;
44
#[tracing::instrument]
5-
pub fn apps() {
5+
pub fn apps(teams: bool) {
66
let token = super::expect_token();
7-
match crate::entities::app::App::fetch_all(token) {
7+
match if !teams {crate::entities::app::App::fetch_all(token)} else {crate::entities::app::App::fetch_foreign_apps(token)} {
88
Ok(apps) => {
9-
println!("Your apps:");
9+
println!("{}Your apps:", if teams{"(Not) "} else {""});
1010
for app in apps {
1111
println!(
1212
"- {}: ({}) {}",

src/commands/commit.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ fn get_zip_file_path() -> PathBuf {
1616
dst_file
1717
}
1818
#[tracing::instrument]
19-
pub fn commit() {
19+
pub fn commit(teams: bool) {
2020
let token = super::expect_token();
21-
let app_id = match super::ask_for_app(token.clone(), "commit") {
21+
let app_id = match super::ask_for_app(token.clone(), "commit", teams) {
2222
Ok(app_id) => app_id,
2323
Err(error) => {
2424
super::err(&format!("Couldn't fetch apps: {}", error));
@@ -33,8 +33,8 @@ pub fn commit() {
3333
Err(e) => super::err(&format!("Failed to zip: {:?}", e)),
3434
}
3535
let mut spinner = Spinner::new(spinners::Spinners::Earth, "Committing app...".to_string());
36-
let msg = match upload_zip(token, app_id) {
37-
Ok(()) => super::format_log("Your app was successfully commited!"),
36+
let msg = match upload_zip(token, app_id, teams) {
37+
Ok(()) => if !teams {super::format_log("Your app was updated successfully!")} else {super::format_log("Your buddy's app was updated!")},
3838
Err(err) => super::format_err(&err),
3939
};
4040
spinner.stop_with_message(msg);
@@ -115,7 +115,7 @@ fn zip_dir_to_file(
115115
Ok(())
116116
}
117117
#[tracing::instrument]
118-
fn upload_zip(token: String, app_id: u128) -> Result<(), String> {
118+
fn upload_zip(token: String, app_id: u128, teams: bool) -> Result<(), String> {
119119
let file_path = get_zip_file_path();
120120
let file_path = file_path.to_str().unwrap();
121121
let client = reqwest::blocking::Client::builder()
@@ -127,7 +127,7 @@ fn upload_zip(token: String, app_id: u128) -> Result<(), String> {
127127
Err(err) => Err(format!("Couldn't open zip file: {}", err)),
128128
Ok(form) => {
129129
let req = client
130-
.put(crate::api_url!(format!("/app/{}/commit", app_id)))
130+
.put(crate::api_url!(format!("/{}/{}/commit", if teams {"team"} else {"app"}, app_id)))
131131
.multipart(form)
132132
.header("api-token", token);
133133
let res = req.send();

src/commands/logs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use spinners::{Spinner, Spinners};
22

33
#[tracing::instrument]
4-
pub fn logs() {
4+
pub fn logs(teams: bool) {
55
let token = super::expect_token();
6-
match super::ask_for_app(token.clone(), "show the logs") {
6+
match super::ask_for_app(token.clone(), "show the logs", teams) {
77
Ok(app_id) => {
88
let mut spinner = Spinner::new(Spinners::Bounce, "Downloading the logs".into());
9-
match crate::entities::app::App::get_logs(token, app_id) {
9+
match crate::entities::app::App::get_logs(token, app_id, teams) {
1010
Ok(logs) => {
1111
spinner.stop_with_message(logs);
1212
}

src/commands/mods/add.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
#[tracing::instrument]
99
pub fn add(id: u128) {
1010
let token = expect_token();
11-
let app_id = crate::handle_result!(ask_for_app(token.clone(), "add a moderator"));
11+
let app_id = crate::handle_result!(ask_for_app(token.clone(), "add a moderator", false));
1212
let mut spinner = Spinner::new(
1313
spinners::Spinners::Bounce,
1414
format!("Adding {} as a moderator", id),

src/commands/mods/allow.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ pub fn allow(id: u128, features: Vec<Feature>) {
44
let token = super::expect_token();
55
let app_id = crate::handle_result!(super::ask_for_app(
66
token.clone(),
7-
"modify the mod's permissions"
7+
"modify the mod's permissions",
8+
false
89
));
910
let mut spinner = Spinner::new(Spinners::Pong, "Adding the permissions...".into());
1011
let moderator = crate::handle_result!(crate::entities::moderator::Mod::fetch_mod(

src/commands/mods/deny.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ pub fn deny(id: u128, features: Vec<Feature>) {
1010
let token = super::expect_token();
1111
let app_id = crate::handle_result!(super::ask_for_app(
1212
token.clone(),
13-
"modify the mod's permissions"
13+
"modify the mod's permissions",
14+
false
1415
));
1516
let mut spinner = Spinner::new(Spinners::Toggle2, "Removing the permissions...".into());
1617
let moderator = crate::handle_result!(crate::entities::moderator::Mod::fetch_mod(

src/commands/mods/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{
88
#[tracing::instrument]
99
pub fn remove(id: u128) {
1010
let token = expect_token();
11-
let app_id = handle_result!(ask_for_app(token.clone(), "remove the moderator"));
11+
let app_id = handle_result!(ask_for_app(token.clone(), "remove the moderator", false));
1212
let mut spinner = Spinner::new(
1313
spinners::Spinners::Moon,
1414
format!("Sending {} to the moon", id),

src/commands/remove.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use spinners::*;
22
#[tracing::instrument]
33
pub fn remove() {
44
let token = super::expect_token();
5-
match super::ask_for_app(token.clone(), "delete") {
5+
match super::ask_for_app(token.clone(), "delete", false) {
66
Ok(app_id) => {
77
let mut spinner = Spinner::new(Spinners::Flip, "Deleting your app".into());
88
match crate::entities::app::App::delete(token, app_id) {

src/commands/restart.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use spinners::*;
22
#[tracing::instrument]
3-
pub fn restart() {
3+
pub fn restart(teams: bool) {
44
let token = super::expect_token();
5-
match super::ask_for_app(token.clone(), "restart") {
5+
match super::ask_for_app(token.clone(), "restart", teams) {
66
Ok(app_id) => {
77
let mut spinner = Spinner::new(Spinners::Earth, "Restarting your app".into());
8-
match crate::entities::app::App::restart(token, app_id) {
8+
match crate::entities::app::App::restart(token, app_id, teams) {
99
Ok(()) => {
1010
spinner.stop_with_message(super::format_log("Your app is up!"));
1111
}

0 commit comments

Comments
 (0)