ezshare/actions/misc.go
Torjus Håkestad fd729eef89
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
Rename module
2022-01-13 18:40:15 +01:00

51 lines
1.0 KiB
Go

package actions
import (
"fmt"
"os"
"git.t-juice.club/torjus/ezshare/certs"
"git.t-juice.club/torjus/ezshare/config"
"github.com/urfave/cli/v2"
)
func ActionGencerts(c *cli.Context) error {
outDir := "."
if c.IsSet("out-dir") {
outDir = c.String("out-dir")
}
if !c.IsSet("hostname") {
return fmt.Errorf("--hostname required")
}
hostname := c.String("hostname")
return certs.GenAllCerts(outDir, hostname)
}
func getConfig(c *cli.Context) (*config.Config, error) {
if c.IsSet("config") {
cfgPath := c.String("config")
return config.FromFile(cfgPath)
}
if val, ok := os.LookupEnv("EZSHARE_CONFIG"); ok {
return config.FromFile(val)
}
cfg, err := config.FromDefaultLocations()
if err == nil {
verbosePrint(c, fmt.Sprintf("Config loaded from %s", cfg.Location()))
}
if cfg == nil {
cfg = config.FromDefault()
}
cfg.UpdateFromEnv()
if cfg.Client.Valid() == nil || cfg.Server.Valid() == nil {
return cfg, nil
}
return cfg, err
}
func verbosePrint(c *cli.Context, message string) {
if c.Bool("verbose") {
fmt.Println(message)
}
}