Add -n option to generate Azgaar-style namebases

This commit is contained in:
Justin C. Miller
2024-03-10 10:37:07 -07:00
parent aa57d606ce
commit cd284ab790

17
lexx.ts
View File

@@ -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);
} }