Skip to content

Commit

Permalink
Format with deno fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
fabon-f committed May 29, 2024
1 parent 8a7d681 commit 1368982
Show file tree
Hide file tree
Showing 5 changed files with 402 additions and 315 deletions.
5 changes: 1 addition & 4 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@ root = true

[*]
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true

[*.{yml,yaml}]
indent_size = 2
67 changes: 35 additions & 32 deletions cli.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { parseArgs } from "@std/cli/parse-args"
import * as colors from "@std/fmt/colors"
import { readAll } from "@std/io"
import scrapboxToReView from "./mod.ts"
import { parseArgs } from "@std/cli/parse-args";
import * as colors from "@std/fmt/colors";
import { readAll } from "@std/io";
import scrapboxToReView from "./mod.ts";

const options = parseArgs(Deno.args, { string: ["_"], boolean: ["help"], alias: { "h": "help" } });
const options = parseArgs(Deno.args, {
string: ["_"],
boolean: ["help"],
alias: { "h": "help" },
});

const usage =
`sb2re - Convert Scrapbox text to Re:VIEW
const usage = `sb2re - Convert Scrapbox text to Re:VIEW
${colors.bold("Usage")}
cat input | sb2re [options] > out.re
Expand All @@ -18,45 +21,45 @@ ${colors.bold("Options")}
--base-heading-level Specify the largest heading level (Default: 3. This means \`[*** ]\` corresponds to Re:VIEW's \`==\`)`;

if (options.help) {
console.log(usage);
Deno.exit(0);
console.log(usage);
Deno.exit(0);
}

const baseHeadingLevel = options["base-heading-level"] as unknown;
if (baseHeadingLevel !== undefined && typeof baseHeadingLevel !== "number") {
console.error("Error: base-heading-level option should be number");
Deno.exit(1);
console.error("Error: base-heading-level option should be number");
Deno.exit(1);
}

const src = await readSource();
const result = scrapboxToReView(src, {
baseHeadingLevel,
logger: {
error(message: string) {
console.error(colors.bold(colors.red(message)));
},
warn(message: string) {
console.warn(message);
}
}
baseHeadingLevel,
logger: {
error(message: string) {
console.error(colors.bold(colors.red(message)));
},
warn(message: string) {
console.warn(message);
},
},
});

if (options._[1] === "-" || options._[1] === undefined) {
console.log(result.replace(/\n$/, ""));
console.log(result.replace(/\n$/, ""));
} else {
await Deno.writeTextFile(options._[1].toString(), result);
await Deno.writeTextFile(options._[1].toString(), result);
}

async function readSource() {
if (options._.length === 0 || options._[0] === "-") {
// read from stdin
if (Deno.stdin.isTerminal()) {
console.log(colors.bold(colors.red("Specify input file.")));
Deno.exit(1);
}
const buf = await readAll(Deno.stdin)
return new TextDecoder().decode(buf)
} else {
return await Deno.readTextFile(options._[0].toString());
if (options._.length === 0 || options._[0] === "-") {
// read from stdin
if (Deno.stdin.isTerminal()) {
console.log(colors.bold(colors.red("Specify input file.")));
Deno.exit(1);
}
const buf = await readAll(Deno.stdin);
return new TextDecoder().decode(buf);
} else {
return await Deno.readTextFile(options._[0].toString());
}
}
2 changes: 1 addition & 1 deletion deps.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * as scrapboxParser from "https://esm.sh/@progfay/[email protected]"
export * as scrapboxParser from "https://esm.sh/@progfay/[email protected]";
Loading

0 comments on commit 1368982

Please sign in to comment.