File tree Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Expand file tree Collapse file tree 2 files changed +29
-1
lines changed Original file line number Diff line number Diff line change @@ -142,3 +142,26 @@ export async function repairUser(
142
142
143
143
return user as User ;
144
144
}
145
+
146
+ /**
147
+ * Intended for use in scripts
148
+ *
149
+ * @param prompt What to ask the user
150
+ * @returns The user's input
151
+ */
152
+ export function getCommandLineInput ( prompt : string ) {
153
+ return new Promise < string > ( ( resolve ) => {
154
+ const readline = require ( "readline" ) . createInterface ( {
155
+ input : process . stdin ,
156
+ output : process . stdout ,
157
+ } ) ;
158
+
159
+ readline . question (
160
+ prompt + " " ,
161
+ ( answer : string ) => {
162
+ readline . close ( ) ;
163
+ resolve ( answer ) ;
164
+ } ,
165
+ ) ;
166
+ } ) ;
167
+ }
Original file line number Diff line number Diff line change 1
1
import CollectionId from "@/lib/client/CollectionId" ;
2
2
import { getDatabase } from "@/lib/MongoDB" ;
3
- import { repairUser } from "@/lib/Utils" ;
3
+ import { getCommandLineInput , repairUser } from "@/lib/Utils" ;
4
4
5
5
async function repairUsers ( ) {
6
6
console . log ( "Getting database..." ) ;
@@ -22,6 +22,11 @@ async function repairUsers() {
22
22
23
23
console . log ( `Found ${ users . length } incomplete users` ) ;
24
24
25
+ if ( await getCommandLineInput ( "Do you want to continue? (yes/no)" ) !== "yes" ) {
26
+ console . log ( "Exiting..." ) ;
27
+ process . exit ( 0 ) ;
28
+ }
29
+
25
30
for ( let i = 0 ; i < users . length ; i ++ ) {
26
31
const user = users [ i ] ;
27
32
console . log ( `Repairing user ${ user . _id } (${ i + 1 } /${ users . length } )` ) ;
You can’t perform that action at this time.
0 commit comments