Skip to content

Commit 484a97d

Browse files
committed
feat(optiosn): add debug options
1 parent d8970cc commit 484a97d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

cmd/cz/cz.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,16 @@ func New() *cobra.Command {
2525
Use: "commitizen",
2626
Long: `Command line utility to standardize git commit messages.`,
2727
PreRun: func(cmd *cobra.Command, args []string) {
28+
if !o.Debug {
29+
return
30+
}
2831
opts := &log.Options{
2932
DisableRotate: true,
3033
DisableFileCaller: true,
3134
DisableConsoleCaller: true,
3235
DisableConsoleLevel: true,
3336
DisableConsoleTime: true,
34-
Output: fmt.Sprintf("%s/commitizen/logs", os.TempDir()),
37+
Output: filepath.Join(os.TempDir(), "commitizen/logs"),
3538
FileLevel: log.DebugLevel.String(),
3639
FilenameEncoder: filenameEncoder,
3740
}

internal/options/options.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
package options
22

33
import (
4-
cliflag "github.com/shipengqi/component-base/cli/flag"
4+
"fmt"
5+
"os"
6+
"path/filepath"
57

68
"github.com/shipengqi/commitizen/internal/git"
9+
cliflag "github.com/shipengqi/component-base/cli/flag"
710
)
811

912
type Options struct {
1013
DryRun bool
1114
Default bool
15+
Debug bool
1216
Template string
1317
GitOptions *git.Options
1418
}
@@ -21,12 +25,16 @@ func New() *Options {
2125
}
2226

2327
func (o *Options) Flags() (fss cliflag.NamedFlagSets) {
28+
dir := filepath.Join(os.TempDir(), "commitizen/logs")
29+
2430
o.GitOptions.AddFlags(fss.FlagSet("Git Commit"))
2531

2632
fs := fss.FlagSet("Commitizen")
2733
fs.BoolVar(&o.DryRun, "dry-run", o.DryRun, "do not create a commit, but show the message and list of paths \nthat are to be committed.")
2834
fs.StringVarP(&o.Template, "template", "t", o.Template, "template name to use when multiple templates exist.")
2935
fs.BoolVarP(&o.Default, "default", "d", o.Default, "use the default template, '--default' has a higher priority than '--template'.")
36+
fs.BoolVar(&o.Debug, "debug", o.Debug, fmt.Sprintf("enable debug mode, writing log file to the %s directory.", dir))
3037

38+
_ = fs.MarkHidden("debug")
3139
return
3240
}

internal/parameter/group.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package parameter
22

33
import (
44
standarderrs "errors"
5+
56
"github.com/charmbracelet/huh"
67
"github.com/shipengqi/golib/strutil"
78
"github.com/shipengqi/log"
@@ -114,12 +115,14 @@ func (c *Condition) Validate() []error {
114115
}
115116

116117
func (c *Condition) Match() bool {
117-
field, ok := c.fields[GetFiledKey(c.ParameterName)]
118+
key := GetFiledKey(c.ParameterName)
119+
log.Debugf("math field condition: %s", key)
120+
field, ok := c.fields[key]
118121
if !ok {
122+
log.Debugf("cannot find field condition: %s", key)
119123
return false
120124
}
121125
val := field.GetValue()
122-
123126
if c.ValueEmpty != nil {
124127
return c.IsEmpty(*c.ValueEmpty, val)
125128
}
@@ -133,32 +136,39 @@ func (c *Condition) Match() bool {
133136
return c.Contains(val)
134137
}
135138
if c.ValueNotContains != nil {
139+
log.Debugf("value not contains val: %v", val)
136140
return c.NotContains(val)
137141
}
138142
return false
139143
}
140144

141145
func (c *Condition) Equal(val interface{}) bool {
146+
log.Debugf("%v contains match val: %v", c.ValueEquals, val)
142147
return helpers.Equal(c.ValueEquals, val)
143148
}
144149

145150
func (c *Condition) NotEqual(val interface{}) bool {
151+
log.Debugf("%v not equals val: %v", c.ValueNotEquals, val)
146152
return helpers.NotEqual(c.ValueNotEquals, val)
147153
}
148154

149155
func (c *Condition) Contains(val interface{}) bool {
156+
log.Debugf("%v contains val: %v", val, c.ValueContains)
150157
return helpers.Contains(val, c.ValueContains)
151158
}
152159

153160
func (c *Condition) NotContains(val interface{}) bool {
161+
log.Debugf("%v not contains val: %v", val, c.ValueContains)
154162
return helpers.NotContains(val, c.ValueNotContains)
155163
}
156164

157165
func (c *Condition) IsEmpty(empty bool, val interface{}) bool {
158166
if empty && helpers.Empty(val) {
167+
log.Debugf("value is empty: %v", val)
159168
return true
160169
}
161170
if !empty && helpers.NotEmpty(val) {
171+
log.Debugf("value is not empty: %v", val)
162172
return true
163173
}
164174
return false

0 commit comments

Comments
 (0)