-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd-command.js
More file actions
107 lines (93 loc) · 3.09 KB
/
add-command.js
File metadata and controls
107 lines (93 loc) · 3.09 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
#!/usr/bin/env node
/**
* Utility to easily add new commands to profiles
* Usage: node add-command.js --profile=premiere --keyword=split --keys="^k" --description="Split clip"
*/
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const profilesPath = path.join(__dirname, 'config', 'profiles.json');
async function main() {
const argv = await yargs(hideBin(process.argv))
.option('profile', {
alias: 'p',
describe: 'Profile name (e.g., premiere, resolve, gaming)',
type: 'string',
demandOption: true,
})
.option('keyword', {
alias: 'k',
describe: 'Command keyword (e.g., split, zoom-in)',
type: 'string',
demandOption: true,
})
.option('keys', {
describe: 'AutoHotkey key sequence (e.g., "^k", "^+z", "Space")',
type: 'string',
demandOption: true,
})
.option('description', {
alias: 'd',
describe: 'Human-readable description',
type: 'string',
default: '',
})
.option('list', {
alias: 'l',
describe: 'List all commands in a profile',
type: 'boolean',
})
.help()
.parse();
try {
// Read current profiles
const content = fs.readFileSync(profilesPath, 'utf-8');
const config = JSON.parse(content);
// Validate profile exists
if (!config.profiles[argv.profile]) {
console.error(`✗ Profile not found: ${argv.profile}`);
console.log(`Available profiles: ${Object.keys(config.profiles).join(', ')}`);
process.exit(1);
}
// List mode
if (argv.list) {
const profile = config.profiles[argv.profile];
console.log(`\nCommands in profile "${argv.profile}" (${profile.name}):\n`);
const commands = profile.commands || {};
for (const [keyword, cmd] of Object.entries(commands)) {
console.log(` ${keyword.padEnd(20)} → ${cmd.keys.padEnd(10)} (${cmd.description})`);
}
console.log();
process.exit(0);
}
// Add command
const profile = config.profiles[argv.profile];
if (!profile.commands) {
profile.commands = {};
}
const keyword = argv.keyword.toLowerCase();
if (profile.commands[keyword]) {
console.log(`⚠ Command already exists: ${keyword}`);
console.log(` Old: ${profile.commands[keyword].keys} (${profile.commands[keyword].description})`);
console.log(` New: ${argv.keys} (${argv.description})`);
console.log('Overwriting...');
}
profile.commands[keyword] = {
keys: argv.keys,
description: argv.description || `Custom command: ${keyword}`,
};
// Write back to file
fs.writeFileSync(profilesPath, JSON.stringify(config, null, 2));
console.log(`✓ Added command to profile "${argv.profile}"`);
console.log(` Keyword: ${keyword}`);
console.log(` Keys: ${argv.keys}`);
console.log(` Description: ${argv.description}`);
} catch (err) {
console.error(`✗ Error: ${err.message}`);
process.exit(1);
}
}
main();