shithub: hell

Download patch

ref: 8f3e0d3cc7476dc877297f8fe7e9ce308248f93f
parent: 482ed92dbc236887d206a1b3f3d14c095ecdc2f4
author: penny <penny@limitedideas.org>
date: Wed Oct 1 09:17:30 EDT 2025

clean up the mod files and switch to TOML for configs

--- a/config.go
+++ b/config.go
@@ -1,6 +1,7 @@
 package main
 
 import (
+	"bytes"
 	"fmt"
 	"io/ioutil"
 	"os"
@@ -7,20 +8,23 @@
 	"time"
 	"strings"
 	
-	"github.com/BurntSushi/toml"
+	"github.com/pelletier/go-toml/v2"
 )
 
 const configFileName = ".hell.conf"
 
 type Hellprefs struct {
-	Apidelay float32 `toml:"apidelay"`
-	Save_Location string `toml:"save_location"`
-	Browser string `toml:"browser"`
-	ImageViewer string `toml:"image_viewer"`
-	MediaImport string `toml:"media_importer"`
+	Apidelay float32 `toml:"apidelay" comment:"Time in seconds between API requests, accepts floats"`
+	Save_Location string `toml:"save_location" comment:"Save location for /download"`
+	Browser string `toml:"browser" comment:"System browser command."`
+	ImageViewer string `toml:"image_viewer" comment:"System image viewer command."`
+	MediaImport string `toml:"media_importer" comment:"Alternative media command used with /import"`
 }
 
