1+ import { CliConfig } from '../models/config' ;
2+
13const SilentError = require ( 'silent-error' ) ;
24const Command = require ( '../ember-cli/lib/models/command' ) ;
3- import { CliConfig } from '../models/config' ;
5+
6+
7+ export interface SetOptions {
8+ global ?: boolean ;
9+ }
410
511
612const SetCommand = Command . extend ( {
@@ -9,7 +15,7 @@ const SetCommand = Command.extend({
915 works : 'everywhere' ,
1016
1117 availableOptions : [
12- { name : 'global' , type : Boolean , default : false , aliases : [ 'g' ] } ,
18+ { name : 'global' , type : Boolean , ' default' : false , aliases : [ 'g' ] } ,
1319 ] ,
1420
1521 asBoolean : function ( raw : string ) : boolean {
@@ -28,13 +34,25 @@ const SetCommand = Command.extend({
2834 return + raw ;
2935 } ,
3036
31- run : function ( commandOptions : any , rawArgs : string [ ] ) : Promise < void > {
37+ run : function ( commandOptions : SetOptions , rawArgs : string [ ] ) : Promise < void > {
3238 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+
3554 const type = config . typeOf ( jsonPath ) ;
3655 let value : any = rawValue ;
37-
3856 switch ( type ) {
3957 case 'boolean' : value = this . asBoolean ( rawValue ) ; break ;
4058 case 'number' : value = this . asNumber ( rawValue ) ; break ;
0 commit comments