From af5205fb365f06727ab8ae051bd28e79f47b346c Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 8 Sep 2025 16:18:30 -0500 Subject: [PATCH] add bash support --- argv.go | 42 ++++++++++++++++++++++++++++++++++++++++++ main.go | 10 ++++++++++ 2 files changed, 52 insertions(+) diff --git a/argv.go b/argv.go index f20cb89..3260285 100644 --- a/argv.go +++ b/argv.go @@ -1,5 +1,10 @@ package main +import ( + "fmt" + "os" +) + /* this parses the command line arguements @@ -16,6 +21,8 @@ type args struct { KeepFiles bool `arg:"--keep-files" help:"keep the build files/"` Force bool `arg:"--force" default:"false" help:"force overwrite an existing .deb file"` Verbose bool `arg:"--verbose" help:"show more things"` + Bash bool `arg:"--bash" help:"generate bash completion"` + BashAuto []string `arg:"--auto-complete" help:"todo: move this to go-arg"` } func (args) Version() string { @@ -33,3 +40,38 @@ Example usage: This will pull down the go sources and the repositories in the go.sum file using git clone` } + +// prints help to STDERR // TODO: move everything below this to go-args +func (args) doBashHelp() { + if argv.BashAuto[1] != "''" { + // if this is not blank, then the user has typed something + return + } + if argv.BashAuto[0] != ARGNAME { + // if this is not the name of the command, the user already started doing something + return + } + if argv.BashAuto[0] == ARGNAME { + me.pp.WriteHelp(os.Stderr) + return + } + fmt.Fprintln(os.Stderr, "") + fmt.Fprintln(os.Stderr, "hello world") + fmt.Fprintln(os.Stderr, "") +} + +func (args) doBashAuto() { + // argv.doBashHelp() + switch argv.BashAuto[0] { + case "arch": + fmt.Println("riscv64") + case "build": + fmt.Println("user devel release") + default: + if argv.BashAuto[0] == ARGNAME { + // list the subcommands here + fmt.Println("arch build") + } + } + os.Exit(0) +} diff --git a/main.go b/main.go index 8745d13..ab09067 100644 --- a/main.go +++ b/main.go @@ -20,6 +20,7 @@ var DATE string //go:embed resources/* var resources embed.FS +var ARGNAME string = "go-deb" var argv args func main() { @@ -28,6 +29,15 @@ func main() { gui.InitArg() arg.MustParse(&argv) + if argv.Bash { + fhelp.DoBash(ARGNAME) + os.Exit(0) + } + if len(argv.BashAuto) != 0 { + argv.doBashAuto() + os.Exit(0) + } + if err := fhelp.ConfigureENV(); err != nil { badExit(err) }