reworked postgres

This commit is contained in:
jandre 2021-02-16 22:18:21 +01:00
parent 680c23460b
commit 5b1a5827f6

View File

@ -19,12 +19,33 @@ import (
"fmt"
"github.com/desmo999r/formolcli/pkg/backup"
"github.com/desmo999r/formolcli/pkg/restore"
"github.com/spf13/cobra"
)
// postgresCmd represents the postgres command
var postgresCmd = &cobra.Command{
Use: "postgres",
var postgresRestoreCmd = &cobra.Command{
Use: "restore",
Short: "restore a PostgreSQL database",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("postgres called")
file, _ := cmd.Flags().GetString("file")
hostname, _ := cmd.Flags().GetString("hostname")
database, _ := cmd.Flags().GetString("database")
username, _ := cmd.Flags().GetString("username")
password, _ := cmd.Flags().GetString("password")
_ = restore.RestorePostgres(file, hostname, database, username, password)
},
}
var postgresBackupCmd = &cobra.Command{
Use: "backup",
Short: "backup a PostgreSQL database",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
@ -43,26 +64,43 @@ to quickly create a Cobra application.`,
},
}
var postgresCmd = &cobra.Command{
Use: "postgres",
Short: "postgres actions",
}
func init() {
backupCmd.AddCommand(postgresCmd)
rootCmd.AddCommand(postgresCmd)
postgresCmd.AddCommand(postgresBackupCmd)
postgresCmd.AddCommand(postgresRestoreCmd)
// Here you will define your flags and configuration settings.
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// postgresCmd.PersistentFlags().String("foo", "", "A help for foo")
// backupPostgresCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// postgresCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
postgresCmd.Flags().String("file", "", "The file the backup will be stored")
postgresCmd.Flags().String("hostname", "", "The postgresql server host")
postgresCmd.Flags().String("database", "", "The postgresql database")
postgresCmd.Flags().String("username", "", "The postgresql username")
postgresCmd.Flags().String("password", "", "The postgresql password")
postgresCmd.MarkFlagRequired("path")
postgresCmd.MarkFlagRequired("hostname")
postgresCmd.MarkFlagRequired("database")
postgresCmd.MarkFlagRequired("username")
postgresCmd.MarkFlagRequired("password")
// backupPostgresCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
postgresBackupCmd.Flags().String("file", "", "The file the backup will be stored")
postgresBackupCmd.Flags().String("hostname", "", "The postgresql server host")
postgresBackupCmd.Flags().String("database", "", "The postgresql database")
postgresBackupCmd.Flags().String("username", "", "The postgresql username")
postgresBackupCmd.Flags().String("password", "", "The postgresql password")
postgresBackupCmd.MarkFlagRequired("path")
postgresBackupCmd.MarkFlagRequired("hostname")
postgresBackupCmd.MarkFlagRequired("database")
postgresBackupCmd.MarkFlagRequired("username")
postgresBackupCmd.MarkFlagRequired("password")
postgresRestoreCmd.Flags().String("file", "", "The file the database will be restored from")
postgresRestoreCmd.Flags().String("hostname", "", "The postgresql server host")
postgresRestoreCmd.Flags().String("database", "", "The postgresql database")
postgresRestoreCmd.Flags().String("username", "", "The postgresql username")
postgresRestoreCmd.Flags().String("password", "", "The postgresql password")
postgresRestoreCmd.MarkFlagRequired("path")
postgresRestoreCmd.MarkFlagRequired("hostname")
postgresRestoreCmd.MarkFlagRequired("database")
postgresRestoreCmd.MarkFlagRequired("username")
postgresRestoreCmd.MarkFlagRequired("password")
}