Skip to content

Commit f734c42

Browse files
author
Ben Keil
committed
added option for debug output
1 parent e8374c1 commit f734c42

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

cmd/cmd-build.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ func newBuildCmd(out io.Writer, workdir string) *cobra.Command {
4141
c.version = args[0]
4242
return c.run()
4343
},
44+
PersistentPostRun: func(cmd *cobra.Command, args []string) {
45+
if c.push {
46+
fmt.Fprintf(c.out, "pushing images for version: %s\n", c.version)
47+
}
48+
},
4449
}
4550
cmd.Flags().BoolVarP(&c.push, "push", "", false, "also push the images (experimental)")
4651

cmd/hydra.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package main
22

33
import (
4-
"bytes"
54
"fmt"
65
"os"
76

@@ -15,7 +14,7 @@ var logger = loggo.GetLogger("hydra")
1514
var version string
1615

1716
func init() {
18-
loggo.ConfigureLoggers("<root>=INFO; hydra=ERROR")
17+
loggo.ConfigureLoggers(fmt.Sprintf("<root>=INFO; hydra=%s", "ERROR"))
1918
}
2019

2120
func main() {
@@ -25,33 +24,25 @@ func main() {
2524
}
2625
}
2726

28-
func emptyRun(*cobra.Command, []string) {}
29-
30-
func executeCommand(root *cobra.Command, args ...string) (output string, err error) {
31-
_, output, err = executeCommandC(root, args...)
32-
return output, err
33-
}
34-
35-
func executeCommandC(root *cobra.Command, args ...string) (c *cobra.Command, output string, err error) {
36-
buf := new(bytes.Buffer)
37-
root.SetOutput(buf)
38-
root.SetArgs(args)
39-
40-
c, err = root.ExecuteC()
41-
42-
return c, buf.String(), err
43-
}
44-
4527
func newRootCmd(args []string) *cobra.Command {
4628
var workdir string
29+
var debug bool
4730
cmd := &cobra.Command{
4831
Use: "hydra",
4932
Short: "Hydra builds docker images and add multiple convenient tags",
5033
Version: version,
5134
SilenceUsage: true,
35+
PersistentPreRun: func(cmd *cobra.Command, args []string) {
36+
var logLevel = "ERROR"
37+
if debug {
38+
logLevel = "DEBUG"
39+
}
40+
loggo.ConfigureLoggers(fmt.Sprintf("<root>=INFO; hydra=%s", logLevel))
41+
},
5242
}
5343

5444
cmd.PersistentFlags().StringVarP(&workdir, "workdir", "w", ".", "the root directory of the project you want to build")
45+
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug output")
5546
cmd.PersistentFlags().Parse(args)
5647

5748
out := cmd.OutOrStdout()

cmd/tag-parser.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ func (parser *DefaultTagParser) parseTag(version Version, tag string) []string {
7777
logger.Debugf("Using ReplaceStrategy for tag: %v", tag)
7878
strategy := ReplaceStrategy{tag, parser.version}
7979
parsedTags = append(parsedTags, strategy.GetTags()...)
80+
} else {
81+
// convenient should not be build if we dont have a semver tag
82+
logger.Debugf("Using SkipStrategy for tag: %v", tag)
8083
}
8184
logger.Debugf("Parsed tags: %v\n", parsedTags)
8285
return parsedTags

cmd/validator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
func SemverValidator() cobra.PositionalArgs {
1111
return func(cmd *cobra.Command, args []string) error {
1212
if len(args) == 0 {
13-
return errors.New("the version you want to push is required")
13+
return errors.New("the version you want to build/push is required")
1414
}
1515
/*_, err := semver.Parse(args[0])
1616
if err != nil {

0 commit comments

Comments
 (0)