MCPcopy Create free account
hub / github.com/delinoio/oss / parse

Function parse

cmds/async-commit-hook/internal/cli/cli.go:55–91  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

53}
54
55func parse(args []string) (options, error) {
56 o := options{flags: map[string]string{}}
57 bools := map[string]bool{"json": true, "help": true, "automatic": true, "failed": true, "force": true, "dry-run": true, "pre-push": true, "recover": true}
58 values := map[string]bool{"repo": true, "commit": true, "run": true, "check": true, "offset": true, "limit": true, "cursor": true, "timeout": true, "previous": true, "config": true, "client": true, "scope": true, "browser": true, "policy": true, "max-age-days": true, "max-bytes": true, "version": true}
59 for i := 0; i < len(args); i++ {
60 a := args[i]
61 if a == "-h" {
62 a = "--help"
63 }
64 if !strings.HasPrefix(a, "--") {
65 o.words = append(o.words, a)
66 continue
67 }
68 key, value, has := strings.Cut(strings.TrimPrefix(a, "--"), "=")
69 if _, ok := o.flags[key]; ok {
70 return o, core.E("duplicate-option", "duplicate option --"+key, 2)
71 }
72 if bools[key] {
73 if has {
74 return o, core.E("invalid-option", "boolean options do not take a value", 2)
75 }
76 o.flags[key] = "true"
77 } else if values[key] {
78 if !has {
79 i++
80 if i == len(args) {
81 return o, core.E("missing-option-value", "missing value for --"+key, 2)
82 }
83 value = args[i]
84 }
85 o.flags[key] = value
86 } else {
87 return o, core.E("unknown-option", "unknown option --"+key, 2)
88 }
89 }
90 return o, nil
91}
92func (o options) get(k, def string) string {
93 if v, ok := o.flags[k]; ok {
94 return v

Calls 1

EFunction · 0.92