[WIP] v0.7.0 almost ready to release
This commit is contained in:
@ -12,8 +12,8 @@ import (
|
||||
|
||||
var (
|
||||
backupCmd = &cobra.Command{
|
||||
Use: "backup [--lists=list1,list2,... | -l list1, list2,...]",
|
||||
Short: "Runs commands defined in config file.",
|
||||
Use: "backup [--lists=list1 --lists list2 ... | -l list1 -l list2 ...]",
|
||||
Short: "Runs commands defined in config file. Use -l flag multiple times to run multiple lists.",
|
||||
Long: "Backup executes commands defined in config file.\nUse the --lists or -l flag to execute the specified lists. If not flag is not given, all lists will be executed.",
|
||||
Run: Backup,
|
||||
}
|
||||
@ -23,8 +23,9 @@ var (
|
||||
var cmdLists []string
|
||||
|
||||
func init() {
|
||||
parseS3Config()
|
||||
|
||||
backupCmd.Flags().StringSliceVarP(&cmdLists, "lists", "l", nil, "Accepts comma-separated names of command lists to execute.")
|
||||
backupCmd.Flags().StringArrayVarP(&cmdLists, "lists", "l", nil, "Accepts comma-separated names of command lists to execute.")
|
||||
|
||||
}
|
||||
|
||||
|
@ -16,8 +16,9 @@ var (
|
||||
)
|
||||
|
||||
func cron(cmd *cobra.Command, args []string) {
|
||||
parseS3Config()
|
||||
|
||||
opts := backy.NewOpts(cfgFile, backy.CronEnabled())
|
||||
opts := backy.NewOpts(cfgFile, backy.EnableCron())
|
||||
opts.InitConfig()
|
||||
opts.ReadConfig()
|
||||
|
||||
|
@ -23,12 +23,11 @@ var (
|
||||
func init() {
|
||||
execCmd.AddCommand(hostExecCommand)
|
||||
|
||||
hostExecCommand.Flags().StringSliceVarP(&hostsList, "hosts", "m", nil, "Accepts comma-separated names of hosts.")
|
||||
hostExecCommand.Flags().StringSliceVarP(&cmdList, "commands", "c", nil, "Accepts comma-separated names of commands.")
|
||||
|
||||
}
|
||||
|
||||
func execute(cmd *cobra.Command, args []string) {
|
||||
parseS3Config()
|
||||
|
||||
if len(args) < 1 {
|
||||
logging.ExitWithMSG("Please provide a command to run. Pass --help to see options.", 1, nil)
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import (
|
||||
|
||||
var (
|
||||
hostExecCommand = &cobra.Command{
|
||||
Use: "host [--commands=command1,command2, ... | -c command1,command2, ...] [--hosts=host1,hosts2, ... | -m host1,host2, ...] ",
|
||||
Use: "host [--command=command1 --command=command2 ... | -c command1 -c command2 ...] [--hosts=host1 --hosts=hosts2 ... | -m host1 -m host2 ...] ",
|
||||
Short: "Runs command defined in config file on the hosts in order specified.",
|
||||
Long: "Host executes specified commands on the hosts defined in config file.\nUse the --commands or -c flag to choose the commands.",
|
||||
Run: Host,
|
||||
@ -21,6 +21,10 @@ var cmdList []string
|
||||
|
||||
func init() {
|
||||
|
||||
hostExecCommand.Flags().StringArrayVarP(&hostsList, "hosts", "m", nil, "Accepts space-separated names of hosts.")
|
||||
hostExecCommand.Flags().StringArrayVarP(&cmdList, "command", "c", nil, "Accepts space-separated names of commands.")
|
||||
parseS3Config()
|
||||
|
||||
}
|
||||
|
||||
// cli input should be hosts and commands. Hosts are defined in config files.
|
||||
@ -40,6 +44,7 @@ func Host(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
// host is only checked when we read the SSH File
|
||||
// so a check may not be needed here
|
||||
// but we can check if the host is in the config file
|
||||
for _, h := range hostsList {
|
||||
_, hostFound := backyConfOpts.Hosts[h]
|
||||
if !hostFound {
|
||||
|
@ -38,6 +38,7 @@ func List(cmd *cobra.Command, args []string) {
|
||||
if cmdLists != nil {
|
||||
|
||||
}
|
||||
parseS3Config()
|
||||
|
||||
opts := backy.NewOpts(cfgFile)
|
||||
|
||||
|
16
cmd/root.go
16
cmd/root.go
@ -13,9 +13,10 @@ import (
|
||||
|
||||
var (
|
||||
// Used for flags.
|
||||
cfgFile string
|
||||
verbose bool
|
||||
logFile string
|
||||
cfgFile string
|
||||
verbose bool
|
||||
logFile string
|
||||
s3Endpoint string
|
||||
|
||||
rootCmd = &cobra.Command{
|
||||
Use: "backy",
|
||||
@ -33,11 +34,16 @@ func Execute() {
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&logFile, "log-file", "", "log file to write to")
|
||||
|
||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "f", "", "config file to read from")
|
||||
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Sets verbose level")
|
||||
|
||||
rootCmd.PersistentFlags().StringVar(&s3Endpoint, "s3-endpoint", "", "Sets the S3 endpoint used for config file fetching. Overrides S3_ENDPOINT env variable.")
|
||||
rootCmd.AddCommand(backupCmd, execCmd, cronCmd, versionCmd, listCmd)
|
||||
}
|
||||
|
||||
func parseS3Config() {
|
||||
if s3Endpoint != "" {
|
||||
os.Setenv("S3_ENDPOINT", s3Endpoint)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user