-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.js
More file actions
105 lines (85 loc) · 3.33 KB
/
cli.js
File metadata and controls
105 lines (85 loc) · 3.33 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
#!/usr/bin/env node
const wordGenerator = require('./wordGenerator.js');
const languages = require('./langs.json');
// args
const args = process.argv.slice(2);
const lengthArg = args[0];
const lang = args[1] || 'en';
// Support or Help commands
const helpArgs = ["?", "--?", "-?", "help", "--help", "-h"];
if (!lengthArg || helpArgs.includes(lengthArg)) {
return sendHelp();
}
if (args.includes("--list")) {
return listLanguages();
}
if (args.includes("--support") || args.includes("--s")) {
return showSupportInfo();
}
// Generate Word
async function generateWord() {
if (lengthArg === "--random") {
const randomLength = Math.floor(Math.random() * 20) + 1;
try {
const word = await wordGenerator(randomLength, lang);
console.log(word);
} catch (error) {
console.error("❌ Error generating word:", error);
}
return process.exit(0);
}
const length = parseInt(lengthArg, 10);
if (length > 50) {
console.error('⚠️ Maximum length allowed is 50 characters.');
return process.exit(1);
}
if (isNaN(length)) {
return sendHelp(); // No length provided, show help
}
try {
const word = await wordGenerator(length, lang);
console.log(word);
} catch (error) {
console.error(error);
}
}
generateWord();
// List available Languages
function listLanguages() {
console.log("🌍 Available languages:");
Object.keys(languages).forEach(lang => console.log(`- ${lang}`));
process.exit(0);
}
// Show Help and Support Information
function showSupportInfo() {
console.log(`
\x1b[34m📖 Need Help?\x1b[0m
\x1b[90m──────────────────────────────────────────\x1b[0m
\x1b[33m📜 Documentation:\x1b[0m \x1b[4;34mhttps://github.com/liveweeeb13/WordWhize/blob/main/README.md\x1b[0m
\x1b[31m⚠️ Error List:\x1b[0m \x1b[4;34mhttps://github.com/liveweeeb13/WordWhize/blob/main/errors.md\x1b[0m
\x1b[32m💬 Discord Support:\x1b[0m \x1b[4;34mhttps://discord.gg/rm7fqE9Taz\x1b[0m
\x1b[90m──────────────────────────────────────────\x1b[0m
`);
process.exit(0);
}
// Send Help Information
function sendHelp() {
console.log(`
\x1b[34m📖 WordWhize - Command list\x1b[0m
\x1b[90m──────────────────────────────────────────\x1b[0m
\x1b[32m📜 Generate a word:\x1b[0m
\x1b[36mnpx wordwhize <length> [language]\x1b[0m
→ Generates a word with the given length in the specified language
\x1b[33m🎲 Random length:\x1b[0m
\x1b[36mnpx wordwhize --random [language]\x1b[0m
→ Generates a word with a random length between 1 and 20
\x1b[31m⚠️ Help & Support:\x1b[0m
\x1b[36mnpx wordwhize --help\x1b[0m → Displays this help message
\x1b[36mnpx wordwhize --list\x1b[0m → List available languages
\x1b[36mnpx wordwhize --support\x1b[0m → Shows the package's links
\x1b[36m🔗 GitHub:\x1b[0m \x1b[4;34mhttps://github.com/liveweeeb13/WordWhize\x1b[0m
\x1b[36m💬 Discord:\x1b[0m \x1b[4;34mhttps://discord.gg/rm7fqE9Taz\x1b[0m
\x1b[90m──────────────────────────────────────────\x1b[0m
`);
process.exit(0);
}