Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies #331

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/jotaen/klog
go 1.23

require (
cloud.google.com/go v0.115.1
github.com/alecthomas/kong v0.9.0
cloud.google.com/go v0.116.0
github.com/alecthomas/kong v1.4.0
github.com/jotaen/genie v0.0.1
github.com/jotaen/kong-completion v0.0.6
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
cloud.google.com/go v0.115.1 h1:Jo0SM9cQnSkYfp44+v+NQXHpcHqlnRJk2qxh6yvxxxQ=
cloud.google.com/go v0.115.1/go.mod h1:DuujITeaufu3gL68/lOFIirVNJwQeyf5UXyi+Wbgknc=
github.com/alecthomas/assert/v2 v2.6.0 h1:o3WJwILtexrEUk3cUVal3oiQY2tfgr/FHWiz/v2n4FU=
github.com/alecthomas/assert/v2 v2.6.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v0.9.0 h1:G5diXxc85KvoV2f0ZRVuMsi45IrBgx9zDNGNj165aPA=
github.com/alecthomas/kong v0.9.0/go.mod h1:Y47y5gKfHp1hDc7CH7OeXgLIpp+Q2m1Ni0L5s3bI8Os=
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
github.com/alecthomas/kong v1.4.0 h1:UL7tzGMnnY0YRMMvJyITIRX1EpO6RbBRZDNcCevy3HA=
github.com/alecthomas/kong v1.4.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU=
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
12 changes: 12 additions & 0 deletions klog/app/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ type Error interface {
// Error returns the error message.
Error() string

Is(error) bool

// Details returns additional details, such as a hint how to solve the problem.
Details() string

Expand Down Expand Up @@ -72,6 +74,11 @@ func (e AppError) Error() string {
return e.message
}

func (e AppError) Is(err error) bool {
_, ok := err.(AppError)
return ok
}

func (e AppError) Details() string {
return e.details
}
Expand Down Expand Up @@ -101,6 +108,11 @@ func (pe parserErrors) Error() string {
return fmt.Sprintf("%d parsing error(s)", len(pe.errors))
}

func (e parserErrors) Is(err error) bool {
_, ok := err.(parserErrors)
return ok
}

func (pe parserErrors) Details() string {
return fmt.Sprintf("%d parsing error(s)", len(pe.errors))
}
Expand Down
26 changes: 16 additions & 10 deletions klog/app/main/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ func Run(homeDir app.File, meta app.Meta, config app.Config, args []string) (int
}),
)
if nErr != nil {
// This code branch is not expected to be invoked in practice. If it were to
// happen, that most likely indicates a bug in the app setup.
return app.GENERAL_ERROR.ToInt(), errors.New("Internal error: " + nErr.Error())
}

Expand Down Expand Up @@ -95,15 +97,19 @@ func Run(homeDir app.File, meta app.Meta, config app.Config, args []string) (int
kongCtx.BindTo(ctx, (*app.Context)(nil))

rErr := kongCtx.Run()
if rErr != nil {
switch e := rErr.(type) {
case app.ParserErrors:
return e.Code().ToInt(), util.PrettifyParsingError(e, styler)
case app.Error:
return e.Code().ToInt(), util.PrettifyAppError(e, config.IsDebug.Value())
default:
return app.GENERAL_ERROR.ToInt(), errors.New("Error: " + e.Error())
}
parserErrors := app.NewParserErrors(nil)
appError := app.NewError("", "", nil)

switch {
case rErr == nil:
return 0, nil
case errors.As(rErr, &parserErrors):
return parserErrors.Code().ToInt(), util.PrettifyParsingError(parserErrors, styler)
case errors.As(rErr, &appError):
return appError.Code().ToInt(), util.PrettifyAppError(appError, config.IsDebug.Value())
default:
// This is just a fallback clause; this code branch is not expected to be
// invoked in practice.
return app.GENERAL_ERROR.ToInt(), errors.New("Error: " + rErr.Error())
}
return 0, nil
}
Loading
Loading