Provide flag for passing package manager arguments
ci/woodpecker/push/woodpecker Pipeline was successful Details

This commit is contained in:
Elara 2022-12-28 11:57:07 -08:00
parent be79eba4c2
commit 770881bf67
2 changed files with 19 additions and 1 deletions

15
main.go
View File

@ -23,6 +23,7 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"
@ -31,6 +32,7 @@ import (
"go.arsenm.dev/logger/log"
"go.arsenm.dev/lure/internal/config"
"go.arsenm.dev/lure/internal/db"
"go.arsenm.dev/lure/manager"
)
//go:generate scripts/gen-version.sh
@ -54,6 +56,13 @@ func main() {
app := &cli.App{
Name: "lure",
Usage: "Linux User REpository",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "pm-args",
Aliases: []string{"P"},
Usage: "Arguments to be passed on to the package manager",
},
},
Commands: []*cli.Command{
{
Name: "install",
@ -155,6 +164,12 @@ func main() {
Action: displayVersion,
},
},
Before: func(c *cli.Context) error {
fmt.Println("pm-args:", c.String("pm-args"))
args := strings.Split(c.String("pm-args"), " ")
manager.Args = append(manager.Args, args...)
return nil
},
After: func(ctx *cli.Context) error {
return gdb.Close()
},

View File

@ -23,6 +23,8 @@ import (
"os/exec"
)
var Args []string
type Opts struct {
AsRoot bool
NoConfirm bool
@ -115,7 +117,8 @@ func setCmdEnv(cmd *exec.Cmd) {
func ensureOpts(opts *Opts) *Opts {
if opts == nil {
return DefaultOpts
opts = DefaultOpts
}
opts.Args = append(opts.Args, Args...)
return opts
}