refactor arg parsing into own package; don't use flags
This commit is contained in:
31
internal/argparser/argparser.go
Normal file
31
internal/argparser/argparser.go
Normal file
@@ -0,0 +1,31 @@
|
||||
package argparser
|
||||
|
||||
import "errors"
|
||||
|
||||
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++ {
|
||||
switch args[i] {
|
||||
case "-c", "--commit", "-commit":
|
||||
shouldCommit = true
|
||||
case "-a", "--add", "-add":
|
||||
shouldStage = true
|
||||
case "--":
|
||||
commit_message = args[i+1:]
|
||||
break argparseloop
|
||||
default:
|
||||
if commit_type == "" {
|
||||
commit_type = args[i]
|
||||
continue argparseloop
|
||||
}
|
||||
if commit_scope == "" {
|
||||
commit_scope = args[i]
|
||||
continue argparseloop
|
||||
}
|
||||
err = errors.New("unknown argument")
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user