forked from piotaixr/zfs-snapback
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- drop config file support (there's no config) - merge PreRunE with Run options for sync command - remove placeholder descriptions - remove unused code
- Loading branch information
Showing
4 changed files
with
15 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
vendor/ | ||
/dist | ||
zfs-snapback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,51 +15,33 @@ package cmd | |
|
||
import ( | ||
"fmt" | ||
"os/exec" | ||
|
||
"github.com/piotaixr/zfs-snapback/zfs" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// syncCmd represents the sync command | ||
// syncCmd represents the sync command. | ||
var syncCmd = &cobra.Command{ | ||
Use: "sync", | ||
Short: "Synchronizes ZFS snapshots", | ||
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.`, | ||
Args: cobra.ExactArgs(2), | ||
Use: "sync", | ||
Short: "Synchronizes ZFS snapshots", | ||
Args: cobra.ExactArgs(2), //nolint:mnd | ||
Example: "zfs-snapback sync [email protected]:zpool/var zpool/backup/remote.host", | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
var err error | ||
|
||
// source | ||
source, err = zfs.GetFilesystem(flags, args[0]) | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
source, err := zfs.GetFilesystem(flags, args[0]) | ||
if err != nil { | ||
return fmt.Errorf("invalid source '%s': %w", args[0], err) | ||
} | ||
|
||
// source | ||
destination, err = zfs.GetFilesystem(flags, args[1]) | ||
destination, err := zfs.GetFilesystem(flags, args[1]) | ||
if err != nil { | ||
return fmt.Errorf("invalid destination '%s': %w", args[1], err) | ||
} | ||
|
||
return nil | ||
}, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
checkError(zfs.DoSync(source, destination, flags)) | ||
return zfs.DoSync(source, destination, flags) | ||
}, | ||
} | ||
|
||
var ( | ||
flags zfs.Flags | ||
source *zfs.Fs | ||
destination *zfs.Fs | ||
) | ||
var flags zfs.Flags | ||
|
||
func init() { | ||
set := syncCmd.Flags() | ||
|
@@ -70,23 +52,4 @@ func init() { | |
set.StringVarP(&flags.Compression, "compression", "c", "", "Set the compression option for SSH (yes/no)") | ||
|
||
RootCmd.AddCommand(syncCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// syncCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// syncCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
func checkError(err error) { | ||
switch err := err.(type) { | ||
case *exec.ExitError: | ||
panic(string(err.Stderr)) | ||
case error: | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters