Skip to content

Commit

Permalink
add errr
Browse files Browse the repository at this point in the history
  • Loading branch information
wenn committed Nov 27, 2024
1 parent cd5b6ec commit a60c79c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
12 changes: 12 additions & 0 deletions errr/errr.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package errr

import (
"errors"
"fmt"

"github.com/reverbdotcom/sbx/commands"
)

func New(message string) error {
return errors.New(fmt.Sprintf("🚫 %s\n\n\n%s", message, commands.Help))
}
12 changes: 3 additions & 9 deletions parser/parser.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package parser

import (
"errors"
"fmt"

"github.com/reverbdotcom/sbx/commands"
"github.com/reverbdotcom/sbx/errr"
)

func Parse(args []string) (*commands.RunFn, error) {
Expand All @@ -19,7 +17,7 @@ func Parse(args []string) (*commands.RunFn, error) {

func command(args []string) (command *string, err error) {
if len(args) < 2 {
return nil, errr("command required")
return nil, errr.New("command required")
}

cmd := args[1]
Expand All @@ -31,12 +29,8 @@ func cmdfn(command string) (*commands.RunFn, error) {
cmd, ok := commands.Commands()[command]

if !ok {
return nil, errr("command not found")
return nil, errr.New("command not found")
}

return &cmd, nil
}

func errr(message string) error {
return errors.New(fmt.Sprintf("🚫 %s\n\n\n%s", message, commands.Help))
}
5 changes: 3 additions & 2 deletions sbx.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ import (
"fmt"
"os"

"github.com/reverbdotcom/sbx/errr"
"github.com/reverbdotcom/sbx/parser"
)

func main() {
cmdfn, err := parser.Parse(os.Args)

if err != nil {
fmt.Println(err)
fmt.Println(errr.New(err.Error()))
os.Exit(1)
}

Expand All @@ -20,7 +21,7 @@ func main() {
fmt.Println(out)

if err != nil {
fmt.Println(err)
fmt.Println(errr.New(err.Error()))
os.Exit(1)
}
}

0 comments on commit a60c79c

Please sign in to comment.