From e6d8ad53ea63866dfa9adebe3fe0b7c458a0bd93 Mon Sep 17 00:00:00 2001 From: Mahendra Date: Thu, 12 Mar 2020 20:11:49 +0530 Subject: [PATCH] =?UTF-8?q?feat:=20=F0=9F=8E=B8=20refCount=20for=20current?= =?UTF-8?q?=20execution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit refCount should only be valid for current execution BREAKING CHANGE: 🧨 No ✅ Closes: #464 --- README.md | 10 +--------- index.js | 6 +----- src/app.js | 5 +++-- src/utils/git.js | 9 +++++---- 4 files changed, 10 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 2b2e82c0..c8d6b293 100644 --- a/README.md +++ b/README.md @@ -151,17 +151,9 @@ Options include: * A hex color code to style Check It Out * refCount * Type: Number - * Default: `500` + * Default: `--count 500` * Total number of references to show. -To set `refCount` , start with the flag `--count` - -``` -checkit --count 20 - OR -checkit --count=20 -``` - To reset Check It Out to its original configurations listed above, start with the flag `--reset-config`: ``` diff --git a/index.js b/index.js index 71fdd086..47c782da 100755 --- a/index.js +++ b/index.js @@ -2,11 +2,7 @@ const app = require('./dist/app'); -const args = process.argv - .slice(2) - .reduce((acc, val) => acc.concat(val.split('=')), []); // support both "key=val" and "key val" - -app.start(args).catch(error => { +app.start(process.argv.slice(2)).catch(error => { console.error(error); process.exit(1); }); diff --git a/src/app.js b/src/app.js index d276f496..da555053 100644 --- a/src/app.js +++ b/src/app.js @@ -54,13 +54,14 @@ const defaultConfig = { const conf = new Configstore(pkg.name, defaultConfig); export const start = async args => { + let refCount; if (args[0] === '-v' || args[0] === '--version') { process.stdout.write(pkg.version + '\n'); process.exit(0); } else if (args[0] === '--reset-config') { conf.all = defaultConfig; } else if (args[0] === '--count' && args[1]) { - conf.set('refCount', parseInt(args[1])); + refCount = args[1]; } const gitLogArguments = conf.get('gitLogArguments'); @@ -348,7 +349,7 @@ export const start = async args => { }; try { - state.setRemotes(await getRefData()); + state.setRemotes(await getRefData(refCount)); state.setCurrentRemoteIndex( state.remotes.findIndex(remote => remote.name === 'heads'), diff --git a/src/utils/git.js b/src/utils/git.js index 5be3d9a8..a282a768 100644 --- a/src/utils/git.js +++ b/src/utils/git.js @@ -27,8 +27,8 @@ export const closeGitResponse = () => { * * @returns {Promise} payload and uniqueRemotes */ -export const getRefData = async () => { - const refs = await getRefs(); +export const getRefData = async refCount => { + const refs = await getRefs(refCount); const remotes = []; @@ -177,12 +177,13 @@ export const formatRemoteBranches = async output => { * * @return {Promise} String list of each ref associated with repository. */ -const getRefs = async () => { +const getRefs = async refCount => { + refCount = refCount ? refCount : conf.get('refCount'); const args = [ 'for-each-ref', `--sort=${conf.get('sort')}`, '--format=%(refname)', - `--count=${conf.get('refCount')}`, + `--count=${refCount}`, ]; return formatRemoteBranches(await execGit(args));