feat(cli): option to generate config file for toml or json

This commit is contained in:
Anhgelus Morhtuuzh 2025-03-03 11:18:59 +01:00
parent 69ab8022bd
commit 383b67669a
No known key found for this signature in database
GPG key ID: CAD341EFA92DDDE5
2 changed files with 74 additions and 4 deletions

View file

@ -62,7 +62,7 @@ type BackgroundColor struct {
Colors []struct {
Color string `json:"color" toml:"color"`
Position uint `json:"position" toml:"position"`
} `json:"colors"`
} `json:"colors" toml:"colors"`
}
type ButtonColor struct {

76
main.go
View file

@ -20,19 +20,27 @@ var (
)
var (
domain string
configPath string
dev bool
domain string
configPath string
dev bool
generateToml bool
generateJson bool
)
func init() {
flag.StringVar(&domain, "domain", "", "domain to use")
flag.StringVar(&configPath, "config", "", "config to use")
flag.BoolVar(&dev, "dev", false, "dev mode enabled")
flag.BoolVar(&generateJson, "generate-json-config", false, "generate a config example")
flag.BoolVar(&generateToml, "generate-toml-config", false, "generate a config example")
}
func main() {
flag.Parse()
if generateToml || generateJson {
generateConfigFile(generateToml)
return
}
if domain == "" {
domain = os.Getenv("NOW_DOMAIN")
if domain == "" {
@ -123,3 +131,65 @@ func main() {
g.StartServer(":80")
}
}
func generateConfigFile(isToml bool) {
cfg := Config{
Image: "wallpaper.webp",
Description: "I am a beautiful description!",
Person: &Person{
Name: "John Doe",
Pronouns: "any",
Image: "pfp.webp",
Tags: []*Tag{
{"Hello", "World", ""},
{"I am", "a tag", ""},
},
},
Color: &Color{
Background: &BackgroundColor{
Type: "linear",
Angle: 141,
Colors: []struct {
Color string `json:"color" toml:"color"`
Position uint `json:"position" toml:"position"`
}{
{"#a4a2b8", 0},
{"#3b3860", 40},
{"#0f0c2c", 80},
},
},
Button: &ButtonColor{
Text: "#4c0850",
TextHover: "#57145b",
Background: "#f399d0",
BackgroundHover: "#f5c0e0",
},
Text: "#fff",
TagHover: "#000",
},
Links: []*Link{
{"/foo", "Blog"},
{"https://www.youtube.com/@anhgelus", "YouTube"},
},
Legal: &Legal{
LegalInformationLink: "/bar",
ImagesSource: []string{
"Profile picture: some one on website",
"Background picture: another one on another website",
},
FontSource: "Name by some one on website",
},
CustomPages: []string{"custom.json"},
}
var b []byte
var err error
if isToml {
b, err = toml.Marshal(&cfg)
} else {
b, err = json.Marshal(&cfg)
}
if err != nil {
panic(err)
}
println(string(b))
}