Skip to content

Commit 0016179

Browse files
authored
fix: update demo-cli-cac to use the new API (#102)
1 parent 23a6ef9 commit 0016179

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

examples/demo-cli-cac/demo-cli-cac.js

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,34 +37,38 @@ const completion = await tab(cli);
3737
// custom config for options
3838
for (const command of completion.commands.values()) {
3939
for (const [optionName, config] of command.options.entries()) {
40-
if (optionName === '--port') {
41-
config.handler = () => {
42-
return [
43-
{ value: '3000', description: 'Default port' },
44-
{ value: '8080', description: 'Alternative port' },
45-
];
40+
if (optionName === 'port') {
41+
config.handler = function (complete) {
42+
complete('3000', 'Default port');
43+
complete('8080', 'Alternative port');
4644
};
4745
}
4846

49-
if (optionName === '--mode') {
50-
config.handler = () => {
51-
return [
52-
{ value: 'development', description: 'Development mode' },
53-
{ value: 'production', description: 'Production mode' },
54-
{ value: 'test', description: 'Test mode' },
55-
];
47+
if (optionName === 'mode') {
48+
config.handler = function (complete) {
49+
complete('development', 'Development mode');
50+
complete('production', 'Production mode');
51+
complete('test', 'Test mode');
5652
};
5753
}
5854

59-
if (optionName === '--config') {
60-
config.handler = () => {
61-
return [
62-
{ value: 'config.json', description: 'JSON config file' },
63-
{ value: 'config.js', description: 'JavaScript config file' },
64-
];
55+
if (optionName === 'config') {
56+
config.handler = function (complete) {
57+
complete('config.json', 'JSON config file');
58+
complete('config.js', 'JavaScript config file');
6559
};
6660
}
6761
}
6862
}
6963

64+
// for root command options
65+
for (const [optionName, config] of completion.options.entries()) {
66+
if (optionName === 'config') {
67+
config.handler = function (complete) {
68+
complete('config.json', 'JSON config file');
69+
complete('config.js', 'JavaScript config file');
70+
};
71+
}
72+
}
73+
7074
cli.parse();

0 commit comments

Comments
 (0)