-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,34 @@ | ||
import * as jp from 'jsonpath' | ||
import {last, assocPath, merge, __} from 'ramda' | ||
|
||
import {apps} from '../../../clients' | ||
|
||
const {saveAppSettings} = apps | ||
const {getAppSettings, saveAppSettings} = apps | ||
|
||
const FIELDS_START_INDEX = 3 | ||
|
||
const castValue = value => { | ||
let parsedValue | ||
try { | ||
parsedValue = JSON.parse(value) | ||
} catch (err) { | ||
parsedValue = value | ||
} | ||
const numberCast = Number(value) | ||
return isNaN(numberCast) ? parsedValue : numberCast | ||
} | ||
|
||
export default { | ||
description: 'Set a value', | ||
requiredArgs: ['app', 'field', 'value'], | ||
handler: (app: string, field: string, value: string) => { | ||
const patch = {} | ||
jp.value(patch, '$.' + field, value) | ||
return saveAppSettings(app, patch) | ||
.then(res => JSON.stringify(res, null, 2)) | ||
requiredArgs: ['app', 'fields', 'value'], | ||
handler: (app: string, _field, _value, options) => { | ||
const value = last(options._) | ||
const fields = options._.slice(FIELDS_START_INDEX, options._.length - 1) | ||
const realValue = castValue(value) | ||
const commandSettings = assocPath(fields, realValue, {}) | ||
return getAppSettings(app) | ||
.then(merge(__, commandSettings)) | ||
.then(newSettings => JSON.stringify(newSettings, null, 2)) | ||
.tap(newSettings => saveAppSettings(app, newSettings)) | ||
.tap(console.log) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import * as jp from 'jsonpath' | ||
import {dissocPath} from 'ramda' | ||
|
||
import {apps} from '../../../clients' | ||
|
||
const {getAppSettings, saveAppSettings} = apps | ||
|
||
const FIELDS_START_INDEX = 3 | ||
|
||
export default { | ||
description: 'Unset a value', | ||
requiredArgs: ['app', 'field'], | ||
handler: (app: string, field: string) => { | ||
requiredArgs: ['app', 'fields'], | ||
handler: (app: string, _, options) => { | ||
const fields = options._.slice(FIELDS_START_INDEX) | ||
return getAppSettings(app) | ||
.tap(patch => jp.value(patch, `$.${field}`, null)) | ||
.then(patch => saveAppSettings(app, patch)) | ||
.then(res => JSON.stringify(res, null, 2)) | ||
.then(dissocPath(fields)) | ||
.then(newSettings => JSON.stringify(newSettings, null, 2)) | ||
.tap(newSettings => saveAppSettings(app, newSettings)) | ||
.tap(console.log) | ||
}, | ||
} |