From 9eacbb42f9a5931bf33d968f775fc806c46b11b0 Mon Sep 17 00:00:00 2001 From: Onur Gündüz Date: Sun, 28 Jun 2026 06:16:07 +0200 Subject: Init --- main.go | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 main.go (limited to 'main.go') diff --git a/main.go b/main.go new file mode 100644 index 0000000..512f5f0 --- /dev/null +++ b/main.go @@ -0,0 +1,51 @@ +package main + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var ( + clientID = "" + clientSecret = "" +) + +var rootCmd = &cobra.Command{ + Use: "colabctl", +} + +func main() { + if err := rootCmd.Execute(); err != nil { + fmt.Fprintln(os.Stderr, err) + os.Exit(1) + } +} + +func init() { + // Allow credentials to be provided via environment variables as a + // convenient alternative to build-time injection. + if id := os.Getenv("COLAB_CLIENT_ID"); id != "" { + clientID = id + } + if secret := os.Getenv("COLAB_CLIENT_SECRET"); secret != "" { + clientSecret = secret + } +} + +// requireCredentials prints a helpful error and exits if the OAuth2 client +// credentials have not been configured. +func requireCredentials() { + if clientID == "" || clientSecret == "" { + fmt.Fprintln(os.Stderr, `Error: OAuth2 credentials not set. + +Set COLAB_CLIENT_ID and COLAB_CLIENT_SECRET environment variables, or run: + + colabctl auth login --client-id --client-secret + +To create credentials, visit: + https://console.cloud.google.com/apis/credentials`) + os.Exit(1) + } +} -- cgit v1.3.1