certwarden-deploy/internal/cli/root.go

45 lines
1.4 KiB
Go
Raw Normal View History

2024-06-28 15:28:54 +02:00
package cli
2024-07-03 10:00:21 +02:00
import (
"log/slog"
"os"
"code.lila.network/adoralaura/certwarden-deploy/internal/certificates"
"code.lila.network/adoralaura/certwarden-deploy/internal/configuration"
"code.lila.network/adoralaura/certwarden-deploy/internal/constants"
"code.lila.network/adoralaura/certwarden-deploy/internal/logger"
"github.com/spf13/cobra"
)
2024-06-28 15:28:54 +02:00
var RootCmd = &cobra.Command{
Use: "certwarden-deploy",
2024-07-03 10:00:21 +02:00
Short: "Deploy Certificates from CertWarden in a breeze",
Long: `certwarden-deploy is a CLI utility to deploy certificates managed by CertWarden.
Configuration is handled by a single YAML file, so you can get started quickly.
For more information on how to configure this tool, visit the docs at https://certwarden-deploy.adora.codes`,
Version: constants.Version,
CompletionOptions: cobra.CompletionOptions{DisableDefaultCmd: true},
Args: cobra.ExactArgs(0),
Run: handleRootCmd,
}
func handleRootCmd(cmd *cobra.Command, args []string) {
config, err := configuration.InitializeConfig()
if err != nil {
slog.Error("failed to initialize config", "error", err)
os.Exit(1)
}
2024-07-12 17:41:50 +02:00
log := logger.Initialize()
2024-07-11 16:11:11 +02:00
config.SubstituteKeys(log)
2024-06-28 15:28:54 +02:00
2024-07-11 16:11:11 +02:00
validation := config.IsValid()
if validation.HasMessages() {
validation.Print(log)
slog.Error("The configuration file has errors! Application cannot start unless all errors are corrected!")
2024-07-12 11:18:32 +02:00
os.Exit(1)
2024-07-11 16:11:11 +02:00
}
2024-07-03 11:56:04 +02:00
2024-07-03 10:00:21 +02:00
certificates.HandleCertificates(log, config)
2024-06-28 15:28:54 +02:00
}