Parses alias for an option and adds it to optionsAliases @method parseAlias @param {Object} option @param {Object|String} alias @return {Object}
(option, alias)
| 453 | @return {Object} |
| 454 | */ |
| 455 | parseAlias(option, alias) { |
| 456 | let aliasType = typeof alias; |
| 457 | let key, value, aliasValue; |
| 458 | |
| 459 | if (isValidAlias(alias, option.type)) { |
| 460 | if (aliasType === 'string') { |
| 461 | key = alias; |
| 462 | value = [`--${option.name}`]; |
| 463 | } else if (aliasType === 'object') { |
| 464 | key = Object.keys(alias)[0]; |
| 465 | value = [`--${option.name}`, alias[key]]; |
| 466 | } |
| 467 | } else { |
| 468 | if (Array.isArray(alias)) { |
| 469 | aliasType = 'array'; |
| 470 | aliasValue = alias.join(','); |
| 471 | } else { |
| 472 | aliasValue = alias; |
| 473 | try { |
| 474 | aliasValue = JSON.parse(alias); |
| 475 | } catch (e) { |
| 476 | const logger = require('heimdalljs-logger')('ember-cli/models/command'); |
| 477 | logger.error(e); |
| 478 | } |
| 479 | } |
| 480 | throw new Error( |
| 481 | `The "${aliasValue}" [type:${aliasType}] alias is not an acceptable value. ` + |
| 482 | `It must be a string or single key object with a string value (for example, "value" or { "key" : "value" }).` |
| 483 | ); |
| 484 | } |
| 485 | |
| 486 | return { |
| 487 | key, |
| 488 | value, |
| 489 | original: alias, |
| 490 | }; |
| 491 | }, |
| 492 | |
| 493 | /** |
| 494 | * @method assignAlias |
nothing calls this directly
no test coverage detected
searching dependent graphs…