Skip to content

Commit

Permalink
Getting ready for release
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeemster committed Nov 24, 2015
1 parent fe3c670 commit 46ab923
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
28 changes: 20 additions & 8 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ import (
"log"
"os"
"path/filepath"
"strings"
)

const (
CLI_NAME = "sql-runner"
CLI_DESCRIPTION = `Run playbooks of SQL scripts in series and parallel on Redshift and Postgres`
CLI_VERSION = "0.4.0"

SQLROOT_BINARY = "BINARY"
SQLROOT_PLAYBOOK = "PLAYBOOK"
SQLROOT_CONSUL = "CONSUL"
SQLROOT_BINARY = "BINARY"
SQLROOT_PLAYBOOK = "PLAYBOOK"
SQLROOT_PLAYBOOK_CHILD = "PLAYBOOK_CHILD"
)

func main() {
Expand Down Expand Up @@ -86,22 +87,33 @@ func processFlags() Options {

// Resolve the path to our SQL scripts
func resolveSqlRoot(sqlroot string, playbookPath string, consulAddress string) (string, error) {
consulErr := fmt.Errorf("Cannot use %s option with -consul argument", sqlroot)
consulErr1 := fmt.Errorf("Cannot use %s option with -consul argument", sqlroot)
consulErr2 := fmt.Errorf("Cannot use %s option without -consul argument", sqlroot)

switch sqlroot {
case SQLROOT_BINARY:
if consulAddress != "" {
return "", consulErr
return "", consulErr1
}
return osext.ExecutableFolder()
case SQLROOT_PLAYBOOK:
if consulAddress != "" {
return "", consulErr
return getAbsConsulPath(playbookPath), nil
}
return filepath.Abs(filepath.Dir(playbookPath))
case SQLROOT_CONSUL:
return playbookPath, nil
case SQLROOT_PLAYBOOK_CHILD:
if consulAddress != "" {
return playbookPath, nil
}
return "", consulErr2
default:
return sqlroot, nil
}
}

// Gets an absolute path for Consul one directory up
func getAbsConsulPath(path string) string {
strSpl := strings.Split(path, "/")
trimSpl := strSpl[:len(strSpl)-1]
return strings.Join(trimSpl, "/")
}
2 changes: 1 addition & 1 deletion options.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (o *Options) GetFlagSet() *flag.FlagSet {
fs.BoolVar(&(o.help), "help", false, "Shows this message")
fs.BoolVar(&(o.version), "version", false, "Shows the program version")
fs.StringVar(&(o.playbook), "playbook", "", "Playbook of SQL scripts to execute")
fs.StringVar(&(o.sqlroot), "sqlroot", SQLROOT_PLAYBOOK, fmt.Sprintf("Absolute path to SQL scripts. Use %s, %s and %s for those respective paths", SQLROOT_PLAYBOOK, SQLROOT_BINARY, SQLROOT_CONSUL))
fs.StringVar(&(o.sqlroot), "sqlroot", SQLROOT_PLAYBOOK, fmt.Sprintf("Absolute path to SQL scripts. Use %s, %s and %s for those respective paths", SQLROOT_PLAYBOOK, SQLROOT_BINARY, SQLROOT_PLAYBOOK_CHILD))
fs.Var(&(o.variables), "var", "Variables to be passed to the playbook, in the key=value format")
fs.StringVar(&(o.fromStep), "fromStep", "", "Starts from a given step defined in your playbook")
fs.BoolVar(&(o.dryRun), "dryRun", false, "Runs through a playbook without executing any of the SQL")
Expand Down

0 comments on commit 46ab923

Please sign in to comment.