Skip to content

Commit

Permalink
Add help cli option
Browse files Browse the repository at this point in the history
  • Loading branch information
kaypee90 committed Nov 5, 2024
1 parent 97f6372 commit 7595421
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ LAUNCH=$(GORUN) $$(ls -1 cmd/depbot/*.go | grep -v _test.go)

run:
$(LAUNCH)
help:
$(LAUNCH) --help
version:
$(LAUNCH) --version
web:
Expand Down
9 changes: 9 additions & 0 deletions cmd/depbot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ func displayAppVersion() {
os.Exit(0)
}

func displayHelpText() {
text := getCliHelpText()
fmt.Printf("%s", text)
os.Exit(0)
}

func handlePromptError(err error) {
if err != nil {
os.Exit(0)
Expand Down Expand Up @@ -93,12 +99,15 @@ func launchApplicaton() {
func main() {
showVersion := flag.Bool("version", false, "Display app version")
startWebApp := flag.Bool("web", false, "Start web application")
displayHelp := flag.Bool("help", false, "Display help text")

flag.Parse()
if *showVersion {
displayAppVersion()
} else if *startWebApp {
startWebApplication()
} else if *displayHelp {
displayHelpText()
} else {
launchApplicaton()
}
Expand Down
14 changes: 13 additions & 1 deletion cmd/depbot/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,21 @@ const (
dependabotFileName = "dependabot.yml"
githubDirectory = ".github"
pathSeperator = "/"
cliHelpText = `Depbot - A CLI tool to help you configure dependabot in your project
Usage:
depbot [flags]
Flags:
--help -h Show help
--version -v Display app version
--web -w Start web application
`
)

func getCliHelpText() string {
return cliHelpText
}

func printIntroductoryText() {
green := "\033[32m"
reset := "\033[0m"
Expand Down Expand Up @@ -47,7 +60,6 @@ func fileExists(filename string) bool {
func createDirectoryIfItDoesNotExist(dir string) (hasCreatedNewDir bool, err error) {
if _, err := os.Stat(dir); os.IsNotExist(err) {
err := os.Mkdir(dir, 0755)

if err != nil {
log.Fatalf("Error creating directory %s: %v", dir, err)
return false, err
Expand Down
6 changes: 6 additions & 0 deletions cmd/depbot/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,9 @@ func TestFileExistsWhenFileAlrieadyExists(t *testing.T) {

assert.Equal(t, hasFile, true)
}

func TestGetCliHelpText(t *testing.T) {
text := getCliHelpText()

assert.Equal(t, text, cliHelpText)
}

0 comments on commit 7595421

Please sign in to comment.