-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinputs.go
More file actions
53 lines (43 loc) · 1.36 KB
/
inputs.go
File metadata and controls
53 lines (43 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package cli
import (
"flag"
"os"
)
type Inputs struct {
AuthID string
AuthToken string
RawText string
RawQuery string
RawURL string
}
func NewInputs() *Inputs {
this := &Inputs{}
this.flags()
return this
}
func (this *Inputs) flags() {
flag.StringVar(&this.AuthID, "auth-id", "",
"The auth-id value. Defaults to `SMARTY_AUTH_ID` environment variable value if set.")
flag.StringVar(&this.AuthToken, "auth-token", "",
"The auth-token value. Defaults to `SMARTY_AUTH_TOKEN` environment variable value if set.")
flag.StringVar(&this.RawText, "raw", "", "The POST body (US Street API, US ZIP Code API, US Extract API).")
flag.StringVar(&this.RawQuery, "query", "", "A query string with input values."+authDisclaimerSuffix)
flag.StringVar(&this.RawURL, "url", "", "A url with query string input values."+authDisclaimerSuffix)
}
func (this *Inputs) ParseFlags() {
flag.Parse()
authID, authInEnvironment := os.LookupEnv("SMARTY_AUTH_ID")
authToken := os.Getenv("SMARTY_AUTH_TOKEN")
if this.AuthID == "" && authInEnvironment {
this.AuthID = authID
this.AuthToken = authToken
}
}
const authDisclaimerSuffix = "Even when present, auth-id and auth-token query string values will be ignored. " +
"(" +
"US Street API, " +
"US ZIP Code API, " +
"US Autocomplete API, " +
"US Extract API, " +
"US Reverse Geocoding API, " +
"International Street API)"