Skip to content
This repository was archived by the owner on Sep 19, 2019. It is now read-only.

Commit 301b319

Browse files
committed
Handling file-mode for paremeters
1 parent 80e1976 commit 301b319

File tree

1 file changed

+22
-17
lines changed

1 file changed

+22
-17
lines changed

lib/utils.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -163,29 +163,34 @@ module.exports.searchItems = function(search, client, fn, errFn) {
163163
module.exports.castFields = function(type, fields) {
164164
var output = {};
165165
_.forEach(fields, function(field) {
166-
try { // field is a valid JSON
166+
if (field[0] == '@') {
167+
var fs = require('fs');
168+
output = JSON.parse(fs.readFileSync(field.substring(1), 'utf-8'));
169+
} else {
170+
try { // field is a valid JSON
167171

168-
var parsed = JSON.parse(field);
169-
if (typeof(parsed) === 'object') {
170-
output = _.defaults(output, parsed);
171-
}
172+
var parsed = JSON.parse(field);
173+
if (typeof(parsed) === 'object') {
174+
output = _.defaults(output, parsed);
175+
}
172176

173-
} catch (e) { // field is an operation
177+
} catch (e) { // field is an operation
174178

175-
var split = field.split('=');
176-
var key = split[0], value = split[1];
179+
var split = field.split('=');
180+
var key = split[0], value = split[1];
177181

178-
if (['true', 'false', 'True', 'False'].indexOf(value) >= 0) {
179-
value = validator.toBoolean(value.toLowerCase());
180-
}
182+
if (['true', 'false', 'True', 'False'].indexOf(value) >= 0) {
183+
value = validator.toBoolean(value.toLowerCase());
184+
}
181185

182-
if (validator.isNumeric(value)) {
183-
value = parseInt(value);
184-
}
186+
if (validator.isNumeric(value)) {
187+
value = parseInt(value);
188+
}
185189

186-
output[key] = value;
187-
// FIXME: cast values accordingly to the resources
188-
// FIXME: type can be a type OR an object, if so, we need to resolve type
190+
output[key] = value;
191+
// FIXME: cast values accordingly to the resources
192+
// FIXME: type can be a type OR an object, if so, we need to resolve type
193+
}
189194
}
190195

191196
});

0 commit comments

Comments
 (0)