@@ -4,7 +4,11 @@ use shuttle_admin::{
4
4
client:: Client ,
5
5
config:: get_api_key,
6
6
} ;
7
- use std:: { fmt:: Write , fs} ;
7
+ use std:: {
8
+ collections:: { hash_map:: RandomState , HashMap } ,
9
+ fmt:: Write ,
10
+ fs,
11
+ } ;
8
12
use tracing:: trace;
9
13
10
14
#[ tokio:: main]
@@ -46,6 +50,97 @@ async fn main() {
46
50
. await
47
51
. expect ( "to get a certificate challenge response" )
48
52
}
53
+ Command :: ProjectNames => {
54
+ let projects = client
55
+ . get_projects ( )
56
+ . await
57
+ . expect ( "to get list of projects" ) ;
58
+
59
+ let projects: HashMap < String , String , RandomState > = HashMap :: from_iter (
60
+ projects
61
+ . into_iter ( )
62
+ . map ( |project| ( project. project_name , project. account_name ) ) ,
63
+ ) ;
64
+
65
+ let mut res = String :: new ( ) ;
66
+
67
+ for ( project_name, account_name) in & projects {
68
+ let mut issues = Vec :: new ( ) ;
69
+ let cleaned_name = project_name. to_lowercase ( ) ;
70
+
71
+ // Were there any uppercase characters
72
+ if & cleaned_name != project_name {
73
+ // Since there were uppercase characters, will the new name clash with any existing projects
74
+ if let Some ( other_account) = projects. get ( & cleaned_name) {
75
+ if other_account == account_name {
76
+ issues. push (
77
+ "changing to lower case will clash with same owner" . to_string ( ) ,
78
+ ) ;
79
+ } else {
80
+ issues. push ( format ! (
81
+ "changing to lower case will clash with another owner: {other_account}"
82
+ ) ) ;
83
+ }
84
+ }
85
+ }
86
+
87
+ let cleaned_underscore = cleaned_name. replace ( '_' , "-" ) ;
88
+ // Were there any underscore cleanups
89
+ if cleaned_underscore != cleaned_name {
90
+ // Since there were underscore cleanups, will the new name clash with any existing projects
91
+ if let Some ( other_account) = projects. get ( & cleaned_underscore) {
92
+ if other_account == account_name {
93
+ issues
94
+ . push ( "cleaning underscore will clash with same owner" . to_string ( ) ) ;
95
+ } else {
96
+ issues. push ( format ! (
97
+ "cleaning underscore will clash with another owner: {other_account}"
98
+ ) ) ;
99
+ }
100
+ }
101
+ }
102
+
103
+ let cleaned_separator_name = cleaned_underscore. trim_matches ( '-' ) ;
104
+ // Were there any dash cleanups
105
+ if cleaned_separator_name != cleaned_underscore {
106
+ // Since there were dash cleanups, will the new name clash with any existing projects
107
+ if let Some ( other_account) = projects. get ( cleaned_separator_name) {
108
+ if other_account == account_name {
109
+ issues. push ( "cleaning dashes will clash with same owner" . to_string ( ) ) ;
110
+ } else {
111
+ issues. push ( format ! (
112
+ "cleaning dashes will clash with another owner: {other_account}"
113
+ ) ) ;
114
+ }
115
+ }
116
+ }
117
+
118
+ // Are reserved words used
119
+ match cleaned_separator_name {
120
+ "shuttleapp" | "shuttle" => issues. push ( "is a reserved name" . to_string ( ) ) ,
121
+ _ => { }
122
+ }
123
+
124
+ // Is it longer than 63 chars
125
+ if cleaned_separator_name. len ( ) > 63 {
126
+ issues. push ( "final name is too long" . to_string ( ) ) ;
127
+ }
128
+
129
+ // Only report of problem projects
130
+ if !issues. is_empty ( ) {
131
+ writeln ! ( res, "{project_name}" )
132
+ . expect ( "to write name of project name having issues" ) ;
133
+
134
+ for issue in issues {
135
+ writeln ! ( res, "\t - {issue}" ) . expect ( "to write issue with project name" ) ;
136
+ }
137
+
138
+ writeln ! ( res) . expect ( "to write a new line" ) ;
139
+ }
140
+ }
141
+
142
+ res
143
+ }
49
144
} ;
50
145
51
146
println ! ( "{res}" ) ;
0 commit comments