-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
68 lines (57 loc) · 1.74 KB
/
options.go
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package add
import (
"context"
"flag"
"fmt"
"github.com/sfomuseum/go-flags/flagset"
)
type RunOptions struct {
AccountsDatabaseURI string
AliasesDatabaseURI string
PropertiesDatabaseURI string
AccountId int64
AccountName string
Aliases []string
AccountType string
Discoverable bool
DisplayName string
Blurb string
URL string
PublicKeyURI string
PrivateKeyURI string
AccountIconURI string
AllowRemoteIconURI bool
EmbedIconURI bool
Properties map[string]string
}
func OptionsFromFlagSet(ctx context.Context, fs *flag.FlagSet) (*RunOptions, error) {
flagset.Parse(fs)
err := flagset.SetFlagsFromEnvVars(fs, "ACTIVITYPUB")
if err != nil {
return nil, fmt.Errorf("Failed to derive flags from environment variables, %w", err)
}
properties_map := make(map[string]string)
for _, kv := range properties_kv {
properties_map[kv.Key()] = kv.Value().(string)
}
opts := &RunOptions{
AccountsDatabaseURI: accounts_database_uri,
AliasesDatabaseURI: aliases_database_uri,
PropertiesDatabaseURI: properties_database_uri,
AccountId: account_id,
AccountName: account_name,
Aliases: aliases,
AccountType: account_type,
AccountIconURI: account_icon_uri,
AllowRemoteIconURI: allow_remote_icon_uri,
EmbedIconURI: embed_icon_uri,
Discoverable: discoverable,
DisplayName: display_name,
Blurb: blurb,
URL: account_url,
PublicKeyURI: public_key_uri,
PrivateKeyURI: private_key_uri,
Properties: properties_map,
}
return opts, nil
}