@@ -3,6 +3,7 @@ import { start as startStudio } from '../../core/models/Studio';
3
3
import { load } from '../../core/models/SpecificationFile' ;
4
4
import { studioFlags } from '../../core/flags/start/studio.flags' ;
5
5
import { Args } from '@oclif/core' ;
6
+ import { isCancel , text , cancel } from '@clack/prompts' ;
6
7
7
8
export default class StartStudio extends Command {
8
9
static description = 'starts a new local instance of Studio' ;
@@ -16,13 +17,22 @@ export default class StartStudio extends Command {
16
17
async run ( ) {
17
18
const { args, flags } = await this . parse ( StartStudio ) ;
18
19
20
+ let filePath = args [ 'spec-file' ] ?? flags . file ;
21
+
22
+ let port = flags . port ;
23
+
19
24
if ( flags . file ) {
20
25
this . warn ( 'The file flag has been removed and is being replaced by the argument spec-file. Please pass the filename directly like `asyncapi start studio asyncapi.yml`' ) ;
21
26
}
22
27
23
- let filePath = args [ 'spec-file' ] ?? flags . file ;
28
+ const isInteractive = ! flags [ 'no-interactive' ] ;
29
+
30
+ if ( isInteractive && ! filePath ) {
31
+ const parsedArgs = await this . parseArgs ( { filePath } , port ?. toString ( ) ) ;
32
+ filePath = parsedArgs . filePath ;
33
+ port = parseInt ( parsedArgs . port , 10 ) ;
34
+ }
24
35
25
- const port = flags . port ;
26
36
if ( ! filePath ) {
27
37
try {
28
38
filePath = ( ( await load ( ) ) . getFilePath ( ) ) ;
@@ -42,4 +52,42 @@ export default class StartStudio extends Command {
42
52
this . metricsMetadata . port = port ;
43
53
startStudio ( filePath as string , port ) ;
44
54
}
55
+
56
+ private async parseArgs ( args :Record < string , any > , port ?:string ) {
57
+ const operationCancelled = 'Operation cancelled by the user.' ;
58
+ let askForPort = false ;
59
+ let { filePath} = args ;
60
+ if ( ! filePath ) {
61
+ filePath = await text ( {
62
+ message : 'Enter the path to the AsyncAPI document' ,
63
+ defaultValue : 'asyncapi.yaml' ,
64
+ placeholder : 'asyncapi.yaml' ,
65
+ validate : ( value ) => {
66
+ if ( ! value ) { return 'The path to the AsyncAPI document is required' ; }
67
+ } ,
68
+ } ) ;
69
+ askForPort = true ;
70
+ }
71
+
72
+ if ( isCancel ( filePath ) ) {
73
+ cancel ( operationCancelled ) ;
74
+ this . exit ( ) ;
75
+ }
76
+
77
+ if ( ! port && askForPort ) {
78
+ port = await text ( {
79
+ message : 'Enter the port in which to start Studio' ,
80
+ defaultValue : '3210' ,
81
+ placeholder : '3210' ,
82
+ validate : ( value ) => ( ! value ? 'The port number is required' : undefined ) ,
83
+ } ) as string ;
84
+ }
85
+
86
+ if ( isCancel ( port ) ) {
87
+ cancel ( operationCancelled ) ;
88
+ this . exit ( ) ;
89
+ }
90
+
91
+ return { filePath, port : port ?? '3210' } ;
92
+ }
45
93
}
0 commit comments