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 702aefa
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 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,10 +45,11 @@ 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 {
if err := cli.ShowSubcommandHelp(c) != nil; err {
log.Println(err)
}
exitWithErr(err)
}

Expand All @@ -64,6 +68,21 @@ func main() {

return nil
},

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

if isSubcommand {
if err := cli.ShowSubcommandHelp(c) != nil; err {
log.Println(err)
}
} else {
if err := cli.ShowAppHelp(c) != nil; err {
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 702aefa

Please sign in to comment.