Skip to content

Commit

Permalink
goplus#1300, gop build pass flags
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jun 23, 2022
1 parent ef31987 commit 3ac98b0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
14 changes: 14 additions & 0 deletions cmd/internal/base/base.go
Expand Up @@ -112,3 +112,17 @@ func Main(c *Command, app string, args []string) {
}
c.Run(c, args)
}

// SkipSwitches skips all switches and returns non-switch arguments.
func SkipSwitches(args []string, f *flag.FlagSet) []string {
out := make([]string, 0, len(args))
for _, arg := range args {
if strings.HasPrefix(arg, "-") {
if f.Lookup(arg[1:]) == nil { // flag not found
continue
}
}
out = append(out, arg)
}
return out
}
15 changes: 8 additions & 7 deletions cmd/internal/build/build.go
Expand Up @@ -51,7 +51,7 @@ func init() {
}

func runCmd(_ *base.Command, args []string) {
err := flag.Parse(args)
err := flag.Parse(base.SkipSwitches(args, flag))
if err != nil {
log.Panicln("parse input arguments failed:", err)
}
Expand All @@ -62,17 +62,17 @@ func runCmd(_ *base.Command, args []string) {
cl.SetDisableRecover(true)
}

args = flag.Args()
if len(args) == 0 {
args = []string{"."}
sargs := flag.Args()
if len(sargs) == 0 {
sargs = []string{"."}
}
proj, sargs, err := gopprojs.ParseOne(sargs...)

proj, args, err := gopprojs.ParseOne(args...)
if err != nil {
log.Panicln(err)
}
if len(args) != 0 {
log.Panicln("too many arguments:", args)
if len(sargs) != 0 {
log.Panicln("too many arguments:", sargs)
}

gopEnv := gopenv.Get()
Expand All @@ -85,6 +85,7 @@ func runCmd(_ *base.Command, args []string) {
}
confCmd.Flags = []string{"-o", output}
}
confCmd.Flags = append(confCmd.Flags, args...)
build(proj, conf, confCmd)
}

Expand Down

0 comments on commit 3ac98b0

Please sign in to comment.