Skip to content

Commit

Permalink
yay woo hooray we did it
Browse files Browse the repository at this point in the history
  • Loading branch information
hiimjasmine00 committed Apr 10, 2023
1 parent e240eeb commit e0772a8
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export = function (argv: string[], mode: "encode" | "decode") {

const descStart = `${mode[0].toUpperCase() + mode.slice(1)}s the specified input data ${isEncode ? "with" : "from"}`;
const encodingOption = program
.createOption("-e, --encoding <format>", `The encoding to ${isEncode ? "write" : "read"} the input data in`)
.createOption("-e, --encoding <format>", `The encoding to ${isEncode ? "read" : "write"} the input data in`)
.default("utf8")
.choices(["ascii", "binary", "latin1", "ucs2", "utf8", "utf16le"]);
const fileFlag = program
Expand All @@ -31,8 +31,9 @@ export = function (argv: string[], mode: "encode" | "decode") {
function actionHandler(radix: number | Exclude<keyof typeof dencodeme, "base">, input: string, options: Options) {
try {
const output = (typeof radix == "number" ? dencodeme.base(radix) : dencodeme[radix])[mode](options.file ?
fs.readFileSync(path.resolve(process.cwd(), input), isEncode ? options.encoding : "utf8") : input, options.encoding);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output) : process.stdout.write(output);
fs.readFileSync(path.resolve(process.cwd(), input), isEncode ? options.encoding : "utf8") : input);
options.out ? fs.writeFileSync(path.resolve(process.cwd(), options.out), output, options.encoding) :
process.stdout.write(output.toString(options.encoding));
} catch (err) {
program.error(String(err));
}
Expand Down

0 comments on commit e0772a8

Please sign in to comment.