File tree Expand file tree Collapse file tree 3 files changed +46
-0
lines changed
Expand file tree Collapse file tree 3 files changed +46
-0
lines changed Original file line number Diff line number Diff line change 1+ module github.com/Sotaneum/go-args-parser
2+
3+ go 1.17
Original file line number Diff line number Diff line change 1+ package parser
2+
3+ import (
4+ "os"
5+ "strings"
6+ )
7+
8+ func toKeyValue (data , pattern string ) (string , string ) {
9+ items := strings .Split (data , pattern )
10+ if len (items ) != 2 {
11+ if pattern == ":" {
12+ return data , "true"
13+ }
14+ return toKeyValue (data , ":" )
15+ }
16+ return items [0 ], items [1 ]
17+ }
18+
19+ func Args (options map [string ]string ) map [string ]string {
20+ argsWithoutProg := os .Args [1 :]
21+
22+ for _ , arg := range argsWithoutProg {
23+ println (arg )
24+ key , value := toKeyValue (arg , "=" )
25+ if key == "" || value == "" {
26+ continue
27+ }
28+ options [key ] = value
29+ }
30+ return options
31+ }
Original file line number Diff line number Diff line change 1+ package parser_test
2+
3+ import (
4+ "fmt"
5+ "testing"
6+
7+ parser "github.com/Sotaneum/go-args-parser"
8+ )
9+
10+ func TestRunner (t * testing.T ) {
11+ fmt .Println (parser .Args (map [string ]string {}))
12+ }
You can’t perform that action at this time.
0 commit comments