Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 6 commits
  • 2 files changed
  • 0 commit comments
  • 3 contributors
Showing with 126 additions and 127 deletions.
  1. +2 −2 lib/app/addons/ac/url.common.js
  2. +124 −125 lib/management/cli.js
View
4 lib/app/addons/ac/url.common.js
@@ -53,11 +53,11 @@ YUI.add('mojito-url-addon', function(Y, NAME) {
query = base + '.' + action;
params = (typeof routeParams === 'string' ? Y.QueryString.parse(routeParams) :
- Y.merge(routeParams || {}));
+ Y.merge(routeParams || {}));
if (urlParams) {
urlParams = (typeof urlParams === 'string' ? Y.QueryString.parse(urlParams) :
- urlParams);
+ urlParams);
// adding querystring params to routeParams and let
// the url maker to create the proper url. Empty params
View
249 lib/management/cli.js
@@ -9,7 +9,7 @@
(function() {
-'use strict';
+ 'use strict';
/**
* @fileoverview Mojito command loader/execution harness. The cli parses the
@@ -33,164 +33,163 @@
// Prerequisites
// ----------------------------------------------------------------------------
-var utils = require('./utils'),
- libpath = require('path');
+ var utils = require('./utils'),
+ libpath = require('path');
// ----------------------------------------------------------------------------
// CLI Root Object
// ----------------------------------------------------------------------------
-/**
- * The Command Line Interpreter object. All testable methods and attributes
- * are properties of this object.
- */
-function CLI() {
-};
+ /**
+ * The Command Line Interpreter object. All testable methods and attributes
+ * are properties of this object.
+ */
+ function CLI() {
+ }
// ----------------------------------------------------------------------------
// Internal Helper Functions
// ----------------------------------------------------------------------------
-/*
- * Creates a map keyed by both short and long option names, to simplify lookup
- * of option info from command line args.
- * @param {Object} optionInfo Option information in the form of an array of
- * objects containing option descriptions with the following keys:
- * shortName - Short (1-char) option name, without leading dash (e.g. 'v').
- * longName - Long option name, without leading dashes (e.g. 'verbose').
- * hasValue - True if option requires a value. Optional; default false.
- * @return {Object} The option map, an object whose keys are the expanded
- * option values such as {'-v': {...}, '--verbose': {...}} and whose values
- * are the option info.
- */
-CLI._makeOptionMap = function(optionInfo) {
- var optionMap = {};
-
- if (optionInfo) {
- optionInfo.forEach(function(info) {
- if (info.shortName) {
- optionMap['-' + info.shortName] = info;
- }
- if (info.longName) {
- optionMap['--' + info.longName] = info;
- }
- });
- }
-
- return optionMap;
-}
-
+ /*
+ * Creates a map keyed by both short and long option names, to simplify
+ * lookup of option info from command line args.
+ * @param {Object} optionInfo Option information in the form of an array of
+ * objects containing option descriptions with the following keys:
+ * shortName - Short (1-char) option name, without leading dash ('v').
+ * longName - Long option name, without leading dashes ('verbose').
+ * hasValue - True if option requires a value. Optional; default false.
+ * @return {Object} The option map, an object whose keys are the expanded
+ * option values such as {'-v': {...}, '--verbose': {...}} and whose
+ * values are the option info.
+ */
+ CLI._makeOptionMap = function(optionInfo) {
+ var optionMap = {};
+
+ if (optionInfo) {
+ optionInfo.forEach(function(info) {
+ if (info.shortName) {
+ optionMap['-' + info.shortName] = info;
+ }
+ if (info.longName) {
+ optionMap['--' + info.longName] = info;
+ }
+ });
+ }
-/*
- * Parses command line args based on the provided option info.
- * @param {Array} args A command line argument string split by whitespace.
- * @param {Object} optionInfo Option information in the form of an array of
- * objects containing option descriptions with the following keys:
- * shortName - Short (1-char) option name, without leading dash (e.g. 'v').
- * longName - Long option name, without leading dashes (e.g. 'verbose').
- * hasValue - True if option requires a value. Optional; default false.
- * @return {Object} A map with three keys:
- * params - an array of the specified parameters
- * options - a map of options, keyed by long name
- * errors - an array of error strings for reporting
- */
-CLI._parseArgs = function(args, optionInfo) {
- var optionMap = CLI._makeOptionMap(optionInfo),
- params = [],
- options = {},
- errors = [],
- option,
- arg;
-
- if (!args) {
- return { params: params, options: options, errors: errors };
- }
+ return optionMap;
+ };
+
+
+ /*
+ * Parses command line args based on the provided option info.
+ * @param {Array} args A command line argument string split by whitespace.
+ * @param {Object} optionInfo Option information in the form of an array of
+ * objects containing option descriptions with the following keys:
+ * shortName - Short (1-char) option name, without leading dash ('v').
+ * longName - Long option name, without leading dashes ('verbose').
+ * hasValue - True if option requires a value. Optional; default false.
+ * @return {Object} A map with three keys:
+ * params - an array of the specified parameters
+ * options - a map of options, keyed by long name
+ * errors - an array of error strings for reporting
+ */
+ CLI._parseArgs = function(args, optionInfo) {
+ var optionMap = CLI._makeOptionMap(optionInfo),
+ params = [],
+ options = {},
+ errors = [],
+ option,
+ arg;
+
+ if (!args) {
+ return { params: params, options: options, errors: errors };
+ }
- while (args.length > 0) {
- arg = args.shift();
- if (arg.charAt(0) === '-') {
- option = optionMap[arg];
- if (option) {
- if (option.hasValue) {
- if (args.length === 0) {
- errors.push('Missing value for option: ' + arg);
+ while (args.length > 0) {
+ arg = args.shift();
+ if (arg.charAt(0) === '-') {
+ option = optionMap[arg];
+ if (option) {
+ if (option.hasValue) {
+ if (args.length === 0) {
+ errors.push('Missing value for option: ' + arg);
+ } else {
+ options[option.longName] = args.shift();
+ }
} else {
- options[option.longName] = args.shift();
+ options[option.longName] = true;
}
} else {
- options[option.longName] = true;
+ errors.push('Invalid option: ' + arg);
}
} else {
- errors.push('Invalid option: ' + arg);
+ params.push(arg);
}
- } else {
- params.push(arg);
}
- }
- return { params: params, options: options, errors: errors };
-}
+ return { params: params, options: options, errors: errors };
+ };
// ----------------------------------------------------------------------------
// Public Functions
// ----------------------------------------------------------------------------
-/**
- * Executes command line processing. If a valid command is parsed and loaded the
- * command module's run method will be invoked. The command module's exported
- * options are used to assist in parsing the command line.
- *
- */
-CLI.run = function() {
- var args = process.argv.slice(2),
- commandName = (args.length === 0 ? 'help' : args.shift()),
- command,
- argInfo;
-
- try {
- command = require('mojito-cli-cmd-' + commandName);
- } catch (e) {
+ /**
+ * Executes command line processing. If a valid command is parsed and loaded
+ * the command module's run method will be invoked. The command module's
+ * exported options are used to assist in parsing the command line.
+ */
+ CLI.run = function() {
+ var args = process.argv.slice(2),
+ commandName = (args.length === 0 ? 'help' : args.shift()),
+ command,
+ argInfo;
+
try {
- command = require(libpath.join(__dirname, '../app/commands/',
- commandName));
- } catch (e2) {
- utils.error('Error loading command: ' + command + ' ' + e2.message,
- 'mojito <command> [<params>] [<options>]');
- return;
+ command = require('mojito-cli-cmd-' + commandName);
+ } catch (e) {
+ try {
+ command = require(libpath.join(__dirname, '../app/commands/',
+ commandName));
+ } catch (e2) {
+ utils.error('Error loading command: ' + command + ' ' + e2.message,
+ 'mojito <command> [<params>] [<options>]');
+ return;
+ }
}
- }
-
- if (args.length === 0) {
- argInfo = { command: 'help', params: [], options: {} };
- } else {
- argInfo = CLI._parseArgs(args, command.options);
- }
- if (argInfo.errors && argInfo.errors.length > 0) {
- argInfo.errors.forEach(function(e) {
- utils.log(e);
- });
- utils.error('Invalid command line.', "Try 'mojito help <command>'.");
- return;
- }
-
- command.run(argInfo.params, argInfo.options, function(err, usg, die) {
- if (err) {
- utils.error(err, usg, die);
+ if (args.length === 0) {
+ argInfo = { command: 'help', params: [], options: {} };
} else {
- utils.success('mojito done.');
+ argInfo = CLI._parseArgs(args, command.options);
}
- });
-}
+
+ if (argInfo.errors && argInfo.errors.length > 0) {
+ argInfo.errors.forEach(function(e) {
+ utils.log(e);
+ });
+ utils.error('Invalid command line.', "Try 'mojito help <command>'.");
+ return;
+ }
+
+ command.run(argInfo.params, argInfo.options, function(err, usg, die) {
+ if (err) {
+ utils.error(err, usg, die);
+ } else {
+ utils.success('mojito done.');
+ }
+ });
+ };
// ----------------------------------------------------------------------------
// EXPORT(S)
// ----------------------------------------------------------------------------
-/**
- * Export the CLI object, which includes all testable functions.
- * @type {Function}
- */
-exports = module.exports = CLI;
+ /**
+ * Export the CLI object, which includes all testable functions.
+ * @type {Function}
+ */
+ module.exports = CLI;
}());

No commit comments for this range

Something went wrong with that request. Please try again.