Skip to content

Commit

Permalink
fix: Fix cli.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
redpeacock78 committed Nov 11, 2021
1 parent cf9b2a6 commit ff53735
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
import { readLines } from "https://deno.land/[email protected]/io/mod.ts";
import { getStdin } from "https://deno.land/x/[email protected]/mod.ts";
import { Command } from "https://deno.land/x/[email protected]/command/mod.ts";
import { base85encode, base85decode } from "./mod.ts";

try {
let judge: boolean;
const stdin: string[] = [];
const isatty: boolean = Deno.isatty(Deno.stdin.rid);
if (!isatty) {
for await (const line of readLines(Deno.stdin)) {
judge = typeof readLines(Deno.stdin) === "object" ? true : false;
stdin.push(line);
}
const get: string = await getStdin({ exitOnEnter: false });
stdin.push(get);
}
const { options, args } = await new Command()
.name("base85")
.description("Base85 (Adobe) encode or decode standard input, to standard output.")
.version("0.0.2")
.version("0.0.3")
.option("-d, --decode", "decode data")
.arguments("<option>")
.parse(isatty ? Deno.args : [...Deno.args, stdin.join("\n")]);
.parse(isatty ? Deno.args : [...Deno.args, ...stdin]);
const { decode } = options;
const runner = decode ? base85decode : base85encode;
if (judge!) {
console.log(runner(String(args[0])));
} else if (!isatty && judge!) {
console.log(runner(String(args[0])));
if (!isatty) {
const result: string | Uint8Array = runner(String(args[0]));
if (typeof result === "string") {
console.log(result);
} else {
await Deno.stdout.write(result);
}
} else {
throw new Error("base85: No such file or directory");
}
Expand Down

0 comments on commit ff53735

Please sign in to comment.