-
Notifications
You must be signed in to change notification settings - Fork 384
/
mini.go
74 lines (63 loc) · 2.14 KB
/
mini.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
69
70
71
72
73
74
package main
import (
"context"
"flag"
"github.com/peterbourgon/ff/v3/ffcli"
"berty.tech/berty/v2/go/cmd/berty/mini"
)
func miniCommand() *ffcli.Command {
var groupFlag string
fsBuilder := func() (*flag.FlagSet, error) {
fs := flag.NewFlagSet("berty mini", flag.ExitOnError)
fs.String("config", "", "config file (optional)")
fs.StringVar(&groupFlag, "mini.group", groupFlag, "group to join, leave empty to create a new group")
manager.Session.Kind = "cli.mini"
manager.SetupLoggingFlags(fs) // also available at root level
manager.SetupMetricsFlags(fs) // add flags to enable metrics
manager.SetupLocalMessengerServerFlags(fs) // add flags to allow creating a full node in the same process
manager.SetupEmptyGRPCListenersFlags(fs) // by default, we don't want to expose gRPC server for mini
manager.SetupRemoteNodeFlags(fs) // mini can be run against an already running server
manager.SetupInitTimeout(fs)
return fs, nil
}
return &ffcli.Command{
Name: "mini",
ShortHelp: "start a terminal-based mini berty client (not fully compatible with the app)",
ShortUsage: "berty [global flags] mini [flags]",
FlagSetBuilder: fsBuilder,
Options: ffSubcommandOptions(),
UsageFunc: usageFunc,
Exec: func(ctx context.Context, args []string) error {
if len(args) > 0 {
return flag.ErrHelp
}
// mini does not support stderr logging
manager.Logging.StderrFilters = ""
// logger
logger, err := manager.GetLogger()
if err != nil {
return err
}
miniLogger := logger.Named("mini")
// messenger client
messengerClient, err := manager.GetMessengerClient()
if err != nil {
return err
}
// protocol client
protocolClient, err := manager.GetProtocolClient()
if err != nil {
return err
}
lcmanager := manager.GetLifecycleManager()
return mini.Main(ctx, &mini.Opts{
GroupInvitation: groupFlag,
MessengerClient: messengerClient,
ProtocolClient: protocolClient,
Logger: miniLogger,
DisplayName: manager.Node.Messenger.DisplayName,
LifecycleManager: lcmanager,
})
},
}
}