Compare commits
5 Commits
96f507fbe3
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
b044825d1a
|
|||
|
d856a3bcd7
|
|||
|
69d2eb70a1
|
|||
|
7910cec1e0
|
|||
|
664f82d4cf
|
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
/out/
|
||||||
11
Makefile
11
Makefile
@@ -1,16 +1,21 @@
|
|||||||
GO_MODULE = qc
|
MOD_NAME = qc
|
||||||
GO_MODULE_FULL = gitea.kevinnlsamuel.com/kevinnls/$(GO_MODULE)
|
GO_MODULE = gitea.kevinnlsamuel.com/kevinnls/$(MOD_NAME)
|
||||||
|
OUTDIR = out/
|
||||||
|
|
||||||
|
ifeq "$(shell command -v go)" ""
|
||||||
prefix = podman run --interactive --tty --rm \
|
prefix = podman run --interactive --tty --rm \
|
||||||
--workdir /usr/local/go/src/$(GO_MODULE) \
|
--workdir /usr/local/go/src/$(GO_MODULE) \
|
||||||
--volume $(PWD)/:/usr/local/go/src/$(GO_MODULE)/:Z \
|
--volume $(PWD)/:/usr/local/go/src/$(GO_MODULE)/:Z \
|
||||||
golang:alpine
|
golang:alpine
|
||||||
|
else
|
||||||
|
prefix =
|
||||||
|
endif
|
||||||
|
|
||||||
run:
|
run:
|
||||||
$(prefix) go run $(GO_MODULE) $(ARGS)
|
$(prefix) go run $(GO_MODULE) $(ARGS)
|
||||||
test:
|
test:
|
||||||
$(prefix) go test ./... $(ARGS)
|
$(prefix) go test ./... $(ARGS)
|
||||||
build:
|
build:
|
||||||
$(prefix) go build -v $(GO_MODULE) $(ARGS)
|
$(prefix) go build -o $(OUTDIR)/ -v $(GO_MODULE) $(ARGS)
|
||||||
sh:
|
sh:
|
||||||
$(prefix) sh
|
$(prefix) sh
|
||||||
|
|||||||
@@ -1,30 +1,38 @@
|
|||||||
package argparser
|
package argparser
|
||||||
|
|
||||||
import "errors"
|
import (
|
||||||
|
"errors"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
func Parse(args []string) (err error, commit_type string, commit_scope string, shouldCommit bool, shouldStage bool, commit_message []string) {
|
func Parse(args []string) (err error, commit_type string, commit_scope string, shouldCommit bool, shouldStage bool, commit_message []string) {
|
||||||
argparseloop:
|
argparseloop:
|
||||||
for i := 0; i < len(args); i++ {
|
for i := 0; i < len(args); i++ {
|
||||||
switch args[i] {
|
if strings.HasPrefix(args[i],"-") {
|
||||||
case "-c", "--commit", "-commit":
|
switch args[i] {
|
||||||
shouldCommit = true
|
case "-c", "--commit", "-commit":
|
||||||
case "-a", "--add", "-add":
|
shouldCommit = true
|
||||||
shouldStage = true
|
case "-a", "--add", "-add":
|
||||||
case "--":
|
shouldStage = true
|
||||||
commit_message = args[i+1:]
|
case "--":
|
||||||
break argparseloop
|
commit_message = args[i+1:]
|
||||||
default:
|
break argparseloop
|
||||||
if commit_type == "" {
|
default:
|
||||||
commit_type = args[i]
|
err = errors.New("unknown argument")
|
||||||
continue argparseloop
|
return
|
||||||
}
|
}
|
||||||
if commit_scope == "" {
|
|
||||||
commit_scope = args[i]
|
|
||||||
continue argparseloop
|
|
||||||
}
|
|
||||||
err = errors.New("unknown argument")
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
if commit_type == "" {
|
||||||
|
commit_type = args[i]
|
||||||
|
} else if commit_scope == "" {
|
||||||
|
commit_scope = args[i]
|
||||||
|
} else {
|
||||||
|
err = errors.New("unknown argument")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if commit_type == "" {
|
||||||
|
err = errors.New("need at least type")
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,5 +26,13 @@ func TestParse(t *testing.T) {
|
|||||||
assert.Equal(t, shouldCommit, false)
|
assert.Equal(t, shouldCommit, false)
|
||||||
assert.Equal(t, shouldStage, false)
|
assert.Equal(t, shouldStage, false)
|
||||||
})
|
})
|
||||||
|
t.Run("fake arg", func(t *testing.T) {
|
||||||
|
error,_,_,_,_,_ := Parse([]string{"-f"})
|
||||||
|
assert.NotEqual(t, error, nil)
|
||||||
|
})
|
||||||
|
t.Run("excess arg", func(t *testing.T) {
|
||||||
|
error,_,_,_,_,_ := Parse([]string{"type","scope","fool me"})
|
||||||
|
assert.NotEqual(t, error, nil)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user