1
+ import { CliConfig } from '../models/config' ;
2
+
1
3
const SilentError = require ( 'silent-error' ) ;
2
4
const Command = require ( '../ember-cli/lib/models/command' ) ;
3
- import { CliConfig } from '../models/config' ;
5
+
6
+
7
+ export interface SetOptions {
8
+ global ?: boolean ;
9
+ }
4
10
5
11
6
12
const SetCommand = Command . extend ( {
@@ -9,7 +15,7 @@ const SetCommand = Command.extend({
9
15
works : 'everywhere' ,
10
16
11
17
availableOptions : [
12
- { name : 'global' , type : Boolean , default : false , aliases : [ 'g' ] } ,
18
+ { name : 'global' , type : Boolean , ' default' : false , aliases : [ 'g' ] } ,
13
19
] ,
14
20
15
21
asBoolean : function ( raw : string ) : boolean {
@@ -28,13 +34,25 @@ const SetCommand = Command.extend({
28
34
return + raw ;
29
35
} ,
30
36
31
- run : function ( commandOptions : any , rawArgs : string [ ] ) : Promise < void > {
37
+ run : function ( commandOptions : SetOptions , rawArgs : string [ ] ) : Promise < void > {
32
38
return new Promise < void > ( resolve => {
33
- const [ jsonPath , rawValue ] = rawArgs ;
34
- const config = CliConfig . fromProject ( ) ;
39
+ const config = commandOptions . global ? CliConfig . fromGlobal ( ) : CliConfig . fromProject ( ) ;
40
+ if ( config === null ) {
41
+ throw new SilentError ( 'No config found. If you want to use global configuration, '
42
+ + 'you need the --global argument.' ) ;
43
+ }
44
+
45
+ let [ jsonPath , rawValue ] = rawArgs ;
46
+
47
+ if ( rawValue === undefined ) {
48
+ [ jsonPath , rawValue ] = jsonPath . split ( '=' , 2 ) ;
49
+ if ( rawValue === undefined ) {
50
+ throw new SilentError ( 'Must specify a value.' ) ;
51
+ }
52
+ }
53
+
35
54
const type = config . typeOf ( jsonPath ) ;
36
55
let value : any = rawValue ;
37
-
38
56
switch ( type ) {
39
57
case 'boolean' : value = this . asBoolean ( rawValue ) ; break ;
40
58
case 'number' : value = this . asNumber ( rawValue ) ; break ;
0 commit comments