-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
85 lines (77 loc) · 1.95 KB
/
cli.js
File metadata and controls
85 lines (77 loc) · 1.95 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
#!/usr/bin/env node
'use strict';
const Spinner = require('./index.js');
const FRAMES = Spinner.FRAMES;
// Parse command line arguments
const args = process.argv.slice(2);
const options = {
frames: 'braille',
prefix: 'Loading',
interval: 100
};
for (let i = 0; i < args.length; i++) {
const arg = args[i];
switch (arg) {
case '-f':
case '--frames':
const frameName = args[++i];
if (FRAMES[frameName]) {
options.frames = frameName;
} else {
// Treat as custom frames
options.frames = args[i].split('');
}
break;
case '-p':
case '--prefix':
options.prefix = args[++i];
break;
case '-i':
case '--interval':
options.interval = parseInt(args[++i], 10) || 100;
break;
case '-l':
case '--list':
console.log('Available presets:');
Object.keys(FRAMES).forEach(name => {
const frames = FRAMES[name];
console.log(` ${name}: ${frames.join(' ')}`);
});
process.exit(0);
break;
case '-h':
case '--help':
console.log(`
Usage: spinner [options] [message]
Options:
-f, --frames <name> Animation preset (default: braille)
-p, --prefix <text> Prefix text (default: Loading)
-i, --interval <ms> Interval in ms (default: 100)
-l, --list List all available presets
-h, --help Show this help message
Examples:
spinner "Processing..."
spinner -f dots "Please wait"
spinner -f moon "Loading..."
spinner -f equal "======="
`.trim());
process.exit(0);
}
}
// Use remaining args as prefix
if (args.length > 0 && !args[0].startsWith('-')) {
options.prefix = args.join(' ');
}
// Create and start spinner
const spinner = new Spinner({
frames: options.frames,
prefix: options.prefix,
interval: options.interval,
autoStart: true
});
// HandleCtrl+C to gracefully stop
process.on('SIGINT', () => {
spinner.stop();
console.log('\nCancelled.');
process.exit(0);
});