1 | "use strict";
|
2 | var config_1 = require('../models/config');
|
3 | var SilentError = require('silent-error');
|
4 | var Command = require('../ember-cli/lib/models/command');
|
5 | var SetCommand = Command.extend({
|
6 | name: 'set',
|
7 | description: 'Set a value in the configuration.',
|
8 | works: 'everywhere',
|
9 | availableOptions: [
|
10 | { name: 'global', type: Boolean, 'default': false, aliases: ['g'] },
|
11 | ],
|
12 | asBoolean: function (raw) {
|
13 | if (raw == 'true' || raw == '1') {
|
14 | return true;
|
15 | }
|
16 | else if (raw == 'false' || raw == '' || raw == '0') {
|
17 | return false;
|
18 | }
|
19 | else {
|
20 | throw new SilentError("Invalid boolean value: \"" + raw + "\"");
|
21 | }
|
22 | },
|
23 | asNumber: function (raw) {
|
24 | if (Number.isNaN(+raw)) {
|
25 | throw new SilentError("Invalid number value: \"" + raw + "\"");
|
26 | }
|
27 | return +raw;
|
28 | },
|
29 | run: function (commandOptions, rawArgs) {
|
30 | var _this = this;
|
31 | return new Promise(function (resolve) {
|
32 | var config = commandOptions.global ? config_1.CliConfig.fromGlobal() : config_1.CliConfig.fromProject();
|
33 | if (config === null) {
|
34 | throw new SilentError('No config found. If you want to use global configuration, '
|
35 | + 'you need the --global argument.');
|
36 | }
|
37 | var jsonPath = rawArgs[0], rawValue = rawArgs[1];
|
38 | if (rawValue === undefined) {
|
39 | _a = jsonPath.split('=', 2), jsonPath = _a[0], rawValue = _a[1];
|
40 | if (rawValue === undefined) {
|
41 | throw new SilentError('Must specify a value.');
|
42 | }
|
43 | }
|
44 | var type = config.typeOf(jsonPath);
|
45 | var value = rawValue;
|
46 | switch (type) {
|
47 | case 'boolean':
|
48 | value = _this.asBoolean(rawValue);
|
49 | break;
|
50 | case 'number':
|
51 | value = _this.asNumber(rawValue);
|
52 | break;
|
53 | case 'string':
|
54 | value = rawValue;
|
55 | break;
|
56 | default: value = JSON.parse(rawValue);
|
57 | }
|
58 | config.set(jsonPath, value);
|
59 | config.save();
|
60 | resolve();
|
61 | var _a;
|
62 | });
|
63 | }
|
64 | });
|
65 | Object.defineProperty(exports, "__esModule", { value: true });
|
66 | exports.default = SetCommand;
|
67 |
|
\ | No newline at end of file |