Skip to content

Commit

Permalink
feat(main): implement type: branch
Browse files Browse the repository at this point in the history
  • Loading branch information
isuke committed Feb 26, 2018
1 parent 4d72a9c commit 33388d5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion git-consistent
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const setOptions = (program, definitions, terms) => {
const optionName = term == 'subject' ? `-m, --${term}` : `--${term}`
const valueStr = definition.required ? `<${term}>` : `[${term}]`
const defaultValue = definition.default
if (type !== 'variable') program.option(`${optionName} ${valueStr}`, definition.description, defaultValue)
if (! ['variable', 'branch'].includes(type)) program.option(`${optionName} ${valueStr}`, definition.description, defaultValue)
return setOptions(program, definitions, _.tail(terms))
}
}
Expand Down
16 changes: 16 additions & 0 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,19 @@ const inputText = (term, _definition) => {
return values.join("\n").trim()
}

const getCurrentBranchName = () => {
return execSync("git rev-parse --abbrev-ref HEAD").toString().trim()
}

const branchText = (_term, definition) => {
const currentBranchName = getCurrentBranchName()
const regExp = new RegExp(definition.regExp)
const matchNum = definition.regExpMatchNum || 1
const match = currentBranchName.match(regExp)
const value = match ? match[matchNum] : ''
return value
}

const input = (term, definition) => {
const type = definition.type
let inputValue
Expand All @@ -75,6 +88,9 @@ const input = (term, definition) => {
case 'text':
inputValue = inputText(term, definition)
break
case 'branch':
inputValue = branchText(term, definition)
break
case 'variable':
break
default:
Expand Down

0 comments on commit 33388d5

Please sign in to comment.