-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cf9b2a6
commit ff53735
Showing
1 changed file
with
12 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
|