-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #464 from /issues/27-hs-config
Added hs config commands
- Loading branch information
Showing
25 changed files
with
812 additions
and
135 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
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,49 @@ | ||
const chalk = require('chalk'); | ||
const { table } = require('table'); | ||
const { mergeDeep } = require('./utils'); | ||
|
||
const tableConfigDefaults = { | ||
singleLine: true, | ||
border: { | ||
topBody: '', | ||
topJoin: '', | ||
topLeft: '', | ||
topRight: '', | ||
|
||
bottomBody: '', | ||
bottomJoin: '', | ||
bottomLeft: '', | ||
bottomRight: '', | ||
|
||
bodyLeft: '', | ||
bodyRight: '', | ||
bodyJoin: '', | ||
|
||
joinBody: '', | ||
joinLeft: '', | ||
joinRight: '', | ||
joinJoin: '', | ||
}, | ||
columnDefault: { | ||
paddingLeft: 0, | ||
paddingRight: 1, | ||
}, | ||
drawHorizontalLine: () => { | ||
return false; | ||
}, | ||
}; | ||
|
||
const getTableContents = (tableData = [], tableConfig = {}) => { | ||
const mergedConfig = mergeDeep({}, tableConfigDefaults, tableConfig); | ||
|
||
return table(tableData, mergedConfig); | ||
}; | ||
|
||
const getTableHeader = headerItems => { | ||
return headerItems.map(headerItem => chalk.bold(headerItem)); | ||
}; | ||
|
||
module.exports = { | ||
getTableContents, | ||
getTableHeader, | ||
}; |
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,35 @@ | ||
/** | ||
* Simple object check. | ||
* @param item | ||
* @returns {boolean} | ||
*/ | ||
const isObject = item => { | ||
return item && typeof item === 'object' && !Array.isArray(item); | ||
}; | ||
|
||
/** | ||
* Deep merge two objects. | ||
* @param target | ||
* @param ...sources | ||
*/ | ||
const mergeDeep = (target, ...sources) => { | ||
if (!sources.length) return target; | ||
const source = sources.shift(); | ||
|
||
if (isObject(target) && isObject(source)) { | ||
for (const key in source) { | ||
if (isObject(source[key])) { | ||
if (!target[key]) Object.assign(target, { [key]: {} }); | ||
mergeDeep(target[key], source[key]); | ||
} else { | ||
Object.assign(target, { [key]: source[key] }); | ||
} | ||
} | ||
} | ||
|
||
return mergeDeep(target, ...sources); | ||
}; | ||
|
||
module.exports = { | ||
mergeDeep, | ||
}; |
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
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,21 @@ | ||
const { addConfigOptions, addAccountOptions } = require('../lib/commonOpts'); | ||
const list = require('./accounts/list'); | ||
const rename = require('./accounts/rename'); | ||
|
||
exports.command = 'accounts'; | ||
exports.describe = 'Commands for working with accounts'; | ||
|
||
exports.builder = yargs => { | ||
addConfigOptions(yargs, true); | ||
addAccountOptions(yargs, true); | ||
|
||
yargs | ||
.command({ | ||
...list, | ||
aliases: 'ls', | ||
}) | ||
.command(rename) | ||
.demandCommand(1, ''); | ||
|
||
return yargs; | ||
}; |
Oops, something went wrong.