|
@@ -5,17 +5,25 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"strings"
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
+ "github.com/joho/godotenv"
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/cobra"
|
|
|
|
|
|
|
|
"gogs.netdome.biz/paul/cheapo/internal/chatto"
|
|
"gogs.netdome.biz/paul/cheapo/internal/chatto"
|
|
|
"gogs.netdome.biz/paul/cheapo/internal/game"
|
|
"gogs.netdome.biz/paul/cheapo/internal/game"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+// loadEnv reads a .env file from the working directory if present (godotenv).
|
|
|
|
|
+// Existing environment variables take precedence over .env values.
|
|
|
|
|
+func loadEnv() {
|
|
|
|
|
+ _ = godotenv.Load()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
// chattoClientFromEnv builds a Chatto client from the CHATTO_TOKEN
|
|
// chattoClientFromEnv builds a Chatto client from the CHATTO_TOKEN
|
|
|
-// environment variable; CHATTO_BASE_URL defaults to the public Chatto
|
|
|
|
|
-// server (https://chat.chatto.run). The token is provided by the operator;
|
|
|
|
|
-// this tool never fetches credentials itself.
|
|
|
|
|
|
|
+// environment variable (or .env file); CHATTO_BASE_URL defaults to the public
|
|
|
|
|
+// Chatto server (https://chat.chatto.run). The token is provided by the
|
|
|
|
|
+// operator; this tool never fetches credentials itself.
|
|
|
func chattoClientFromEnv() (*chatto.Client, error) {
|
|
func chattoClientFromEnv() (*chatto.Client, error) {
|
|
|
|
|
+ loadEnv()
|
|
|
base := os.Getenv("CHATTO_BASE_URL")
|
|
base := os.Getenv("CHATTO_BASE_URL")
|
|
|
if base == "" {
|
|
if base == "" {
|
|
|
base = "https://chat.chatto.run"
|
|
base = "https://chat.chatto.run"
|