-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added, ability to remove ignoreFields through CLI
- Loading branch information
Showing
6 changed files
with
101 additions
and
17 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 |
---|---|---|
@@ -0,0 +1,79 @@ | ||
const ldColl = require('lodash/collection'); | ||
const ldObject = require('lodash/object'); | ||
const ldArray = require('lodash/array'); | ||
const shell = require('shelljs'); | ||
const logging = require('debug')('Weaver:bin:commands:add:ignore'); | ||
const { getConfig, setConfig, getClientIDs } = require('../../lib/config'); | ||
|
||
const clientIDs = getClientIDs(); | ||
let defaultMsg = `Usage:\n | ||
weaver remove ignore -i [clientID] -n [<namespace> ...] | ||
`; | ||
if (clientIDs.length) { | ||
defaultMsg += `\nAvailable clientIDs: ${clientIDs.join(' ')}\n`; | ||
} else { | ||
defaultMsg += '\nNo clients are configured yet, try adding a client first.\n'; | ||
} | ||
|
||
const commandName = 'ignore'; | ||
const commandDesc = 'Remove an ignore collection/index namespace of a client.'; | ||
const commandSpec = (yargs) => { | ||
shell.echo(defaultMsg); | ||
return yargs | ||
.options({ | ||
clientid: { | ||
alias: 'i', | ||
choices: clientIDs, | ||
demandOption: true, | ||
describe: 'The client id to remove the namespace from.', | ||
type: 'string', | ||
}, | ||
namespaces: { | ||
alias: 'n', | ||
demandOption: true, | ||
describe: 'The namespaces to avoid querying upon.', | ||
type: 'array', | ||
}, | ||
}); | ||
}; | ||
|
||
const removeIgnores = (params = {}) => { | ||
const CFG = { ...getConfig() }; | ||
const dataClient = ldColl.find(CFG.dataClients, (c) => c.clientId === params.clientid); | ||
const clientIdx = ldArray.findIndex(CFG.dataClients, (c) => c.clientId === params.clientid); | ||
const newClient = ldObject.assign({}, dataClient); | ||
const clientOpts = newClient.client ? newClient.client : {}; | ||
let { ignoreFields = [] } = clientOpts; | ||
|
||
if (clientIdx < 0) return CFG; | ||
ignoreFields = ignoreFields.filter((f) => params.namespaces.indexOf(f) < 0); | ||
clientOpts.ignoreFields = ldArray.uniq(ignoreFields); | ||
newClient.client = ldObject.assign({}, clientOpts); | ||
CFG.dataClients[clientIdx] = newClient; | ||
|
||
return CFG; | ||
}; | ||
|
||
const commandHandler = (params) => { | ||
logging('ignorefield params', params); | ||
const newClientConfig = removeIgnores(params); | ||
if (newClientConfig) { | ||
try { | ||
logging('Saving ignoreFields'); | ||
setConfig(newClientConfig); | ||
shell.echo('Saved new settings:', JSON.stringify(newClientConfig, null, 2)); | ||
} catch (error) { | ||
shell.echo(error); | ||
return false; | ||
} | ||
} | ||
return params; | ||
}; | ||
|
||
module.exports = { | ||
commandName, | ||
commandDesc, | ||
commandSpec, | ||
commandHandler, | ||
removeIgnores, | ||
}; |
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,3 +1,4 @@ | ||
module.exports = { | ||
client: require('./client'), | ||
ignore: require('./ignore'), | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 +1 @@ | ||
"use strict";module.exports={client:require("./client")}; | ||
"use strict";module.exports={client:require("./client"),ignore:require("./ignore")}; |