reworked postgres
This commit is contained in:
parent
680c23460b
commit
5b1a5827f6
@ -19,12 +19,33 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/desmo999r/formolcli/pkg/backup"
|
"github.com/desmo999r/formolcli/pkg/backup"
|
||||||
|
"github.com/desmo999r/formolcli/pkg/restore"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
)
|
)
|
||||||
|
|
||||||
// postgresCmd represents the postgres command
|
// postgresCmd represents the postgres command
|
||||||
var postgresCmd = &cobra.Command{
|
var postgresRestoreCmd = &cobra.Command{
|
||||||
Use: "postgres",
|
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",
|
Short: "backup a PostgreSQL database",
|
||||||
Long: `A longer description that spans multiple lines and likely contains examples
|
Long: `A longer description that spans multiple lines and likely contains examples
|
||||||
and usage of using your command. For example:
|
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() {
|
func init() {
|
||||||
backupCmd.AddCommand(postgresCmd)
|
rootCmd.AddCommand(postgresCmd)
|
||||||
|
postgresCmd.AddCommand(postgresBackupCmd)
|
||||||
|
postgresCmd.AddCommand(postgresRestoreCmd)
|
||||||
|
|
||||||
// Here you will define your flags and configuration settings.
|
// Here you will define your flags and configuration settings.
|
||||||
|
|
||||||
// Cobra supports Persistent Flags which will work for this command
|
// Cobra supports Persistent Flags which will work for this command
|
||||||
// and all subcommands, e.g.:
|
// 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
|
// Cobra supports local flags which will only run when this command
|
||||||
// is called directly, e.g.:
|
// is called directly, e.g.:
|
||||||
// postgresCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
// backupPostgresCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||||
postgresCmd.Flags().String("file", "", "The file the backup will be stored")
|
postgresBackupCmd.Flags().String("file", "", "The file the backup will be stored")
|
||||||
postgresCmd.Flags().String("hostname", "", "The postgresql server host")
|
postgresBackupCmd.Flags().String("hostname", "", "The postgresql server host")
|
||||||
postgresCmd.Flags().String("database", "", "The postgresql database")
|
postgresBackupCmd.Flags().String("database", "", "The postgresql database")
|
||||||
postgresCmd.Flags().String("username", "", "The postgresql username")
|
postgresBackupCmd.Flags().String("username", "", "The postgresql username")
|
||||||
postgresCmd.Flags().String("password", "", "The postgresql password")
|
postgresBackupCmd.Flags().String("password", "", "The postgresql password")
|
||||||
postgresCmd.MarkFlagRequired("path")
|
postgresBackupCmd.MarkFlagRequired("path")
|
||||||
postgresCmd.MarkFlagRequired("hostname")
|
postgresBackupCmd.MarkFlagRequired("hostname")
|
||||||
postgresCmd.MarkFlagRequired("database")
|
postgresBackupCmd.MarkFlagRequired("database")
|
||||||
postgresCmd.MarkFlagRequired("username")
|
postgresBackupCmd.MarkFlagRequired("username")
|
||||||
postgresCmd.MarkFlagRequired("password")
|
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")
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user