Skip to content

Commit

Permalink
Improve help text and add usage exampes
Browse files Browse the repository at this point in the history
Fixes #85
  • Loading branch information
qasimwarraich committed Apr 28, 2023
1 parent 7bd1035 commit 00d7dbe
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"fmt"
"log"
"os"

"github.com/bespinian/livelint/internal/app"
Expand All @@ -20,9 +21,11 @@ func main() {

Commands: []*cli.Command{
{
Name: "check",
Aliases: []string{"c"},
Usage: "checks a Kubernetes deployment for issues",
Name: "check",
Aliases: []string{"c"},
Usage: "livelint check/c [--namespace/-n <namespace>] <deployment name>",
UsageText: "livelint check my-deployment\nlivelint check --namespace default my-deployment",
Description: "Checks a Kubernetes deployment for issues",

Flags: []cli.Flag{
&cli.StringFlag{
Expand All @@ -42,11 +45,10 @@ func main() {
Action: func(c *cli.Context) error {
bubbletea := livelint.NewBubbleTeaInterface(tea.NewProgram(livelint.InitialModel()))
namespace := c.String("namespace")
args := c.Args().First()
fmt.Println(args)
app, err := app.New(namespace, c.Args().First(), bubbletea)
if err != nil {
exitWithErr(err)
defer exitWithErr(err)
err = cli.ShowSubcommandHelp(c)
}

go func() {
Expand All @@ -64,6 +66,23 @@ func main() {

return nil
},

OnUsageError: func(c *cli.Context, err error, isSubcommand bool) error {
originalError := err

if isSubcommand {
err = cli.ShowSubcommandHelp(c)
if err != nil {
log.Println(err)
}
} else {
err = cli.ShowAppHelp(c)
if err != nil {
log.Println(err)
}
}
return originalError
},
},
},

Expand All @@ -80,6 +99,6 @@ func main() {
}

func exitWithErr(err error) {
_, _ = fmt.Fprintf(os.Stderr, "failed to start livelint: %s\n", err)
_, _ = fmt.Fprintf(os.Stderr, "\nfailed to start livelint: %s\n", err)
os.Exit(1)
}

0 comments on commit 00d7dbe

Please sign in to comment.