diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-06-28 06:16:07 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-06-28 06:16:07 +0200 |
| commit | 9eacbb42f9a5931bf33d968f775fc806c46b11b0 (patch) | |
| tree | bf9a34182b2db560023ba0deb060146bdbcc0d34 /main.go | |
| parent | 4137fae6df4e77198b8ddd9d9647a1ee0c7c49d3 (diff) | |
| download | colabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.tar.gz colabctl-9eacbb42f9a5931bf33d968f775fc806c46b11b0.zip | |
Init
Diffstat (limited to 'main.go')
| -rw-r--r-- | main.go | 51 |
1 files changed, 51 insertions, 0 deletions
@@ -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 <id> --client-secret <secret> + +To create credentials, visit: + https://console.cloud.google.com/apis/credentials`) + os.Exit(1) + } +} |
