Added command and list execution (#1), small touchups

- Added exec command to execute individual commands
- Added --lists, -l flag to backup command
  - Run command lists (#1)
- Small touchups and documentation
This commit is contained in:
2023-01-20 02:42:52 -06:00
parent 37c57f6438
commit 03f54c8714
8 changed files with 259 additions and 91 deletions

View File

@ -2,31 +2,33 @@ package cmd
import (
"git.andrewnw.xyz/CyberShell/backy/pkg/backy"
"git.andrewnw.xyz/CyberShell/backy/pkg/notifications"
"git.andrewnw.xyz/CyberShell/backy/pkg/notification"
"github.com/spf13/cobra"
)
var (
backupCmd = &cobra.Command{
Use: "backup [--commands==list1,list2]",
Use: "backup [--lists==list1,list2]",
Short: "Runs commands defined in config file.",
Long: `Backup executes commands defined in config file,
use the -cmds flag to execute the specified commands.`,
Long: `Backup executes commands defined in config file.
Use the --lists flag to execute the specified commands.`,
Run: Backup,
}
)
var CmdList []string
// Holds command list to run
var cmdList []string
func init() {
// cobra.OnInitialize(initConfig)
backupCmd.Flags().StringSliceVar(&CmdList, "cmds", nil, "Accepts a comma-separated list of command lists to execute.")
backupCmd.Flags().StringSliceVarP(&cmdList, "lists", "l", nil, "Accepts a comma-separated names of command lists to execute.")
}
func Backup(cmd *cobra.Command, args []string) {
config := backy.ReadAndParseConfigFile(cfgFile)
notifications.SetupNotify(*config)
config := backy.ReadAndParseConfigFile(cfgFile, cmdList)
notification.SetupNotify(*config)
config.RunBackyConfig()
}