Skip to content

Commit

Permalink
Make commander script
Browse files Browse the repository at this point in the history
  • Loading branch information
alcuadrado committed Aug 8, 2012
1 parent 73d3863 commit 54bb07f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
44 changes: 34 additions & 10 deletions bin/hieroglyphy
Original file line number Diff line number Diff line change
@@ -1,17 +1,41 @@
#!/usr/bin/env node

var hieroglyphy = require("../hieroglyphy.js"),
pkg = require('../package.json'),
version = pkg.version,
program = require('commander'),
fs = require("fs");

if ((process.argv.length !== 3) || (process.argv[2] == "--help") ||
(process.argv[2] == "-h")) {
program.version(version);

console.log("Run it with the file to convert as first argument.");
console.log("It prints the output to stdout.");
process.exit(1);
}
program
.command('script <file>')
.description('transform a script to symbols')
.action(function(file){
fs.readFile(file, function (err, data) {
if (err) throw err;
process.stdout.write(hieroglyphy.hieroglyphyScript(data.toString()));
});
});

fs.readFile(process.argv[2], function (err, data) {
if (err) throw err;
console.log(hieroglyphy(data.toString()));
});
program
.command('string <file>')
.description('transform a string to symbols')
.action(function(file){
fs.readFile(file, function (err, data) {
if (err) throw err;
process.stdout.write(hieroglyphy.hieroglyphyString(data.toString()));
});
});

program
.command('number <file>')
.description('transform a number to symbols (errors may arise for lager n))')
.action(function(file){
fs.readFile(file, function (err, data) {
if (err) throw err;
process.stdout.write(hieroglyphy.hieroglyphyNumber(data.toString()));
});
});

program.parse(process.argv);

0 comments on commit 54bb07f

Please sign in to comment.