-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
41 lines (32 loc) · 705 Bytes
/
Copy pathconfig.go
File metadata and controls
41 lines (32 loc) · 705 Bytes
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
package main
import (
"flag"
"fmt"
)
type Config struct {
Homeserver string
Username string
Password string
}
type ErrMissingArg string
func (e ErrMissingArg) Error() string {
return fmt.Sprint(string(e))
}
func parseArgs() (Config, error) {
homeserver := flag.String("homeserver", "https://matrix.org", "")
username := flag.String("username", "", "")
password := flag.String("password", "", "")
flag.Parse()
if *username == "" {
return Config{}, ErrMissingArg("username empty")
}
if *password == "" {
return Config{}, ErrMissingArg("password empty")
}
config := Config{
Homeserver: *homeserver,
Username: *username,
Password: *password,
}
return config, nil
}