Files
qc/internal/argparser/argparser.go
2024-03-06 16:14:33 +05:30

40 lines
825 B
Go

package argparser
import (
"errors"
"strings"
)
func Parse(args []string) (err error, commit_type string, commit_scope string, shouldCommit bool, shouldStage bool, commit_message []string) {
argparseloop:
for i := 0; i < len(args); i++ {
if strings.HasPrefix(args[i],"-") {
switch args[i] {
case "-c", "--commit", "-commit":
shouldCommit = true
case "-a", "--add", "-add":
shouldStage = true
case "--":
commit_message = args[i+1:]
break argparseloop
default:
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
}