reworked snapshot

This commit is contained in:
jandre 2021-02-16 22:19:27 +01:00
parent fbdc69f168
commit cce762cb78

View File

@ -17,7 +17,7 @@ package cmd
import ( import (
"os" "os"
"github.com/desmo999r/formolcli/pkg/backup" "github.com/desmo999r/formolcli/pkg/restic"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -25,32 +25,22 @@ import (
var snapshotCmd = &cobra.Command{ var snapshotCmd = &cobra.Command{
Use: "snapshot", Use: "snapshot",
Short: "A brief description of your command", Short: "A brief description of your command",
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. var snapshotDeleteCmd = &cobra.Command{
This application is a tool to generate the needed files Use: "delete",
to quickly create a Cobra application.`, Short: "delete a snapshot",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
snapshot, _ := cmd.Flags().GetString("snapshot") snapshot, _ := cmd.Flags().GetString("snapshot-id")
if err := backup.DeleteSnapshot(snapshot); err != nil { if err := restic.DeleteSnapshot(snapshot); err != nil {
os.Exit(1) os.Exit(1)
} }
}, },
} }
func init() { func init() {
deleteCmd.AddCommand(snapshotCmd) rootCmd.AddCommand(snapshotCmd)
snapshotCmd.AddCommand(snapshotDeleteCmd)
// Here you will define your flags and configuration settings. snapshotDeleteCmd.Flags().String("snapshot-id", "", "The snapshot to delete")
snapshotDeleteCmd.MarkFlagRequired("snapshot-id")
// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// snapshotCmd.PersistentFlags().String("foo", "", "A help for foo")
// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// snapshotCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
snapshotCmd.Flags().String("snapshot", "", "The snapshot to delete")
snapshotCmd.MarkFlagRequired("snapshot")
} }