]> Cypherpunks.ru repositories - goredo.git/commitdiff
Dashes are valid targets
authorSergey Matveev <stargrave@stargrave.org>
Sat, 7 Oct 2023 15:52:47 +0000 (18:52 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Sat, 7 Oct 2023 15:52:47 +0000 (18:52 +0300)
main.go
t/goredo-dashed-tgt.t [new file with mode: 0755]

diff --git a/main.go b/main.go
index c579a0f6ec935414ff18815fa3eaf0aea62ebcb1..41d8d30f0ded6473b600938207d1890e323ae74f 100644 (file)
--- a/main.go
+++ b/main.go
@@ -98,7 +98,18 @@ func main() {
        }
 
        flag.Usage = func() { usage(os.Args[0]) }
-       flag.Parse()
+
+       BuildUUIDStr := os.Getenv(EnvBuildUUID)
+       IsTopRedo = BuildUUIDStr == ""
+
+       var args []string
+       if IsTopRedo {
+               flag.Parse()
+               args = flag.Args()
+       } else {
+               args = os.Args[1:]
+       }
+
        if *warranty {
                fmt.Println(Warranty)
                return
@@ -279,13 +290,12 @@ func main() {
                fdDep = mustParseFd(v, EnvDepFd)
        }
 
-       tgts := make([]*Tgt, 0, len(flag.Args()))
-       for _, arg := range flag.Args() {
+       tgts := make([]*Tgt, 0, len(args))
+       for _, arg := range args {
                tgts = append(tgts, NewTgt(arg))
        }
        tgtsWasEmpty := len(tgts) == 0
-       if BuildUUIDStr := os.Getenv(EnvBuildUUID); BuildUUIDStr == "" {
-               IsTopRedo = true
+       if BuildUUIDStr == "" {
                BuildUUID = uuid.New()
                if tgtsWasEmpty {
                        tgts = append(tgts, NewTgt("all"))
diff --git a/t/goredo-dashed-tgt.t b/t/goredo-dashed-tgt.t
new file mode 100755 (executable)
index 0000000..8f6f408
--- /dev/null
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+testname=`basename "$0"`
+test_description="Check that dashed targets are not treated as options"
+. $SHARNESS_TEST_SRCDIR/sharness.sh
+export REDO_TOP_DIR="`pwd`" REDO_NO_PROGRESS=1
+
+echo echo \$1 > default.do
+redo -- ok
+test_expect_success "redo skips dashes" '[ ! -e ./-- ]'
+test_expect_success "redo mades ok" '[ -s ok ]'
+
+echo "redo-ifchange -- ok" > foo.do
+rm ok
+redo foo
+test_expect_success "dashes made" '[ -s ./-- ]'
+test_expect_success "ok is also made" '[ -e ok ]'
+
+test_done