diff --git a/retroload/bin/retroload-convert.js b/retroload/bin/retroload-convert.js new file mode 100755 index 0000000..af6ea07 --- /dev/null +++ b/retroload/bin/retroload-convert.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +import('../dist/esm/retroload-convert.js'); + diff --git a/retroload/bin/retroload-tokenize.js b/retroload/bin/retroload-tokenize.js new file mode 100755 index 0000000..8197953 --- /dev/null +++ b/retroload/bin/retroload-tokenize.js @@ -0,0 +1,4 @@ +#!/usr/bin/env node + +import('../dist/esm/retroload-tokenize.js'); + diff --git a/retroload/bin/retroload-tokenizer.js b/retroload/bin/retroload-tokenizer.js deleted file mode 100755 index af04ccd..0000000 --- a/retroload/bin/retroload-tokenizer.js +++ /dev/null @@ -1,4 +0,0 @@ -#!/usr/bin/env node - -import('../dist/esm/retroload-tokenizer.js'); - diff --git a/retroload/package.json b/retroload/package.json index e6ae71d..1b706b6 100644 --- a/retroload/package.json +++ b/retroload/package.json @@ -38,8 +38,9 @@ }, "bin": { "retroload": "./bin/retroload.js", - "retroload-tokenizer": "./bin/retroload-tokenizer.js", - "retroload-decode": "./bin/retroload-decode.js" + "retroload-convert": "./bin/retroload-convert.js", + "retroload-decode": "./bin/retroload-decode.js", + "retroload-tokenize": "./bin/retroload-tokenize.js" }, "dependencies": { "commander": "^11.1.0", diff --git a/retroload/src/retroload-convert.ts b/retroload/src/retroload-convert.ts new file mode 100755 index 0000000..1d76caa --- /dev/null +++ b/retroload/src/retroload-convert.ts @@ -0,0 +1,63 @@ +#!/usr/bin/env node + +import {ConverterManager, Exception, Logger, version as libVersion} from 'retroload-lib'; +import {Command} from 'commander'; +import {version as cliVersion} from './version.js'; +import {readFile, writeFile} from './Utils.js'; + +main() + .catch((err) => { + Logger.error(err as string); + }); + +async function main() { + // const formatNames = AdapterManager.getAllAdapters().map((a) => a.internalName); + // formatNames.sort(); + const program = (new Command()) + .name('retroload-convert') + .description('Convert raw data into tape archive formats. (EXPERIMENTAL!)') + .argument('infile', 'Path to file to convert') + .allowExcessArguments(false) + .option('-o ', 'Path to file to write') + .option('-f ', 'Name of format to create') + .option('-l, --loglevel ', 'Verbosity of log output', '1') + .version(`retroload: ${cliVersion}\nretroload-lib: ${libVersion}`) + .showHelpAfterError(); + // Options defined in adapters/encoders + + /* + const allOptions = AdapterManager.getAllOptions(); + allOptions.sort((a, b) => a.common && !b.common ? -1 : 0); + for (const option of allOptions) { + program.addOption(new Option(getCommanderFlagsString(option), option.description).hideHelp()); + } + */ + program.parse(); + + const options = program.opts(); + const infile = program.args[0]; + const outfile = options['o'] as string; // TODO: fix type stuff; let converter propose new filename ((input.bin).cas)? + Logger.setVerbosity(parseInt(typeof options['loglevel'] === 'string' ? options['loglevel'] : '1', 10)); + const inputBa = readFile(infile); + const format: string = options['f'] as string; // TODO: fix type stuff + + Logger.debug(`Processing ${infile}...`); + + try { + const outputBa = ConverterManager.convert(inputBa, format, options); + writeFile(outfile, outputBa); + } catch (e) { + if (e instanceof Exception.UsageError) { + Logger.error(e.message); + process.exit(1); + } else { + throw e; // show full stack trace for unexpected errors + } + } +} + +/* +function getCommanderFlagsString(optionDefinition: PublicOptionDefinition) { + return optionDefinition.type !== 'text' || optionDefinition.argument === undefined ? `--${optionDefinition.name}` : `--${optionDefinition.name} <${optionDefinition.argument}>`; +} +*/ diff --git a/retroload/src/retroload-decode.ts b/retroload/src/retroload-decode.ts index 94ba150..77cc9da 100755 --- a/retroload/src/retroload-decode.ts +++ b/retroload/src/retroload-decode.ts @@ -19,7 +19,7 @@ async function main() { // - visualize WAVE samples of section around error as ASCII graph when --on-error was set to 'stop' const program = (new Command()) .name('retroload-decode') - .description('Decode WAVE files of historical computers.') + .description('Decode WAVE files of historical computers. (EXPERIMENTAL)') .argument('', 'Path to WAVE file to decode') .allowExcessArguments(false) .option('-o ', 'Prefix (filename or complete path) for files to write', './') diff --git a/retroload/src/retroload-tokenizer.ts b/retroload/src/retroload-tokenize.ts similarity index 95% rename from retroload/src/retroload-tokenizer.ts rename to retroload/src/retroload-tokenize.ts index 7cbf06d..e3c2622 100755 --- a/retroload/src/retroload-tokenizer.ts +++ b/retroload/src/retroload-tokenize.ts @@ -6,8 +6,8 @@ import {BasicTokenizers} from 'retroload-lib'; function main() { const program = (new Command()) - .name('retroload-tokenizer') - .description('Convert plain text BASIC files into tokenized BASIC files for loading.') + .name('retroload-tokenize') + .description('Convert plain text BASIC files into tokenized BASIC files for loading. (EXPERIMENTAL)') .argument('', 'Path to source file to tokenize') .option('-d, --dialect ', 'BASIC dialect to use') .option('-o, --outfile ', 'Where to write to binary output to. By default the input filename with a dialect specific extension is used as output filename.');