summaryrefslogtreecommitdiff
path: root/cmd/cli
diff options
context:
space:
mode:
authorjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
committerjwijenbergh <jeroenwijenbergh@protonmail.com>2022-04-22 16:29:59 +0200
commitb1d92b395322f2164ccfb44b0f7caebbaece6b62 (patch)
tree2133e4045b4af4d07a98674b7ae3a234670f0305 /cmd/cli
parent3a4ae2942b43923ff98fd2eca8878c3cf145686c (diff)
Refactor: Restructure project
- Add an internal folder where all the internal code lives - Make a state.go and state_test.go for the public interface This gives a more clear separation between functions and modules. It also makes this a more typical Go project setup.
Diffstat (limited to 'cmd/cli')
-rw-r--r--cmd/cli/main.go55
1 files changed, 55 insertions, 0 deletions
diff --git a/cmd/cli/main.go b/cmd/cli/main.go
new file mode 100644
index 0000000..1406175
--- /dev/null
+++ b/cmd/cli/main.go
@@ -0,0 +1,55 @@
+package main
+
+import (
+ "flag"
+ "fmt"
+ "os/exec"
+ "strings"
+
+ eduvpn "github.com/jwijenbergh/eduvpn-common"
+)
+
+func openBrowser(urlString string) {
+ fmt.Printf("OAuth: Initialized with AuthURL %s\n", urlString)
+ fmt.Println("OAuth: Opening browser with xdg-open...")
+ exec.Command("xdg-open", urlString).Start()
+}
+
+func logState(oldState string, newState string, data string) {
+ fmt.Printf("State: %s -> State: %s with data %s\n", oldState, newState, data)
+
+ if newState == "OAuth_Started" {
+ openBrowser(data)
+ }
+}
+
+func main() {
+ urlArg := flag.String("url", "", "The url of the vpn")
+ flag.Parse()
+
+ urlString := *urlArg
+
+ if urlString != "" {
+ if !strings.HasPrefix(urlString, "https://") {
+ urlString = "https://" + urlString
+ }
+
+ state := eduvpn.GetVPNState()
+
+ state.Register("org.eduvpn.app.linux", "configs", logState, true)
+ config, configErr := state.Connect(urlString)
+
+ if configErr != nil {
+ fmt.Printf("Config error %v", configErr)
+ return
+ }
+
+ fmt.Println(config)
+
+ state.Deregister()
+
+ return
+ }
+
+ flag.PrintDefaults()
+}