-
Notifications
You must be signed in to change notification settings - Fork 48
Expand file tree
/
Copy pathmain.go
More file actions
98 lines (87 loc) · 3.48 KB
/
main.go
File metadata and controls
98 lines (87 loc) · 3.48 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* This file is part of GADS.
*
* Copyright (c) 2022-2025 Nikola Shabanov
*
* This source code is licensed under the GNU Affero General Public License v3.0.
* You may obtain a copy of the license at https://www.gnu.org/licenses/agpl-3.0.html
*/
package main
import (
"GADS/client/adb"
"GADS/hub"
"GADS/provider"
"embed"
"fmt"
"os"
"github.com/spf13/cobra"
)
var AppVersion = "development"
//go:embed resources
var resourceFiles embed.FS
func main() {
var rootCmd = &cobra.Command{Use: "GADS"}
rootCmd.PersistentFlags().String("mongo-db", "localhost:27017", "The address of the MongoDB instance")
// Hub Command
var hubCmd = &cobra.Command{
Use: "hub",
Short: "Run a hub component",
Run: func(cmd *cobra.Command, args []string) {
hub.StartHub(cmd.Flags(), AppVersion, uiFiles, resourceFiles)
},
}
hubCmd.Flags().String("host-address", "localhost", "The IP address of the host machine")
hubCmd.Flags().String("port", "", "The port on which the component should run")
hubCmd.Flags().Bool("auth", true, "Enable or disable authentication on hub endpoints, default is `true`")
hubCmd.Flags().String("files-dir", "", "Directory where resource files will be unpacked."+
"\nBy default app will try to use a temp dir on the host, use this flag only if you encounter issues with the temp folder."+
"\nAlso you need to have created the folder in advance!")
hubCmd.Flags().String("turn-username-suffix", "gads", "Suffix to append to TURN usernames (format: timestamp:suffix)")
rootCmd.AddCommand(hubCmd)
// Provider Command
var providerCmd = &cobra.Command{
Use: "provider",
Short: "Run a provider component",
Run: func(cmd *cobra.Command, args []string) {
provider.StartProvider(cmd.Flags(), resourceFiles)
},
}
providerCmd.Flags().String("nickname", "", "Nickname of the provider")
providerCmd.Flags().String("provider-folder", ".", "The folder where logs and other data will be stored")
providerCmd.Flags().String("log-level", "info", "The verbosity of the logs of the provider instance")
providerCmd.Flags().String("hub", "", "The address of the GADS hub instance")
providerCmd.Flags().String("turn-username-suffix", "gads", "Suffix to append to TURN usernames (format: timestamp:suffix)")
providerCmd.Flags().Bool("use-ios-pair-cache", false, "Cache iOS pair records on disk to skip Trust dialog on reconnect (for unsupervised devices)")
rootCmd.AddCommand(providerCmd)
// ADB Client Command
var adbClientCmd = &cobra.Command{
Use: "adb-client",
Short: "Connect to a remote Android device via ADB tunnel through the hub",
Run: func(cmd *cobra.Command, args []string) {
adb.Start(cmd.Flags())
},
}
adbClientCmd.Flags().String("hub", "", "Hub URL (e.g. http://localhost:10000)")
adbClientCmd.Flags().String("udid", "", "Device UDID to tunnel")
adbClientCmd.Flags().String("username", "", "GADS username")
adbClientCmd.Flags().String("password", "", "GADS password")
adbClientCmd.Flags().Int("port", 0, "Local port to listen on (0 = auto)")
adbClientCmd.MarkFlagRequired("hub")
adbClientCmd.MarkFlagRequired("udid")
adbClientCmd.MarkFlagRequired("username")
adbClientCmd.MarkFlagRequired("password")
rootCmd.AddCommand(adbClientCmd)
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the application version",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(AppVersion)
},
}
rootCmd.AddCommand(versionCmd)
// Execute the root command
if err := rootCmd.Execute(); err != nil {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
}