mirror of
https://github.com/justinian/lexx.git
synced 2025-12-09 16:14:32 -08:00
Add -n option to generate Azgaar-style namebases
This commit is contained in:
17
lexx.ts
17
lexx.ts
@@ -1,13 +1,19 @@
|
|||||||
import { parseArgs } from 'util';
|
import { parseArgs } from 'util';
|
||||||
import { build_language } from './src/definition'
|
import { build_language } from './src/definition'
|
||||||
|
|
||||||
|
const default_count = '20';
|
||||||
|
|
||||||
const { values, positionals } = parseArgs({
|
const { values, positionals } = parseArgs({
|
||||||
args: Bun.argv.slice(2),
|
args: Bun.argv.slice(2),
|
||||||
options: {
|
options: {
|
||||||
count: {
|
count: {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
short: 'c',
|
short: 'c',
|
||||||
default: '20',
|
default: default_count,
|
||||||
|
},
|
||||||
|
namebase: {
|
||||||
|
type: 'boolean',
|
||||||
|
short: 'n',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
allowPositionals: true,
|
allowPositionals: true,
|
||||||
@@ -20,11 +26,20 @@ if (positionals.length > 0)
|
|||||||
const def = await Bun.file(language).text();
|
const def = await Bun.file(language).text();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
if (typeof(values.count) != "string")
|
||||||
|
values.count = default_count;
|
||||||
|
|
||||||
const lang = build_language(def);
|
const lang = build_language(def);
|
||||||
let words = lang.generate(parseInt(values.count));
|
let words = lang.generate(parseInt(values.count));
|
||||||
|
|
||||||
|
if (values.namebase) {
|
||||||
|
let ws = words.map(w => w[0]);
|
||||||
|
console.log(ws.join(','));
|
||||||
|
} else {
|
||||||
for (const w of words) {
|
for (const w of words) {
|
||||||
console.log(`${w[0]}\t\t/${w[1]}/`);
|
console.log(`${w[0]}\t\t/${w[1]}/`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user