Close host connections after all command have been run, added some flags to version subcommand

This commit is contained in:
2023-03-10 16:01:02 -06:00
parent 9ffa2e473e
commit 2ca5f193e4
5 changed files with 93 additions and 16 deletions

View File

@ -33,4 +33,9 @@ func Backup(cmd *cobra.Command, args []string) {
backyConfOpts.InitConfig()
config := backy.ReadConfig(backyConfOpts)
config.RunBackyConfig("")
for _, host := range config.Hosts {
if host.SshClient != nil {
host.SshClient.Close()
}
}
}

View File

@ -11,15 +11,21 @@ const versionStr = "0.2.4"
var (
versionCmd = &cobra.Command{
Use: "version",
Use: "version [flags]",
Short: "Prints the version and exits.",
Run: version,
}
numOnly bool
)
func version(cmd *cobra.Command, args []string) {
fmt.Printf("%s\n", versionStr)
cmd.PersistentFlags().BoolVarP(&numOnly, "num", "n", true, "Output the version number only.")
if numOnly {
fmt.Printf("%s\n", versionStr)
} else {
fmt.Printf("Version: %s", versionStr)
}
os.Exit(0)
}