@@ -10,26 +10,21 @@ import (
1010 "github.com/charmbracelet/x/term"
1111 "github.com/pubgo/dix/v2"
1212 "github.com/pubgo/dix/v2/dixcontext"
13- "github.com/pubgo/fastcommit/cmds/pullcmd"
14- "github.com/pubgo/funk/v2/assert"
15- "github.com/pubgo/funk/v2/buildinfo/version"
16- "github.com/pubgo/funk/v2/config"
17- "github.com/pubgo/funk/v2/errors"
18- "github.com/pubgo/funk/v2/features/featureflags"
19- "github.com/pubgo/funk/v2/log"
20- "github.com/pubgo/funk/v2/recovery"
21- "github.com/pubgo/funk/v2/running"
22- "github.com/samber/lo"
23- _ "github.com/sashabaranov/go-openai"
24- "github.com/urfave/cli/v3"
25-
2613 "github.com/pubgo/fastcommit/cmds/configcmd"
2714 "github.com/pubgo/fastcommit/cmds/fastcommitcmd"
2815 "github.com/pubgo/fastcommit/cmds/historycmd"
16+ "github.com/pubgo/fastcommit/cmds/pullcmd"
2917 "github.com/pubgo/fastcommit/cmds/tagcmd"
3018 "github.com/pubgo/fastcommit/cmds/upgradecmd"
3119 "github.com/pubgo/fastcommit/cmds/versioncmd"
3220 "github.com/pubgo/fastcommit/utils"
21+ "github.com/pubgo/funk/v2/assert"
22+ "github.com/pubgo/funk/v2/config"
23+ "github.com/pubgo/funk/v2/errors"
24+ "github.com/pubgo/funk/v2/log"
25+ "github.com/pubgo/funk/v2/recovery"
26+ "github.com/pubgo/redant"
27+ _ "github.com/sashabaranov/go-openai"
3328)
3429
3530func Main () {
@@ -44,7 +39,7 @@ func Main() {
4439 )
4540}
4641
47- func run (cmds ... * cli .Command ) {
42+ func run (cmds ... * redant .Command ) {
4843 defer recovery .Exit (func (err error ) error {
4944 if errors .Is (err , context .Canceled ) {
5045 return nil
@@ -58,32 +53,28 @@ func run(cmds ...*cli.Command) {
5853 return nil
5954 })
6055
61- app := & cli.Command {
62- Name : "fastcommit" ,
63- Suggest : true ,
64- UseShortOptionHandling : true ,
65- ShellComplete : cli .DefaultAppComplete ,
66- Usage : "Intelligent generation of git commit message" ,
67- Version : version .ReleaseVersion (),
68- Commands : cmds ,
69- EnableShellCompletion : true ,
70- Flags : append (featureflags .GetFlags (), lo .ToPtr (running .DebugFlag )),
71- Before : func (ctx context.Context , command * cli.Command ) (context.Context , error ) {
72- if ! term .IsTerminal (os .Stdin .Fd ()) {
73- return ctx , fmt .Errorf ("stdin is not terminal" )
74- }
56+ app := & redant.Command {
57+ Use : "fastcommit" ,
58+ Short : "Intelligent generation of git commit message" ,
59+ Children : cmds ,
60+ Middleware : func (next redant.HandlerFunc ) redant.HandlerFunc {
61+ return func (ctx context.Context , i * redant.Invocation ) error {
62+ if utils .IsHelp () {
63+ return redant .DefaultHelpFn ()(ctx , i )
64+ }
7565
76- if utils . IsHelp ( ) {
77- return ctx , cli . ShowAppHelp ( command )
78- }
66+ if ! term . IsTerminal ( os . Stdin . Fd () ) {
67+ return fmt . Errorf ( "stdin is not terminal" )
68+ }
7969
80- initConfig ()
81- di := dix .New (dix .WithValuesNull ())
82- di .Provide (config .Load [configProvider ])
83- di .Provide (utils .NewOpenaiClient )
84- return dixcontext .Create (ctx , di ), nil
70+ initConfig ()
71+ di := dix .New (dix .WithValuesNull ())
72+ di .Provide (config .Load [configProvider ])
73+ di .Provide (utils .NewOpenaiClient )
74+ return next (dixcontext .Create (ctx , di ), i )
75+ }
8576 },
8677 }
8778
88- assert .Must (app .Run (utils .Context (), os . Args ))
79+ assert .Must (app .Run (utils .Context ()))
8980}
0 commit comments