Skip to content

Commit eacd020

Browse files
committed
chore(cmd): Add color output to progress messages
- Add the `github.com/fatih/color` package to the imports - Add the `github.com/mattn/go-colorable` and `github.com/mattn/go-isatty` packages to the imports - Add print statements using colors to inform the user about the progress of the program.
1 parent a9fd57b commit eacd020

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

cmd/commit.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/appleboy/CodeGPT/prompt"
1111
"github.com/appleboy/CodeGPT/util"
1212

13+
"github.com/fatih/color"
1314
"github.com/spf13/cobra"
1415
"github.com/spf13/viper"
1516
)
@@ -39,6 +40,8 @@ var commitCmd = &cobra.Command{
3940
log.Fatal(err)
4041
}
4142

43+
color.Green("Summarize the commit message use " + viper.GetString("openai.model") + " model")
44+
4245
client, err := openai.New(
4346
viper.GetString("openai.api_key"),
4447
viper.GetString("openai.model"),
@@ -59,6 +62,7 @@ var commitCmd = &cobra.Command{
5962
log.Fatal(err)
6063
}
6164

65+
color.Cyan("We are trying to summarize a git diff")
6266
summarizeDiff, err := client.Completion(cmd.Context(), out)
6367
if err != nil {
6468
log.Fatal(err)
@@ -74,6 +78,7 @@ var commitCmd = &cobra.Command{
7478
log.Fatal(err)
7579
}
7680

81+
color.Cyan("We are trying to summarize a title for pull request")
7782
summarizeTitle, err := client.Completion(cmd.Context(), out)
7883
if err != nil {
7984
log.Fatal(err)
@@ -92,6 +97,7 @@ var commitCmd = &cobra.Command{
9297
log.Fatal(err)
9398
}
9499

100+
color.Cyan("We are trying to translate a git commit message to " + prompt.GetLanguage(viper.GetString("output.lang")) + "language")
95101
summarize, err := client.Completion(cmd.Context(), out)
96102
if err != nil {
97103
log.Fatal(err)
@@ -101,6 +107,7 @@ var commitCmd = &cobra.Command{
101107
message = strings.TrimSpace(summarizeTitle) + "\n\n" + strings.TrimSpace(summarizeDiff)
102108
}
103109

110+
color.Cyan("Write the commit message to " + viper.GetString("output.file") + " file")
104111
err = os.WriteFile(viper.GetString("output.file"), []byte(message), 0o644)
105112
if err != nil {
106113
log.Fatal(err)

cmd/hook.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55

66
"github.com/appleboy/CodeGPT/hook"
77

8+
"github.com/fatih/color"
89
"github.com/spf13/cobra"
910
)
1011

@@ -19,9 +20,18 @@ var hookCmd = &cobra.Command{
1920

2021
switch args[0] {
2122
case "install":
22-
return hook.Install()
23+
if err := hook.Install(); err != nil {
24+
return err
25+
}
26+
27+
color.Green("Install git hook: prepare-commit-msg successfully")
28+
color.Green("You can see the hook file: .git/hooks/prepare-commit-msg")
2329
case "uninstall":
24-
return hook.Uninstall()
30+
if err := hook.Uninstall(); err != nil {
31+
return err
32+
}
33+
34+
color.Green("Remove git hook: prepare-commit-msg successfully")
2535
}
2636

2737
return nil

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,13 @@ require (
1010
)
1111

1212
require (
13+
github.com/fatih/color v1.14.1 // indirect
1314
github.com/fsnotify/fsnotify v1.6.0 // indirect
1415
github.com/hashicorp/hcl v1.0.0 // indirect
1516
github.com/inconshreveable/mousetrap v1.0.1 // indirect
1617
github.com/magiconair/properties v1.8.7 // indirect
18+
github.com/mattn/go-colorable v0.1.13 // indirect
19+
github.com/mattn/go-isatty v0.0.17 // indirect
1720
github.com/mitchellh/mapstructure v1.5.0 // indirect
1821
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
1922
github.com/spf13/afero v1.9.3 // indirect

go.sum

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
5858
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
5959
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
6060
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
61+
github.com/fatih/color v1.14.1 h1:qfhVLaG5s+nCROl1zJsZRxFeYrHLqWroPOQ8BWiNb4w=
62+
github.com/fatih/color v1.14.1/go.mod h1:2oHN61fhTpgcxD3TSWCgKDiH1+x4OiDVVGH8WlgGZGg=
6163
github.com/frankban/quicktest v1.14.3 h1:FJKSZTDHjyhriyC81FLQ0LY93eSai0ZyR/ZIkd3ZUKE=
6264
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
6365
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
@@ -138,6 +140,11 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
138140
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
139141
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
140142
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
143+
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
144+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
145+
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
146+
github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng=
147+
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
141148
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
142149
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
143150
github.com/pelletier/go-toml/v2 v2.0.6 h1:nrzqCb7j9cDFj2coyLNLaZuJTLjWjlaz6nvTvIwycIU=
@@ -311,6 +318,7 @@ golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7w
311318
golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
312319
golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
313320
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
321+
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
314322
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
315323
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
316324
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

0 commit comments

Comments
 (0)