Skip to content

Commit

Permalink
Improve CLI
Browse files Browse the repository at this point in the history
- Make it work again
- Add ability to set mode
- Add help menu with available modes
  • Loading branch information
RobinBoers committed Mar 22, 2024
1 parent 4134ffd commit 9173b48
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 51 deletions.
39 changes: 39 additions & 0 deletions bin/smartypants.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env node

const binary = "smartypants";
const mode = process.argv[2] || "1";

if (mode == "-h" || mode == "--help") {
process.stdout.write(`Usage: ${binary} [mode]
Available modes:
0 Suppress all transformations. (Do nothing.)
1 Performs default SmartyPants transformations: quotes (including backticks-style), em-dashes, and ellipses. -- (dash dash) is used to signify an em-dash; there is no support for en-dashes.
2 Same as 1, except that it uses the old-school typewriter shorthand for dashes: -- (dash dash) for en-dashes, --- (dash dash dash) for em-dashes.
3 Same 2, but inverts the shorthand for dashes: -- (dash dash) for em-dashes, and --- (dash dash dash) for en-dashes.
-1 Stupefy mode. Reverses the SmartyPants transformation process, turning the HTML entities produced by SmartyPants into their ASCII equivalents. E.g. “ is turned into a simple double-quote ("), — is turned into two dashes, etc. This is useful if you are using SmartyPants from Brad Choate's MT-Textile text filter, but wish to suppress smart punctuation in specific MT templates, such as RSS feeds. Text filters do their work before templates are processed; but you can use smarty_pants="-1" to reverse the transformations in specific templates.
`);
process.exit(0);
}

if (process.stdin.isTTY) {
console.error("No input!");
process.exit(1);
}

let smartypants = require("../smartypants.cjs").smartypants;
let text = "";

process.stdin.setEncoding("utf8");

process.stdin.on("readable", () => {
let chunk = process.stdin.read();
if (chunk !== null) {
text = text + chunk;
}
});

process.stdin.on("end", () => {
process.stdout.write(smartypants(text, mode));
});
24 changes: 0 additions & 24 deletions bin/smartypants.js

This file was deleted.

39 changes: 39 additions & 0 deletions bin/smartypantsu.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#! /usr/bin/env node

const binary = "smartypantsu";
const mode = process.argv[2] || "1";

if (mode == "-h" || mode == "--help") {
process.stdout.write(`Usage: ${binary} [mode]
Available modes:
0 Suppress all transformations. (Do nothing.)
1 Performs default SmartyPants transformations: quotes (including backticks-style), em-dashes, and ellipses. -- (dash dash) is used to signify an em-dash; there is no support for en-dashes.
2 Same as 1, except that it uses the old-school typewriter shorthand for dashes: -- (dash dash) for en-dashes, --- (dash dash dash) for em-dashes.
3 Same 2, but inverts the shorthand for dashes: -- (dash dash) for em-dashes, and --- (dash dash dash) for en-dashes.
-1 Stupefy mode. Reverses the SmartyPants transformation process, turning the HTML entities produced by SmartyPants into their ASCII equivalents. E.g. “ is turned into a simple double-quote ("), — is turned into two dashes, etc. This is useful if you are using SmartyPants from Brad Choate's MT-Textile text filter, but wish to suppress smart punctuation in specific MT templates, such as RSS feeds. Text filters do their work before templates are processed; but you can use smarty_pants="-1" to reverse the transformations in specific templates.
`);
process.exit(0);
}

if (process.stdin.isTTY) {
console.error("No input!");
process.exit(1);
}

let smartypants = require("../smartypants.cjs").smartypantsu;
let text = "";

process.stdin.setEncoding("utf8");

process.stdin.on("readable", () => {
let chunk = process.stdin.read();
if (chunk !== null) {
text = text + chunk;
}
});

process.stdin.on("end", () => {
process.stdout.write(smartypants(text, mode));
});
24 changes: 0 additions & 24 deletions bin/smartypantsu.js

This file was deleted.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
"bin/smartypantsu.js"
],
"bin": {
"smartypants": "./bin/smartypants.js",
"smartypantsu": "./bin/smartypantsu.js"
"smartypants": "./bin/smartypants.cjs",
"smartypantsu": "./bin/smartypantsu.cjs"
},
"devDependencies": {
"babel-eslint": "^9.0.0",
Expand All @@ -55,4 +55,4 @@
"typescript": "^3.0.3",
"uglify-js": "3.9.4"
}
}
}

0 comments on commit 9173b48

Please sign in to comment.