Skip to content

Commit 9ab139d

Browse files
committed
feat(main): support not required enum
1 parent a261cc1 commit 9ab139d

4 files changed

Lines changed: 22 additions & 7 deletions

File tree

.git_consistent

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ type:
22
type: enum
33
required: true
44
description: 'commit type'
5-
suffix: ': '
65
values:
76
-
87
name: feat
@@ -46,6 +45,16 @@ type:
4645
-
4746
name: revert
4847
description: 'when reverts a previous commit'
48+
scope:
49+
type: enum
50+
required: false
51+
description: 'The scope could be specifying place of the commit change.'
52+
prefix: '('
53+
suffix: ')'
54+
values:
55+
-
56+
name: "main"
57+
description: 'git-consistent'
4958
subject:
5059
type: string
5160
required: true

.gitcommit_template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<type><subject>
1+
<type><scope>: <subject>
22

33
<body>

.vscode/launch.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
"args": [
1414
"-i",
1515
"--type='feat'",
16-
"--subject='add skip-options option'",
16+
// "--scope='main'",
17+
"--subject='this is test'",
18+
"--body='This is test.'",
1719
"-d"
1820
]
1921
}

git-consistent

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ const createProgram = (program, definitions, terms) => {
4444
}
4545

4646
const select = (term, definition) => {
47+
const none = "(none)"
4748
const header = `Select ${term}: `
48-
const values = _.map(definition.values, function (value) { return value.name }) // TODO: description
49-
const command = `echo '${values.join("\n")}' | fzf --reverse --cycle --header="${header}"`
49+
const choices = _.map(definition.values, function (value) { return `${value.name}\t${value.description}` })
50+
if (!definition.required) choices.unshift(`\t${none}`)
51+
const command = `echo '${_.replace(choices.join("\n"), "'", '"')}' | fzf --reverse --cycle --header="${header}"`
5052

51-
value = execSync(command, { stdio: ['inherit', 'pipe', 'inherit'], shell: true }).toString().trim()
53+
const selectedValue = execSync(command, { stdio: ['inherit', 'pipe', 'inherit'], shell: true }).toString().trim()
54+
const value = selectedValue.split("\t")[0]
55+
const v = value === none ? '' : value
5256
console.log(`${header}${value}`)
53-
return value
57+
return v
5458
}
5559

5660
const inputString = (term, _definition) => {

0 commit comments

Comments
 (0)