Skip to content

Commit

Permalink
feat: add command (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
Apricot-S committed Jun 26, 2024
1 parent 349e2c8 commit 211b216
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/command.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env node

import fs from 'fs';
import { parseArgs } from 'node:util';
import { convertLog, MODE } from './lib/convertLog.js';

const options = {
mode: {
type: 'string',
short: 'm',
multiple: false,
default: MODE.Log,
},
} as const;

const main = async () => {
const args = process.argv.slice(2);
const parsedArgs = parseArgs({ options, args });
const mode = parsedArgs.values.mode!;

const input = fs.readFileSync(process.stdin.fd, 'utf-8');
const parsedInput = JSON.parse(input);

const outputJson = convertLog(parsedInput, mode);

const output = Array.isArray(outputJson)
? outputJson.join('\n') + '\n'
: JSON.stringify(outputJson) + '\n';
fs.writeSync(process.stdout.fd, output);
};

main().catch((error) => {
process.exitCode = 1;
console.error(error);
});

0 comments on commit 211b216

Please sign in to comment.