@@ -108,13 +108,17 @@ cli
108108 .option (' --host <host>' , ' Specify host' );
109109
110110// Initialize tab completions
111- const completion = tab (cli );
111+ const completion = await tab (cli );
112112
113113// Add custom completions for option values
114- completion .commands .get (' dev' )?.options .get (' --port' )! .handler = async () => [
115- { value: ' 3000' , description: ' Development port' },
116- { value: ' 8080' , description: ' Production port' },
117- ];
114+ const devCommand = completion .commands .get (' dev' );
115+ const portOption = devCommand ?.options .get (' port' );
116+ if (portOption ) {
117+ portOption .handler = (complete ) => {
118+ complete (' 3000' , ' Development port' );
119+ complete (' 8080' , ' Production port' );
120+ };
121+ }
118122
119123cli .parse ();
120124```
@@ -142,10 +146,14 @@ const main = defineCommand({
142146const completion = await tab (main );
143147
144148// Add custom completions
145- completion .commands .get (' dev' )?.options .get (' --port' )! .handler = async () => [
146- { value: ' 3000' , description: ' Development port' },
147- { value: ' 8080' , description: ' Production port' },
148- ];
149+ const devCommand = completion .commands .get (' dev' );
150+ const portOption = devCommand ?.options .get (' port' );
151+ if (portOption ) {
152+ portOption .handler = (complete ) => {
153+ complete (' 3000' , ' Development port' );
154+ complete (' 8080' , ' Production port' );
155+ };
156+ }
149157
150158const cli = createMain (main );
151159cli ();
@@ -174,10 +182,14 @@ program
174182const completion = tab (program );
175183
176184// Add custom completions
177- completion .commands .get (' serve' )?.options .get (' --port' )! .handler = async () => [
178- { value: ' 3000' , description: ' Default port' },
179- { value: ' 8080' , description: ' Alternative port' },
180- ];
185+ const serveCommand = completion .commands .get (' serve' );
186+ const portOption = serveCommand ?.options .get (' port' );
187+ if (portOption ) {
188+ portOption .handler = (complete ) => {
189+ complete (' 3000' , ' Default port' );
190+ complete (' 8080' , ' Alternative port' );
191+ };
192+ }
181193
182194program .parse ();
183195```
0 commit comments