2017-07-10 22:03:46 +02:00
import { BaseCommand } from './base-command.js' ;
2017-07-18 20:49:47 +02:00
import { _ , setLocale } from 'lib/locale.js' ;
import { app } from './app.js' ;
2017-07-10 22:03:46 +02:00
import { Setting } from 'lib/models/setting.js' ;
class Command extends BaseCommand {
usage ( ) {
2017-07-28 00:59:34 +02:00
return _ ( 'config [name] [value]' ) ;
2017-07-10 22:03:46 +02:00
}
description ( ) {
2017-07-24 20:58:11 +02:00
return _ ( "Gets or sets a config value. If [value] is not provided, it will show the value of [name]. If neither [name] nor [value] is provided, it will list the current configuration." ) ;
2017-07-10 22:03:46 +02:00
}
2017-07-24 21:47:01 +02:00
options ( ) {
return [
[ '-v, --verbose' , _ ( 'Also displays hidden config variables.' ) ] ,
] ;
}
2017-07-10 22:03:46 +02:00
async action ( args ) {
2017-07-24 20:58:11 +02:00
const renderKeyValue = ( name ) => {
const value = Setting . value ( name ) ;
if ( Setting . isEnum ( name ) ) {
return _ ( '%s = %s (%s)' , name , value , Setting . enumOptionLabel ( name , value ) ) ;
} else {
return _ ( '%s = %s' , name , value ) ;
}
}
2017-07-10 22:03:46 +02:00
if ( ! args . name && ! args . value ) {
2017-07-24 21:47:01 +02:00
let keys = args . options . verbose ? Setting . keys ( ) : Setting . publicKeys ( ) ;
2017-07-10 22:03:46 +02:00
for ( let i = 0 ; i < keys . length ; i ++ ) {
2017-07-24 20:58:11 +02:00
this . log ( renderKeyValue ( keys [ i ] ) ) ;
2017-07-10 22:03:46 +02:00
}
return ;
}
if ( args . name && ! args . value ) {
2017-07-24 20:58:11 +02:00
this . log ( renderKeyValue ( args . name ) ) ;
2017-07-10 22:03:46 +02:00
return ;
}
Setting . setValue ( args . name , args . value ) ;
2017-07-18 20:49:47 +02:00
if ( args . name == 'locale' ) {
setLocale ( Setting . value ( 'locale' ) ) ;
app ( ) . onLocaleChanged ( ) ;
}
2017-07-10 22:03:46 +02:00
await Setting . saveAll ( ) ;
}
}
module . exports = Command ;