-type account struct {
+type account_array struct {
+	AccountConfigs        []*mastodon_account `toml:"account"`
+}
+type mastodon_account struct {
 	MASTODON_CLIENT_ID     string    `toml:"MASTODON_CLIENT_ID"`
 	MASTODON_CLIENT_SECRET string    `toml:"MASTODON_CLIENT_SECRET"`
 	MASTODON_ACCESS_TOKEN  string    `toml:"MASTODON_ACCESS_TOKEN"`
@@ -74,8 +78,9 @@
 	return *prefs
 }
 
-func loadConfig() (*account, error) {
-	config := &account{}
+func loadConfig() (*mastodon_account, error) {
+	config := &account_array{}
+	first_account := &mastodon_account{}
 	homedir, err := os.UserHomeDir()
 	var configpath string
 	if err == nil {
@@ -89,23 +94,26 @@
 	if _, err = os.Stat(configpath); os.IsNotExist(err) {
 		// no config, create account
 		client := ConfigureClient()
-		config.URL = "https://eldritch.cafe"
-		config.MASTODON_CLIENT_ID = client.Config.ClientID
-		config.MASTODON_CLIENT_SECRET = client.Config.ClientSecret
-		config.MASTODON_ACCESS_TOKEN = client.Config.AccessToken
+		first_account.URL = "https://eldritch.cafe"
+		first_account.MASTODON_CLIENT_ID = client.Config.ClientID
+		first_account.MASTODON_CLIENT_SECRET = client.Config.ClientSecret
+		first_account.MASTODON_ACCESS_TOKEN = client.Config.AccessToken
 
-		config.Preferences = initPrefs()
-
-		data, err := toml.Marshal(config)
+		first_account.Preferences = initPrefs()
+		config.AccountConfigs = append(config.AccountConfigs, first_account)
+		var b bytes.Buffer
+		encoder := toml.NewEncoder(&b)
+		encoder.SetIndentTables(true)
+		err = encoder.Encode(config)
 		if err != nil {
 			return nil, fmt.Errorf("error marshalling config: %w", err)
 		}
 
-		err = ioutil.WriteFile(configpath, data, 0644)
+		err = ioutil.WriteFile(configpath, b.Bytes(), 0644)
 		if err != nil {
 			return nil, fmt.Errorf("error writing config file: %w", err)
 		}
-		return config, nil
+		return first_account, nil
 	}
 
 	// File exists, load it
@@ -118,23 +126,31 @@
 	if err != nil {
 		return nil, fmt.Errorf("error unmarshalling config: %w", err)
 	}
-	prefs := &config.Preferences
-	prefs, fixed := fixPrefs(&config.Preferences)
-	config.Preferences = *prefs
+	if len(config.AccountConfigs) < 1 {
+		return nil, fmt.Errorf("empty config?\n")
+	}
+	
+	prefval := config.AccountConfigs[0].Preferences
+	prefs := &prefval
+	prefs, fixed := fixPrefs(prefs)
+	config.AccountConfigs[0].Preferences = *prefs
 
 	if fixed {
-		data, err = toml.Marshal(config)
+		var b bytes.Buffer
+		encoder := toml.NewEncoder(&b)
+		encoder.SetIndentTables(true)
+		err = encoder.Encode(config)
 		if err != nil {
 			return nil, fmt.Errorf("error marshalling config: %w", err)
 		}
 
-		err = ioutil.WriteFile(configpath, data, 0644)
+		err = ioutil.WriteFile(configpath, b.Bytes(), 0644)
 		if err != nil {
 			return nil, fmt.Errorf("error writing config file: %w", err)
 		}
 	}
-	config.Preferences.Save_Location = expandDir(config.Preferences.Save_Location)
-	return config, nil
+	prefs.Save_Location = expandDir(prefs.Save_Location)
+	return config.AccountConfigs[0], nil
 }
 
 func expandDir(dir string) string {
--- a/go.mod
+++ b/go.mod
@@ -1,32 +1,20 @@
 module hell
 
-go 1.23.8
+go 1.24.0
 
 require (
+	codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20251001171436-178f7eef4328
 	github.com/ergochat/readline v0.1.3
 	github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
 	github.com/k3a/html2text v1.2.1
-	golang.org/x/net v0.42.0
-	golang.org/x/term v0.33.0
+	github.com/pelletier/go-toml/v2 v2.2.4
+	golang.org/x/net v0.44.0
+	golang.org/x/term v0.35.0
 )
 
 require (
-	codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20250923211910-cfaf18532c25 // indirect
-	github.com/BurntSushi/toml v1.5.0 // indirect
-	github.com/google/go-cmp v0.6.0 // indirect
-	github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
 	github.com/gorilla/websocket v1.5.3 // indirect
-	github.com/jtolds/gls v4.20.0+incompatible // indirect
-	github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d // indirect
-	github.com/smartystreets/goconvey v1.6.4 // indirect
-	github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 // indirect
-	github.com/yuin/goldmark v1.4.13 // indirect
-	golang.org/x/crypto v0.40.0 // indirect
-	golang.org/x/mod v0.25.0 // indirect
-	golang.org/x/sync v0.16.0 // indirect
-	golang.org/x/sys v0.34.0 // indirect
-	golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457 // indirect
-	golang.org/x/text v0.27.0 // indirect
-	golang.org/x/tools v0.34.0 // indirect
-	golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7 // indirect
+	github.com/tomnomnom/linkheader v0.0.0-20250811210735-e5fe3b51442e // indirect
+	golang.org/x/sys v0.36.0 // indirect
+	golang.org/x/text v0.29.0 // indirect
 )
--- a/go.sum
+++ b/go.sum
@@ -1,10 +1,7 @@
-codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20250923211910-cfaf18532c25 h1:ou5aQCb1QfkralqKoTJ1XUm4OKO7igrC/VBRj8P1eOY=
-codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20250923211910-cfaf18532c25/go.mod h1:uBGYW1AuCWBfm/LaIH4X4SnuWGWcSP4DNH/v/KUUMj8=
-github.com/BurntSushi/toml v1.5.0 h1:W5quZX/G/csjUnuI8SUYlsHs9M38FC7znL0lIO+DvMg=
-github.com/BurntSushi/toml v1.5.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
+codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20251001171436-178f7eef4328 h1:azMD7sk28oe+aHzrtkjA86KkBST33tOvdN8Tt2SpG0g=
+codeberg.org/penny64/hellclient-go-mastodon v0.0.0-20251001171436-178f7eef4328/go.mod h1:uBGYW1AuCWBfm/LaIH4X4SnuWGWcSP4DNH/v/KUUMj8=
 github.com/ergochat/readline v0.1.3 h1:/DytGTmwdUJcLAe3k3VJgowh5vNnsdifYT6uVaf4pSo=
 github.com/ergochat/readline v0.1.3/go.mod h1:o3ux9QLHLm77bq7hDB21UTm6HlV2++IPDMfIfKDuOgY=
-github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
 github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
 github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
@@ -15,29 +12,24 @@
 github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
 github.com/k3a/html2text v1.2.1 h1:nvnKgBvBR/myqrwfLuiqecUtaK1lB9hGziIJKatNFVY=
 github.com/k3a/html2text v1.2.1/go.mod h1:ieEXykM67iT8lTvEWBh6fhpH4B23kB9OMKPdIBmgUqA=
+github.com/pelletier/go-toml/v2 v2.2.4 h1:mye9XuhQ6gvn5h28+VilKrrPoQVanw5PMw/TB0t5Ec4=
+github.com/pelletier/go-toml/v2 v2.2.4/go.mod h1:2gIqNv+qfxSVS7cM2xJQKtLSTLUE9V8t9Stt+h56mCY=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d h1:zE9ykElWQ6/NYmHa3jpm/yHnI4xSofP+UP6SpjHcSeM=
 github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
 github.com/smartystreets/goconvey v1.6.4 h1:fv0U8FUIMPNf1L9lnHLvLhgicrIVChEkdzIKYqbNC9s=
 github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
-github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80 h1:nrZ3ySNYwJbSpD6ce9duiP+QkD3JuLCcWkdaehUS/3Y=
-github.com/tomnomnom/linkheader v0.0.0-20180905144013-02ca5825eb80/go.mod h1:iFyPdL66DjUD96XmzVL3ZntbzcflLnznH0fr99w5VqE=
-github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
+github.com/tomnomnom/linkheader v0.0.0-20250811210735-e5fe3b51442e h1:tD38/4xg4nuQCASJ/JxcvCHNb46w0cdAaJfkzQOO1bA=
+github.com/tomnomnom/linkheader v0.0.0-20250811210735-e5fe3b51442e/go.mod h1:krvJ5AY/MjdPkTeRgMYbIDhbbbVvnPQPzsIsDJO8xrY=
 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
-golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
-golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
-golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
+golang.org/x/net v0.44.0 h1:evd8IRDyfNBMBTTY5XRF1vaZlD+EmWx6x8PkhR04H/I=
+golang.org/x/net v0.44.0/go.mod h1:ECOoLqd5U3Lhyeyo/QDCEVQ4sNgYsqvCZ722XogGieY=
 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
-golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
-golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-golang.org/x/telemetry v0.0.0-20240521205824-bda55230c457/go.mod h1:pRgIJT+bRLFKnoM1ldnzKoxTIn14Yxz928LQRYYgIN0=
-golang.org/x/term v0.33.0 h1:NuFncQrRcaRvVmgRkvM3j/F00gWIAlcmlB8ACEKmGIg=
-golang.org/x/term v0.33.0/go.mod h1:s18+ql9tYWp1IfpV9DmCtQDDSRBUjKaw9M1eAv5UeF0=
+golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
+golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
+golang.org/x/term v0.35.0 h1:bZBVKBudEyhRcajGcNc3jIfWPqV4y/Kt2XcoigOWtDQ=
+golang.org/x/term v0.35.0/go.mod h1:TPGtkTLesOwf2DE8CgVYiZinHAOuy5AYUYT1lENIZnA=
 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
-golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
+golang.org/x/text v0.29.0 h1:1neNs90w9YzJ9BocxfsQNHKuAT4pkghyXc4nhZ6sJvk=
+golang.org/x/text v0.29.0/go.mod h1:7MhJOA9CD2qZyOKYazxdYMF85OwPdEr9jTtBpO7ydH4=
 golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
-golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
-golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
--- a/mastodon.go
+++ b/mastodon.go
@@ -56,7 +56,7 @@
 	return c
 }
 
-func initClient(account *account) *mastodon.Client {
+func initClient(account *mastodon_account) *mastodon.Client {
 
 	clientID := account.MASTODON_CLIENT_ID
 	clientSecret := account.MASTODON_CLIENT_ID
--