@@ -65,46 +65,53 @@ export async function renderUserInputType(config: CliConfig): Promise<string> {
65
65
66
66
// add command-specific options
67
67
for ( const [ commandName , command ] of Object . entries ( config . commands ) ) {
68
- const commandType = new StructType ( scope , {
69
- export : true ,
70
- name : `${ kebabToPascal ( commandName ) } Options` ,
71
- docs : {
72
- summary : command . description ,
73
- remarks : command . aliases ? `aliases: ${ command . aliases . join ( ' ' ) } ` : undefined ,
74
- } ,
75
- } ) ;
76
-
77
- // add command level options
78
- for ( const [ optionName , option ] of Object . entries ( command . options ?? { } ) ) {
79
- commandType . addProperty ( {
80
- name : kebabToCamelCase ( optionName ) ,
81
- type : convertType ( option . type , option . count ) ,
68
+ let commandType : Type = Type . anonymousInterface ( [ ] ) ;
69
+ const commandOptions = Object . entries ( command . options ?? { } ) ;
70
+
71
+ // if we have something to add to an interface
72
+ if ( command . arg || commandOptions . length ) {
73
+ const commandStruct = new StructType ( scope , {
74
+ export : true ,
75
+ name : `${ kebabToPascal ( commandName ) } Options` ,
82
76
docs : {
83
- // Notification Arns is a special property where undefined and [] mean different things
84
- default : optionName === 'notification-arns' ? 'undefined' : normalizeDefault ( option . default ) ,
85
- summary : option . desc ,
86
- deprecated : option . deprecated ? String ( option . deprecated ) : undefined ,
87
- remarks : option . alias ? `aliases: ${ Array . isArray ( option . alias ) ? option . alias . join ( ' ' ) : option . alias } ` : undefined ,
77
+ summary : command . description ,
78
+ remarks : command . aliases ? `aliases: ${ command . aliases . join ( ' ' ) } ` : undefined ,
88
79
} ,
89
- optional : true ,
90
- } ) ;
91
- }
92
-
93
- // add positional argument associated with the command
94
- if ( command . arg ) {
95
- commandType . addProperty ( {
96
- name : command . arg . name ,
97
- type : command . arg . variadic ? Type . arrayOf ( Type . STRING ) : Type . STRING ,
98
- docs : {
99
- summary : `Positional argument for ${ commandName } ` ,
100
- } ,
101
- optional : true ,
102
80
} ) ;
81
+ commandType = Type . fromName ( scope , commandStruct . name ) ;
82
+
83
+ // add command level options
84
+ for ( const [ optionName , option ] of commandOptions ) {
85
+ commandStruct . addProperty ( {
86
+ name : kebabToCamelCase ( optionName ) ,
87
+ type : convertType ( option . type , option . count ) ,
88
+ docs : {
89
+ // Notification Arns is a special property where undefined and [] mean different things
90
+ default : optionName === 'notification-arns' ? 'undefined' : normalizeDefault ( option . default ) ,
91
+ summary : option . desc ,
92
+ deprecated : option . deprecated ? String ( option . deprecated ) : undefined ,
93
+ remarks : option . alias ? `aliases: ${ Array . isArray ( option . alias ) ? option . alias . join ( ' ' ) : option . alias } ` : undefined ,
94
+ } ,
95
+ optional : true ,
96
+ } ) ;
97
+ }
98
+
99
+ // add positional argument associated with the command
100
+ if ( command . arg ) {
101
+ commandStruct . addProperty ( {
102
+ name : command . arg . name ,
103
+ type : command . arg . variadic ? Type . arrayOf ( Type . STRING ) : Type . STRING ,
104
+ docs : {
105
+ summary : `Positional argument for ${ commandName } ` ,
106
+ } ,
107
+ optional : true ,
108
+ } ) ;
109
+ }
103
110
}
104
111
105
112
userInputType . addProperty ( {
106
113
name : kebabToCamelCase ( commandName ) ,
107
- type : Type . fromName ( scope , commandType . name ) ,
114
+ type : commandType ,
108
115
docs : {
109
116
summary : command . description ,
110
117
remarks : command . aliases ? `aliases: ${ command . aliases . join ( ' ' ) } ` : undefined ,
0 commit comments