|
1 | 1 | #!/usr/bin/env node |
| 2 | +import process from 'node:process'; |
2 | 3 | import {Command} from 'commander'; |
| 4 | +import packageJSON from '../package.json'; |
3 | 5 | import {showBanner, showWarning} from './utils/ui.js'; |
4 | 6 | import {commitCommand} from './commands/commit.js'; |
5 | 7 | import { |
6 | | -authenticateWithCopilot, |
7 | | -authenticateWithOpenAI, |
8 | | -showAuthStatusCommand, |
9 | | -logout, |
| 8 | + authenticateWithCopilot, |
| 9 | + authenticateWithOpenAI, |
| 10 | + showAuthStatusCommand, |
| 11 | + logout, |
10 | 12 | } from './commands/auth.js'; |
11 | 13 | import {showConfig, resetConfig} from './commands/config.js'; |
12 | | -import packageJSON from '../package.json'; |
13 | 14 |
|
14 | 15 | const program = new Command(); |
15 | 16 |
|
16 | 17 | // Setup program metadata |
17 | 18 | program |
18 | | -.name('magicc') |
19 | | -.description('🪄 You can do magicc, you can build anything that you desire.') |
20 | | -.version(packageJSON.version); |
| 19 | + .name('magicc') |
| 20 | + .description('🪄 You can do magicc, you can build anything that you desire.') |
| 21 | + .version(packageJSON.version); |
21 | 22 |
|
22 | 23 | // Show banner on startup (except for --help and --version) |
23 | | -const args = process.argv.slice(2); |
24 | | -if (!args.includes('--help') && !args.includes('-h') && |
25 | | - !args.includes('--version') && !args.includes('-V')) { |
26 | | -showBanner(); |
| 24 | +const args = new Set(process.argv.slice(2)); |
| 25 | +if ( |
| 26 | + !args.has('--help') && |
| 27 | + !args.has('-h') && |
| 28 | + !args.has('--version') && |
| 29 | + !args.has('-V') |
| 30 | +) { |
| 31 | + showBanner(); |
27 | 32 | } |
28 | 33 |
|
29 | 34 | // Default command (commit) |
30 | | -program |
31 | | -.action(() => { |
32 | | -// If no command is specified, run commit |
33 | | -commitCommand(); |
| 35 | +program.action(() => { |
| 36 | + // If no command is specified, run commit |
| 37 | + commitCommand(); |
34 | 38 | }); |
35 | 39 |
|
36 | 40 | // Commit command |
37 | | -const commitCmd = program |
38 | | -.command('commit', {isDefault: false}) |
39 | | -.description('Generate AI-powered commit messages') |
40 | | -.option('--all', 'Process all files at once') |
41 | | -.option('--file <path>', 'Process specific file') |
42 | | -.option('--model <model>', 'Specify AI model (e.g., gpt-4, gpt-3.5-turbo)') |
43 | | -.action((options) => { |
44 | | -commitCommand(options); |
45 | | -}); |
| 41 | +program |
| 42 | + .command('commit', {isDefault: false}) |
| 43 | + .description('Generate AI-powered commit messages') |
| 44 | + .option('--all', 'Process all files at once') |
| 45 | + .option('--file <path>', 'Process specific file') |
| 46 | + .option('--model <model>', 'Specify AI model (e.g., gpt-4, gpt-3.5-turbo)') |
| 47 | + .action(options => { |
| 48 | + commitCommand(options); |
| 49 | + }); |
46 | 50 |
|
47 | 51 | // Auth command |
48 | | -const authCmd = program |
49 | | -.command('auth') |
50 | | -.description('Manage authentication'); |
| 52 | +const authCmd = program.command('auth').description('Manage authentication'); |
51 | 53 |
|
52 | 54 | authCmd |
53 | | -.command('copilot') |
54 | | -.description('Authenticate with GitHub Copilot') |
55 | | -.option('--token <token>', 'GitHub token') |
56 | | -.action((options) => { |
57 | | -authenticateWithCopilot(options.token); |
58 | | -}); |
| 55 | + .command('copilot') |
| 56 | + .description('Authenticate with GitHub Copilot') |
| 57 | + .option('--token <token>', 'GitHub token') |
| 58 | + .action(options => { |
| 59 | + authenticateWithCopilot(options.token); |
| 60 | + }); |
59 | 61 |
|
60 | 62 | authCmd |
61 | | -.command('openai <key>') |
62 | | -.description('Authenticate with OpenAI (legacy)') |
63 | | -.action((key) => { |
64 | | -authenticateWithOpenAI(key); |
65 | | -}); |
| 63 | + .command('openai <key>') |
| 64 | + .description('Authenticate with OpenAI (legacy)') |
| 65 | + .action(key => { |
| 66 | + authenticateWithOpenAI(key); |
| 67 | + }); |
66 | 68 |
|
67 | 69 | authCmd |
68 | | -.command('status') |
69 | | -.description('Show authentication status') |
70 | | -.action(() => { |
71 | | -showAuthStatusCommand(); |
72 | | -}); |
| 70 | + .command('status') |
| 71 | + .description('Show authentication status') |
| 72 | + .action(() => { |
| 73 | + showAuthStatusCommand(); |
| 74 | + }); |
73 | 75 |
|
74 | 76 | authCmd |
75 | | -.command('logout') |
76 | | -.description('Clear all credentials') |
77 | | -.action(() => { |
78 | | -logout(); |
79 | | -}); |
| 77 | + .command('logout') |
| 78 | + .description('Clear all credentials') |
| 79 | + .action(() => { |
| 80 | + logout(); |
| 81 | + }); |
80 | 82 |
|
81 | 83 | // Config command |
82 | | -const configCmd = program |
83 | | -.command('config') |
84 | | -.description('Manage configuration'); |
| 84 | +const configCmd = program.command('config').description('Manage configuration'); |
85 | 85 |
|
86 | 86 | configCmd |
87 | | -.option('--show', 'Show current configuration') |
88 | | -.option('--reset', 'Reset configuration to defaults') |
89 | | -.action((options) => { |
90 | | -if (options.reset) { |
91 | | -resetConfig(); |
92 | | -} else { |
93 | | -showConfig(); |
94 | | -} |
95 | | -}); |
| 87 | + .option('--show', 'Show current configuration') |
| 88 | + .option('--reset', 'Reset configuration to defaults') |
| 89 | + .action(options => { |
| 90 | + if (options.reset) { |
| 91 | + resetConfig(); |
| 92 | + } else { |
| 93 | + showConfig(); |
| 94 | + } |
| 95 | + }); |
96 | 96 |
|
97 | 97 | // Legacy flags support with deprecation warnings |
98 | 98 | program |
99 | | -.option('-s, --setopenai <key>', '[DEPRECATED] Set OpenAI API key') |
100 | | -.option('-d, --delopenai', '[DEPRECATED] Delete OpenAI API key'); |
| 99 | + .option('-s, --setopenai <key>', '[DEPRECATED] Set OpenAI API key') |
| 100 | + .option('-d, --delopenai', '[DEPRECATED] Delete OpenAI API key'); |
101 | 101 |
|
102 | 102 | // Handle legacy flags |
103 | | -program.hook('preAction', (thisCommand) => { |
104 | | -const options = thisCommand.opts(); |
105 | | - |
106 | | -if (options.setopenai) { |
107 | | -showWarning('The -s flag is deprecated. Use: magicc auth openai <key>'); |
108 | | -console.log(''); |
109 | | -authenticateWithOpenAI(options.setopenai); |
110 | | -process.exit(0); |
111 | | -} |
112 | | - |
113 | | -if (options.delopenai) { |
114 | | -showWarning('The -d flag is deprecated. Use: magicc auth logout'); |
115 | | -console.log(''); |
116 | | -logout(); |
117 | | -process.exit(0); |
118 | | -} |
| 103 | +program.hook('preAction', thisCommand => { |
| 104 | + const options = thisCommand.opts(); |
| 105 | + |
| 106 | + if (options.setopenai) { |
| 107 | + showWarning('The -s flag is deprecated. Use: magicc auth openai <key>'); |
| 108 | + console.log(''); |
| 109 | + authenticateWithOpenAI(options.setopenai); |
| 110 | + process.exit(0); |
| 111 | + } |
| 112 | + |
| 113 | + if (options.delopenai) { |
| 114 | + showWarning('The -d flag is deprecated. Use: magicc auth logout'); |
| 115 | + console.log(''); |
| 116 | + logout(); |
| 117 | + process.exit(0); |
| 118 | + } |
119 | 119 | }); |
120 | 120 |
|
121 | 121 | // Parse arguments |
|
0 commit comments