Files
db-wait/cmd/root.go
Markus Pesch 172d8c072b
Some checks failed
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-amd64) (push) Successful in 27s
Run Golang tests / Run unit tests (stable, ubuntu-latest-amd64) (push) Failing after 7s
Lint Markdown files / Run markdown linter (push) Successful in 4s
Lint Golang files / Run golang CI linter (stable, ubuntu-latest-arm64) (push) Successful in 1m7s
Run Golang tests / Run unit tests (stable, ubuntu-latest-arm64) (push) Failing after 17s
fix(cmd): add nosec for example
2026-05-03 20:53:21 +02:00

51 lines
1.2 KiB
Go

package cmd
import (
"net/url"
"time"
"git.cryptic.systems/volker.raschek/db-wait/pkg/dbwait"
"github.com/spf13/cobra"
)
func Execute(version string) error {
rootCmd := &cobra.Command{
Use: "db-wait",
Short: "Tool to wait until a connection to a database can be established",
Args: cobra.ExactArgs(1),
RunE: rootRunE,
//#nosec G101
Long: `Wait until a database connection can be established and returns a zero exit code if successfully
# Wait until oracle database is ready to establish connections
$ db-wait oracle://user:password@localhost:1521/xe
# Wait until postgres database is ready to establish connections
$ db-wait postgres://user:password@localhost:5432/postgres?sslmode=disable
`,
}
rootCmd.Flags().Duration("period", time.Second*5, "Period")
rootCmd.Flags().Duration("timeout", time.Second*60, "Timeout")
return rootCmd.Execute()
}
func rootRunE(cmd *cobra.Command, args []string) error {
period, err := cmd.Flags().GetDuration("period")
if err != nil {
return err
}
timeout, err := cmd.Flags().GetDuration("timeout")
if err != nil {
return err
}
databaseURL, err := url.Parse(args[0])
if err != nil {
return err
}
return dbwait.Wait(databaseURL, period, timeout)
}