@@ -31,6 +31,7 @@ import {
31
31
ViewerDocument ,
32
32
} from "./paperspace-graphql.ts" ;
33
33
import * as project from "./projects/index.ts" ;
34
+ import { pollCmd } from "./poll.ts" ;
34
35
35
36
const DOCS_ENDPOINT = "https://docs.paperspace.com" ;
36
37
144
145
this . showHelp ( ) ;
145
146
} ) ;
146
147
147
- /**
148
- * Notebooks
149
- */
150
- cli
151
- . command (
152
- "notebook, nb" ,
153
- new Command ( )
154
- . command ( "init" )
155
- . action ( ( ) => {
156
- console . log ( "init" ) ;
157
- } )
158
- . command ( "create" )
159
- . action ( act . ifLoggedIn ( ( ) => {
160
- console . log ( "create" ) ;
161
- return { value : "" } ;
162
- } ) )
163
- . command ( "update" )
164
- . action ( act . ifLoggedIn ( ( ) => {
165
- console . log ( "update" ) ;
166
- return { value : "" } ;
167
- } ) )
168
- . command ( "delete" )
169
- . action ( act . ifLoggedIn ( ( ) => {
170
- console . log ( "delete" ) ;
171
- return { value : "" } ;
172
- } ) )
173
- . command ( "list" )
174
- . action ( act . ifLoggedIn ( ( ) => {
175
- console . log ( "list" ) ;
176
- return { value : "" } ;
177
- } ) )
178
- . command ( "get" )
179
- . action ( act . ifLoggedIn ( ( ) => {
180
- console . log ( "get" ) ;
181
- return { value : "" } ;
182
- } ) ) ,
183
- )
184
- . action ( function ( ) {
185
- this . showHelp ( ) ;
186
- } ) ;
187
-
188
148
/**
189
149
* Machines
190
150
*/
@@ -333,28 +293,43 @@ cli
333
293
. option ( "--fields <fields:string[]>" , "Return only these fields." , {
334
294
collect : true ,
335
295
} )
336
- . action ( act . ifLoggedIn ( async ( opt , id ) => {
337
- const fields = opt . fields ?. flat ( ) . map ( ( field ) => field . trim ( ) ) as any ;
296
+ . option (
297
+ "--poll [interval:string]" ,
298
+ `Poll the server for updates. Defaults to "3s".` ,
299
+ )
300
+ . action (
301
+ act . ifLoggedIn ( async ( opt , id ) => {
302
+ const fields = opt . fields ?. flat ( ) . map ( ( field ) => field . trim ( ) ) as any ;
338
303
339
- if ( ! id ) {
340
- const suggestions = await gqlFetch ( ListProjectsDocument , {
341
- first : 100 ,
342
- } ) ;
343
-
344
- id = await select ( {
345
- message : "Select a project" ,
346
- options : suggestions . projects . nodes . map ( ( p ) => ( {
347
- name : `${ p . name } (${ p . id } )` ,
348
- value : p . id ,
349
- } ) ) ,
350
- search : true ,
351
- searchLabel : "| 🔍" ,
352
- info : true ,
353
- } ) ;
354
- }
304
+ if ( ! id ) {
305
+ const suggestions = await gqlFetch ( ListProjectsDocument , {
306
+ first : 100 ,
307
+ } ) ;
355
308
356
- return await project . get ( { id, fields } ) ;
357
- } ) ) ,
309
+ id = await select ( {
310
+ message : "Select a project" ,
311
+ options : suggestions . projects . nodes . map ( ( p ) => ( {
312
+ name : `${ p . name } (${ p . id } )` ,
313
+ value : p . id ,
314
+ } ) ) ,
315
+ search : true ,
316
+ searchLabel : "| 🔍" ,
317
+ info : true ,
318
+ } ) ;
319
+ }
320
+
321
+ if ( opt . poll ) {
322
+ return {
323
+ value : await pollCmd (
324
+ async ( ) => await project . get ( { id : id ! , fields } ) ,
325
+ opt ,
326
+ ) ,
327
+ } ;
328
+ } else {
329
+ return await project . get ( { id, fields } ) ;
330
+ }
331
+ } ) ,
332
+ ) ,
358
333
)
359
334
. description ( `Manage your Paperspace Gradient projects.` )
360
335
. action ( function ( ) {
@@ -641,23 +616,23 @@ cli
641
616
642
617
/**
643
618
* Adds a command to upgrade the CLI
644
-
645
- cli.command(
646
- "upgrade",
647
- new UpgradeCommand({ provider: ["choco", "brew", "curl", "scoop"] })
648
- );
649
-
650
- async function checkVersion() {
651
- const mainCommand = cli.getMainCommand();
652
- const upgradeCommand = mainCommand.getCommand("upgrade");
653
- const latestVersion = await upgradeCommand.getLatestVersion();
654
- const currentVersion = mainCommand.getVersion();
655
-
656
- if (currentVersion === latestVersion) {
657
- return;
658
- }
659
-
660
- const versionHelpText = `(New version available: ${latestVersion}. Run '${mainCommand.getName()} upgrade' to upgrade to the latest version!)`;
661
- console.log(warn(versionHelpText));
662
- }
663
619
*/
620
+ // cli.command(
621
+ // "upgrade",
622
+ // new UpgradeCommand({ provider: ["choco", "brew", "curl", "scoop"] }),
623
+ // );
624
+
625
+ // async function checkVersion() {
626
+ // const mainCommand = cli.getMainCommand();
627
+ // const upgradeCommand = mainCommand.getCommand("upgrade");
628
+ // const latestVersion = await upgradeCommand.getLatestVersion();
629
+ // const currentVersion = mainCommand.getVersion();
630
+
631
+ // if (currentVersion === latestVersion) {
632
+ // return;
633
+ // }
634
+
635
+ // const versionHelpText =
636
+ // `(New version available: ${latestVersion}. Run '${mainCommand.getName()} upgrade' to upgrade to the latest version!)`;
637
+ // console.log(warn(versionHelpText));
638
+ // }
0 commit comments