Skip to content

Commit

Permalink
feat(options): add a new option --default/-d (#41)
Browse files Browse the repository at this point in the history
* feat(options): add a new option --default/-d

* feat(options): add a new option --default/-t
  • Loading branch information
shipengqi authored Mar 20, 2024
1 parent 5beb4b8 commit 4239d34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ func (c *Config) Run(opts *options.Options) (*render.Template, error) {
if err != nil {
return nil, err
}

if opts.Default {
return c.defaultTmpl, nil
}
// find the given template
if len(opts.Template) > 0 {
if opts.Template == c.defaultTmpl.Name {
Expand Down
2 changes: 2 additions & 0 deletions internal/options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
type Options struct {
DryRun bool
NoTTY bool
Default bool
Template string
GitOptions *git.Options
}
Expand All @@ -25,6 +26,7 @@ func (o *Options) AddFlags(f *pflag.FlagSet) {

f.BoolVar(&o.DryRun, "dry-run", o.DryRun, "you can use the --dry-run flag to preview the message that would be committed, without really submitting it.")
f.StringVarP(&o.Template, "template", "t", o.Template, "template name to use when multiple templates exist.")
f.BoolVarP(&o.Default, "default", "d", o.Default, "use the default template, '--default' has a higher priority than '--template'.")
f.BoolVar(&o.NoTTY, "no-tty", o.NoTTY, "make sure that the TTY (terminal) is never used for any output.")

_ = f.MarkHidden("no-tty")
Expand Down

0 comments on commit 4239d34

Please sign in to comment.