-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrefwire.js
More file actions
69 lines (58 loc) · 3.08 KB
/
refwire.js
File metadata and controls
69 lines (58 loc) · 3.08 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
#!/usr/bin/env node
import { Command } from 'commander';
import chalk from 'chalk';
import { getCredentials } from './src/lib/configManager.js';
import registerApiKeyCommands from './src/commands/apiKeyCommands.js';
import registerDatasetCommands from './src/commands/datasetCommands.js';
import registerItemCommands from './src/commands/itemCommands.js';
import registerInstanceCommands from './src/commands/instanceCommands.js';
import registerHealthCommands from './src/commands/healthCommands.js';
import registerAuthCommands from './src/commands/authCommands.js';
import { handleError } from './src/utils/errorHandler.js';
import { readFileSync } from 'fs';
// Load package.json for version info
const packageJson = JSON.parse(readFileSync(new URL('./package.json', import.meta.url)));
const program = new Command();
program
.name('refwire')
.description(chalk.blueBright(chalk.cyan(`
██████╗ ███████╗███████╗██╗ ██╗██╗██████╗ ███████╗
██╔══██╗██╔════╝██╔════╝██║ ██║██║██╔══██╗██╔════╝
██████╔╝█████╗ █████╗ ██║ █╗ ██║██║██████╔╝█████╗
██╔══██╗██╔══╝ ██╔══╝ ██║███╗██║██║██╔══██╗██╔══╝
██║ ██║███████╗██║ ╚███╔███╔╝██║██║ ██║███████╗
╚═╝ ╚═╝╚══════╝╚═╝ ╚══╝╚══╝ ╚═╝╚═╝ ╚═╝╚══════╝
Visit: https://refwire.online
Docs: https://github.com/coretravis/RefWireCLI
`)))
.version(packageJson.version);
// Global hook to ensure credentials are set before any command action
program.hook('preAction', async (thisCommand, actionCommand) => {
try {
// Skip credential check for auth commands
const isAuthCommand = actionCommand.parent &&
actionCommand.parent.name() === 'auth';
// These specific auth commands don't need credentials
const skipCredentialCommands = ['logout', 'status'];
if (isAuthCommand && skipCredentialCommands.includes(actionCommand.name())) {
console.log(chalk.dim(`Executing: ${actionCommand.name()}`));
return;
}
await getCredentials(); // Ensures URL and API Key are prompted for if not already set
console.log(chalk.dim(`Executing: ${actionCommand.name()}`));
} catch (error) {
handleError(error);
process.exit(1); // Exit if credential setup fails
}
});
// Register command modules
registerApiKeyCommands(program);
registerDatasetCommands(program);
registerItemCommands(program);
registerHealthCommands(program);
registerInstanceCommands(program);
registerAuthCommands(program);
program.parseAsync(process.argv).catch(err => {
handleError(err);
process.exit(1);
});