-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcli.js
More file actions
executable file
·143 lines (124 loc) · 3.53 KB
/
cli.js
File metadata and controls
executable file
·143 lines (124 loc) · 3.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/usr/bin/env node
import process from 'node:process';
import {Command} from 'commander';
import packageJSON from '../package.json';
import {showBanner, showWarning, showSuccess, showError} from './utils/ui.js';
import {commitCommand} from './commands/commit.js';
import {
authenticateWithCopilot,
authenticateWithOpenAI,
showAuthStatusCommand,
logout,
} from './commands/auth.js';
import {showConfig, resetConfig} from './commands/config.js';
import {setConvention} from './utils/config-manager.js';
import {CONVENTIONS} from './utils/commit-conventions.js';
const program = new Command();
// Setup program metadata
program
.name('magicc')
.description('🪄 You can do magicc, you can build anything that you desire.')
.version(packageJSON.version);
// Show banner on startup (except for --help and --version)
const args = new Set(process.argv.slice(2));
if (
!args.has('--help') &&
!args.has('-h') &&
!args.has('--version') &&
!args.has('-V')
) {
showBanner();
}
// Default command (commit)
program.action(() => {
// If no command is specified, run commit
commitCommand();
});
// Commit command
program
.command('commit', {isDefault: false})
.description('Generate AI-powered commit messages')
.option('--all', 'Process all files at once')
.option('--file <path>', 'Process specific file')
.option('--model <model>', 'Specify AI model (e.g., gpt-4, gpt-3.5-turbo)')
.option(
'--convention <type>',
'Commit convention (clean, conventional, gitmoji, simple)',
)
.action(options => {
commitCommand(options);
});
// Auth command
const authCmd = program.command('auth').description('Manage authentication');
authCmd
.command('copilot')
.description('Authenticate with GitHub Copilot')
.option('--token <token>', 'GitHub token')
.action(options => {
authenticateWithCopilot(options.token);
});
authCmd
.command('openai <key>')
.description('Authenticate with OpenAI (legacy)')
.action(key => {
authenticateWithOpenAI(key);
});
authCmd
.command('status')
.description('Show authentication status')
.action(() => {
showAuthStatusCommand();
});
authCmd
.command('logout')
.description('Clear all credentials')
.action(() => {
logout();
});
// Config command
const configCmd = program.command('config').description('Manage configuration');
configCmd
.command('set-convention <type>')
.description('Set default commit convention')
.action(type => {
const validConventions = Object.keys(CONVENTIONS);
if (!validConventions.includes(type)) {
showError(`Invalid convention: ${type}`);
console.log(`Available: ${validConventions.join(', ')}`);
process.exit(1);
}
setConvention(type);
showSuccess(`Default convention set to: ${type}`);
});
configCmd
.option('--show', 'Show current configuration')
.option('--reset', 'Reset configuration to defaults')
.action(options => {
if (options.reset) {
resetConfig();
} else {
showConfig();
}
});
// Legacy flags support with deprecation warnings
program
.option('-s, --setopenai <key>', '[DEPRECATED] Set OpenAI API key')
.option('-d, --delopenai', '[DEPRECATED] Delete OpenAI API key');
// Handle legacy flags
program.hook('preAction', thisCommand => {
const options = thisCommand.opts();
if (options.setopenai) {
showWarning('The -s flag is deprecated. Use: magicc auth openai <key>');
console.log('');
authenticateWithOpenAI(options.setopenai);
process.exit(0);
}
if (options.delopenai) {
showWarning('The -d flag is deprecated. Use: magicc auth logout');
console.log('');
logout();
process.exit(0);
}
});
// Parse arguments
program.parse();