• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

snowplow / sql-runner / 15063404311

16 May 2025 07:46AM UTC coverage: 27.73% (+1.0%) from 26.721%
15063404311

push

github

jbeemster
Prepared for release

353 of 1273 relevant lines covered (27.73%)

2.04 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/sql_runner/options.go
1
// Copyright (c) 2015-2025 Snowplow Analytics Ltd. All rights reserved.
2
//
3
// This program is licensed to you under the Apache License Version 2.0,
4
// and you may not use this file except in compliance with the Apache License Version 2.0.
5
// You may obtain a copy of the Apache License Version 2.0 at http://www.apache.org/licenses/LICENSE-2.0.
6
//
7
// Unless required by applicable law or agreed to in writing,
8
// software distributed under the Apache License Version 2.0 is distributed on an
9
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
// See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
11
package main
12

13
import (
14
        "errors"
15
        "flag"
16
        "fmt"
17
        "strings"
18
)
19

20
// CLIVariables represents the cli variables map.
21
type CLIVariables map[string]string
22

23
// Implement the Value interface
24
func (i *CLIVariables) String() string {
×
25
        return fmt.Sprintf("%s", *i)
×
26
}
×
27

28
// Set adds a kv pair given as string to CLIVariables.
29
func (i *CLIVariables) Set(value string) error {
×
30
        var split = strings.Split(value, ",")
×
31

×
32
        for value := range split {
×
33
                kv := strings.SplitN(split[value], "=", 2)
×
34

×
35
                if len(kv) != 2 {
×
36
                        return errors.New("invalid size for key, value, key value should be in the key=value format")
×
37
                }
×
38

39
                (*i)[kv[0]] = kv[1]
×
40
        }
41
        return nil
×
42
}
43

44
// Options represents the SQL-Runner options.
45
type Options struct {
46
        help              bool
47
        version           bool
48
        playbook          string
49
        sqlroot           string
50
        fromStep          string
51
        dryRun            bool
52
        consul            string
53
        lock              string
54
        softLock          string
55
        checkLock         string
56
        deleteLock        string
57
        runQuery          string
58
        variables         CLIVariables
59
        fillTemplates     bool
60
        consulOnlyForLock bool
61
        showQueryOutput   bool
62
}
63

64
// NewOptions returns Options.
65
func NewOptions() Options {
×
66
        return Options{variables: make(map[string]string)}
×
67
}
×
68

69
// GetFlagSet returns a ptr to the FlagSet.
70
func (o *Options) GetFlagSet() *flag.FlagSet {
×
71
        var fs = flag.NewFlagSet("Options", flag.ExitOnError)
×
72

×
73
        fs.BoolVar(&(o.help), "help", false, "Shows this message")
×
74
        fs.BoolVar(&(o.version), "version", false, "Shows the program version")
×
75
        fs.StringVar(&(o.playbook), "playbook", "", "Playbook of SQL scripts to execute")
×
76
        fs.StringVar(&(o.sqlroot), "sqlroot", sqlrootPlaybook, fmt.Sprintf("Absolute path to SQL scripts. Use %s, %s and %s for those respective paths", sqlrootPlaybook, sqlrootBinary, sqlrootPlaybookChild))
×
77
        fs.Var(&(o.variables), "var", "Variables to be passed to the playbook, in the key=value format")
×
78
        fs.StringVar(&(o.fromStep), "fromStep", "", "Starts from a given step defined in your playbook")
×
79
        fs.BoolVar(&(o.dryRun), "dryRun", false, "Runs through a playbook without executing any of the SQL")
×
80
        fs.StringVar(&(o.consul), "consul", "", "The address of a consul server with playbooks and SQL files stored in KV pairs")
×
81
        fs.StringVar(&(o.lock), "lock", "", "Optional argument which checks and sets a lockfile to ensure this run is a singleton. Deletes lock on run completing successfully")
×
82
        fs.StringVar(&(o.softLock), "softLock", "", "Optional argument, like '-lock' but the lockfile will be deleted even if the run fails")
×
83
        fs.StringVar(&(o.checkLock), "checkLock", "", "Checks whether the lockfile already exists")
×
84
        fs.StringVar(&(o.deleteLock), "deleteLock", "", "Will attempt to delete a lockfile if it exists")
×
85
        fs.StringVar(&(o.runQuery), "runQuery", "", "Will run a single query in the playbook")
×
86
        fs.BoolVar(&(o.fillTemplates), "fillTemplates", false, "Will print all queries after templates are filled")
×
87
        fs.BoolVar(&(o.consulOnlyForLock), "consulOnlyForLock", false, "Will read playbooks locally, but use Consul for locking.")
×
88
        fs.BoolVar(&(o.showQueryOutput), "showQueryOutput", false, "Will print all output from queries")
×
89
        // TODO: add format flag if/when we support TOML
×
90

×
91
        return fs
×
92
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc