Skip to content

Commit 1eac0c2

Browse files
committed
feat(flags): support more git flags
1 parent f67b946 commit 1eac0c2

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

internal/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ const (
2424
FieldKeyTemplateSelect = "template-select"
2525
)
2626

27+
// Config represents a configuration object.
2728
type Config struct {
2829
defaultTmpl *templates.Template
2930
more []*templates.Template
3031
}
3132

33+
// New creates a new Config object.
3234
func New() *Config {
3335
return &Config{}
3436
}
@@ -154,6 +156,7 @@ func (c *Config) createTemplatesSelect(label string) *huh.Form {
154156
)
155157
}
156158

159+
// LoadTemplates reads a list of templates from the provided file.
157160
func LoadTemplates(file string) ([]*templates.Template, error) {
158161
if len(file) == 0 {
159162
return nil, nil
@@ -166,10 +169,12 @@ func LoadTemplates(file string) ([]*templates.Template, error) {
166169
return load(fd)
167170
}
168171

172+
// Load reads a list of templates from the provided byte slice.
169173
func Load(data []byte) ([]*templates.Template, error) {
170174
return load(bytes.NewReader(data))
171175
}
172176

177+
// load reads a list of templates from the provided io.Reader.
173178
func load(reader io.Reader) ([]*templates.Template, error) {
174179
var tmpls []*templates.Template
175180
d := yaml.NewDecoder(reader)

internal/config/default.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package config
22

3+
// DefaultCommitTemplate is the default commit template.
34
const DefaultCommitTemplate = `---
45
name: default
56
default: true

internal/git/options.go

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,34 @@
11
package git
22

3-
import "github.com/spf13/pflag"
3+
import (
4+
"github.com/spf13/pflag"
5+
)
46

57
type Options struct {
6-
Quiet bool
7-
Verbose bool
8-
SignOff bool
9-
All bool
10-
Amend bool
11-
DryRun bool
12-
Author string
13-
Date string
8+
Quiet bool
9+
Verbose bool
10+
SignOff bool
11+
All bool
12+
Amend bool
13+
DryRun bool
14+
NoVerify bool
15+
Author string
16+
Date string
17+
ExtraGitFlags []string
1418
}
1519

1620
func NewOptions() *Options {
1721
return &Options{
18-
Quiet: false,
19-
Verbose: false,
20-
SignOff: false,
21-
All: false,
22-
Amend: false,
23-
DryRun: false,
24-
Author: "",
25-
Date: "",
22+
Quiet: false,
23+
Verbose: false,
24+
SignOff: false,
25+
All: false,
26+
Amend: false,
27+
NoVerify: false,
28+
DryRun: false,
29+
Author: "",
30+
Date: "",
31+
ExtraGitFlags: []string{},
2632
}
2733
}
2834

@@ -35,6 +41,8 @@ func (o *Options) AddFlags(f *pflag.FlagSet) {
3541
f.BoolVarP(&o.All, "all", "a", o.All, "commit all changed files.")
3642
f.BoolVarP(&o.SignOff, "signoff", "s", o.SignOff, "add a Signed-off-by trailer.")
3743
f.BoolVar(&o.Amend, "amend", o.Amend, "amend previous commit")
44+
f.BoolVarP(&o.NoVerify, "no-verify", "n", o.NoVerify, "bypass pre-commit and commit-msg hooks.")
45+
f.StringSliceVar(&o.ExtraGitFlags, "git-flag", o.ExtraGitFlags, "git flags, e.g. --git-flag=\"--branch\"")
3846
}
3947

4048
func (o *Options) Combine(filename string) []string {
@@ -61,9 +69,15 @@ func (o *Options) Combine(filename string) []string {
6169
if o.Amend {
6270
combination = append(combination, "--amend")
6371
}
72+
if o.NoVerify {
73+
combination = append(combination, "--no-verify")
74+
}
6475
if o.DryRun {
6576
combination = append(combination, "--dry-run")
6677
}
78+
if len(o.ExtraGitFlags) > 0 {
79+
combination = append(combination, o.ExtraGitFlags...)
80+
}
6781

6882
return combination
69-
}
83+
}

0 commit comments

Comments
 (0)