cli: don't coerce args in option store

This commit is contained in:
bordun 2020-03-29 15:05:52 +02:00
parent 8085749aeb
commit 781a13b1a8
3 changed files with 14 additions and 20 deletions

View file

@ -102,7 +102,7 @@ module.exports = {
}
}
var state = {
state: settings.read('state'),
state: JSON.parse(fs.readFileSync(settings.read('state'), 'utf8')),
send: send
}
ipc.send('stateLoad', state, clientId)
@ -145,7 +145,7 @@ module.exports = {
if (!ok) return
if (!data.path || settings.read('remote-saving') && !settings.read('remote-saving').test(ipc.clients[clientId].address)) {
if (!data.path || settings.read('remote-saving') && !RegExp(settings.read('remote-saving')).test(ipc.clients[clientId].address)) {
return ipc.send('notify', {
icon: 'save',

View file

@ -10,17 +10,11 @@ module.exports = {
'l': {alias: 'load', type: 'string', file: {name: 'OSC Session (.json)', extensions: ['json', 'js']}, describe: 'session file to load',
check: (arg)=>{
return fs.lstatSync(arg) ? true : 'Session file not found: ' + arg
},
coerce: (arg)=>{
return JSON.parse(fs.readFileSync(arg, 'utf8'))
}
},
'state': {type: 'string', file: {name: 'OSC State (.state)', extensions: ['state']}, describe: 'state file to load',
check: (arg)=>{
return fs.lstatSync(arg) ? true : 'State file not found: ' + arg
},
coerce: (arg)=>{
return JSON.parse(fs.readFileSync(arg, 'utf8'))
}
},
'c': {alias: 'custom-module', type: 'array', file: {name: 'OSC Custom module (.js)', extensions: ['js']}, describe: 'custom module file to load (custom options can be passed after the filename)',
@ -63,15 +57,6 @@ module.exports = {
check: (o)=>{
return o.some(item=>!item.match(/^[^=]*=[^=]*$/)) ?
'Options must be key=value pairs' : true
},
coerce: (arg)=>{
var opts = {}
for (var o of arg) {
if (!o.includes('=')) continue
var [k, v] = o.split('=')
opts[k] = v
}
return opts
}
},
'disable-vsync': {type: 'boolean', describe: 'disable gui\'s vertical synchronization', restart: true},
@ -86,8 +71,7 @@ module.exports = {
msg = e
}
return msg
},
coerce: arg=>RegExp(arg)
}
},
'remote-root': {type: 'string', describe: 'set remote file browsing root folder', file: {folder: true}},
'instance-name': {type: 'string', describe: 'used to differenciate multiple instances in a zeroconf network'},

View file

@ -15,6 +15,16 @@ var urlparser = require('url'),
clients = {},
httpCheckTimeout
var clientOptions = {}
if (settings.read('client-options')) {
for (var o of settings.read('client-options')) {
if (!o.includes('=')) continue
var [k, v] = o.split('=')
clientOptions[k] = v
}
}
function httpRoute(req, res) {
res.sendFile = (path)=>{
@ -30,7 +40,7 @@ function httpRoute(req, res) {
fs.createReadStream(path.resolve(__dirname + '/../client/index.html'))
.pipe(replaceStream('</body>', `
<script>
window.ENV=${JSON.stringify(settings.read('client-options'))}
window.ENV=${JSON.stringify(clientOptions)}
window.READ_ONLY=${JSON.stringify(settings.read('read-only'))}
</script></body>`))
.pipe(res)