/* Copyright 2013 Daniel Wirtz Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ var util = require("util"), path = require("path"), colour = require("colour"); // Default alphabet var alphabet = require(path.join(__dirname, "alphabet", "straight.json")); module.exports = function(appName) { ascli.appName = appName; return ascli; }; module.exports.app = module.exports; // For backward compatibility /** * Builds a banner. * @param {string=} title App name * @param {string=} appendix Appendix, e.g. version * @returns {string} */ function ascli(title, appendix) { title = title || ascli.appName; appendix = appendix || ""; var lines = ["", "", ""], c, a, j, ac = ""; for (var i=0; i} alpha File name or alphabet to use * @returns {Function} ascli */ ascli.use = function(alpha) { if (typeof alpha === 'string') alphabet = require(alpha); else alphabet = alpha; return ascli; }; /** * Prints a final success message. * @param {string} msg Message text * @param {number=} code Exit code, defaults not to send it explicitly */ ascli.ok = function(msg, code) { process.stderr.write('\n '+ascli.appName.green.bold+' OK'.white.bold+(msg ? ' '+msg : '')+'\n'); if (typeof code !== 'undefined') process.exit(code); }; /** * Prints a final failure message. * @param {string} msg Message text * @param {number=} code Exit code, defaults to not send it explicitly */ ascli.fail = function(msg, code) { process.stderr.write('\n '+ascli.appName.red.bold+' ERROR'.white.bold+(msg ? ' '+msg : '')+'\n'); if (typeof code !== 'undefined') process.exit(code); }; /** * opt.js * @param {Array.=} argv * @returns {{node: string, script: string, argv: Array., opt: Object.}} */ ascli.optjs = require("optjs"); // Pre-run it var opt = ascli.optjs(); ascli.node = opt.node; ascli.script = opt.script; ascli.argv = opt.argv; ascli.opt = opt.opt; // Expose colour.js ascli.colour = ascli.colors = colour;