Skip to content

Commit b656f7a

Browse files
committed
feat(install): do not configure commit hook by default(use --hook option to install)
do not configure commit hook by default(use `--hook` option to install) close #21 Signed-off-by: mritd <[email protected]>
1 parent 0101010 commit b656f7a

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

cmds.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func installCmd() *cli.Command {
1111
if c.NArg() != 0 {
1212
return cli.ShowAppHelp(c)
1313
}
14-
return install(c.String("dir"))
14+
return install(c.String("dir"), c.Bool("hook"))
1515
},
1616
Flags: []cli.Flag{
1717
&cli.StringFlag{
@@ -20,6 +20,11 @@ func installCmd() *cli.Command {
2020
Usage: "Install dir",
2121
Value: "/usr/local/bin",
2222
},
23+
&cli.BoolFlag{
24+
Name: "hook",
25+
Usage: "Install Commit Message hook",
26+
Value: false,
27+
},
2328
},
2429
}
2530
}

install.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
"github.com/mitchellh/go-homedir"
1414
)
1515

16-
func install(dir string) error {
16+
func install(dir string, withHook bool) error {
1717
home, err := homedir.Dir()
1818
if err != nil {
1919
return err
@@ -100,6 +100,9 @@ func install(dir string) error {
100100
{
101101
Title: "Set commit hooks...",
102102
Func: func() error {
103+
if !withHook {
104+
return ui.WarnErr{Message: "Hook is not installed!"}
105+
}
103106
err := os.MkdirAll(toolKitHooks, 0755)
104107
if err != nil {
105108
return fmt.Errorf("💔 failed to create hooks dir: %s: %s", toolKitHooks, err)

ui/multi_task.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ var (
3030
MultiTaskMsgWaitingStyle = MultiTaskMsgSuccessStyle.Copy().
3131
Foreground(lipgloss.AdaptiveColor{Light: "#2B53AF", Dark: "#37B9FF"})
3232

33+
MultiTaskMsgWarningStyle = MultiTaskMsgSuccessStyle.Copy().
34+
Foreground(lipgloss.AdaptiveColor{Light: "#FF9A0D", Dark: "#F8CA61"})
35+
3336
MultiTaskSpinner = spinner.Model{
3437
Style: lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "#FF9A0D", Dark: "#F8CA61"}),
3538
Spinner: spinner.Spinner{
@@ -67,6 +70,14 @@ type Task struct {
6770
err error
6871
}
6972

73+
type WarnErr struct {
74+
Message string
75+
}
76+
77+
func (e WarnErr) Error() string {
78+
return e.Message
79+
}
80+
7081
type MultiTaskModel struct {
7182
Tasks []Task
7283
Spinner spinner.Model
@@ -77,6 +88,7 @@ type MultiTaskModel struct {
7788
MsgSuccessStyle lipgloss.Style
7889
MsgFailedStyle lipgloss.Style
7990
MsgWaitingStyle lipgloss.Style
91+
MsgWarningStyle lipgloss.Style
8092

8193
index int
8294
}
@@ -95,6 +107,7 @@ func NewMultiTaskModelWithTasks(tasks []Task) MultiTaskModel {
95107
MsgSuccessStyle: MultiTaskMsgSuccessStyle,
96108
MsgFailedStyle: MultiTaskMsgFailedStyle,
97109
MsgWaitingStyle: MultiTaskMsgWaitingStyle,
110+
MsgWarningStyle: MultiTaskMsgWarningStyle,
98111
}
99112
}
100113

@@ -119,7 +132,9 @@ func (m MultiTaskModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
119132
}
120133
case TaskDoneMsg:
121134
if m.Tasks[m.index].err != nil {
122-
return m, tea.Quit
135+
if _, ok := m.Tasks[m.index].err.(WarnErr); !ok {
136+
return m, tea.Quit
137+
}
123138
}
124139

125140
m.index++
@@ -147,7 +162,11 @@ func (m MultiTaskModel) View() string {
147162
view = lipgloss.JoinVertical(lipgloss.Left, view, m.Spinner.View()+" "+m.MsgWaitingStyle.Render(task.Title))
148163
}
149164
} else {
150-
view = lipgloss.JoinVertical(lipgloss.Left, view, m.MsgFailedStyle.Render("[ ✗ ] "+task.err.Error()))
165+
if _, ok := task.err.(WarnErr); ok {
166+
view = lipgloss.JoinVertical(lipgloss.Left, view, m.MsgWarningStyle.Render("[ ≡ ] "+task.err.Error()))
167+
} else {
168+
view = lipgloss.JoinVertical(lipgloss.Left, view, m.MsgFailedStyle.Render("[ ✗ ] "+task.err.Error()))
169+
}
151170
}
152171

153172
}

version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.1.2
1+
v2.1.3

0 commit comments

Comments
 (0)