2023-01-17 00:55:28 -06:00
// root.go
// Copyright (C) Andrew Woodlee 2023
// License: Apache-2.0
2022-12-15 10:42:21 -06:00
package cmd
import (
"fmt"
"os"
"github.com/spf13/cobra"
)
var (
// Used for flags.
2025-02-08 15:17:34 -06:00
cfgFile string
verbose bool
logFile string
s3Endpoint string
2022-12-15 10:42:21 -06:00
rootCmd = & cobra . Command {
Use : "backy" ,
Short : "An easy-to-configure backup tool." ,
2023-01-17 00:55:28 -06:00
Long : ` Backy is a command-line application useful for configuring backups, or any commands run in sequence. ` ,
2022-12-15 10:42:21 -06:00
}
)
// Execute executes the root command.
2023-01-17 00:55:28 -06:00
func Execute ( ) {
if err := rootCmd . Execute ( ) ; err != nil {
fmt . Println ( err )
os . Exit ( 1 )
}
2022-12-15 10:42:21 -06:00
}
func init ( ) {
2025-01-14 09:42:43 -06:00
rootCmd . PersistentFlags ( ) . StringVar ( & logFile , "log-file" , "" , "log file to write to" )
2023-02-01 23:45:23 -06:00
rootCmd . PersistentFlags ( ) . StringVarP ( & cfgFile , "config" , "f" , "" , "config file to read from" )
2022-12-15 10:42:21 -06:00
rootCmd . PersistentFlags ( ) . BoolVarP ( & verbose , "verbose" , "v" , false , "Sets verbose level" )
2025-02-08 15:17:34 -06:00
rootCmd . PersistentFlags ( ) . StringVar ( & s3Endpoint , "s3-endpoint" , "" , "Sets the S3 endpoint used for config file fetching. Overrides S3_ENDPOINT env variable." )
2023-09-08 23:42:13 -05:00
rootCmd . AddCommand ( backupCmd , execCmd , cronCmd , versionCmd , listCmd )
2022-12-15 10:42:21 -06:00
}
2025-02-08 15:17:34 -06:00
func parseS3Config ( ) {
if s3Endpoint != "" {
os . Setenv ( "S3_ENDPOINT" , s3Endpoint )
}
}