Skip to content

Commit

Permalink
refactor(*): add enforcer package (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrynhard authored Jul 23, 2017
1 parent 26ff570 commit 19e4656
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 72 deletions.
6 changes: 3 additions & 3 deletions cmd/enforce.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"fmt"

"github.com/Masterminds/semver"
conform "github.com/autonomy/conform/pkg"
"github.com/autonomy/conform/pkg/enforcer"
"github.com/docker/docker/client"
"github.com/spf13/cobra"
)
Expand All @@ -37,11 +37,11 @@ var enforceCmd = &cobra.Command{
if err := checkDockerVersion(); err != nil {
return err
}
c, err := conform.New()
e, err := enforcer.New()
if err != nil {
return err
}
if err = c.Enforce(); err != nil {
if err = e.Enforce(); err != nil {
return err
}

Expand Down
64 changes: 61 additions & 3 deletions cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,52 @@
package cmd

import (
"github.com/autonomy/conform/pkg/version"
"bytes"
"fmt"
"html/template"
"runtime"

"github.com/spf13/cobra"
)

var (
shortVersion bool
// Tag is set at build time.
Tag string
// SHA is set at build time.
SHA string
// Built is set at build time.
Built string
)

const versionTemplate = `Devise:
Tag: {{ .Tag }}
SHA: {{ .SHA }}
Built: {{ .Built }}
Go version: {{ .GoVersion }}
OS/Arch: {{ .Os }}/{{ .Arch }}
`

// Version contains verbose version information.
type Version struct {
Tag string
SHA string
Built string
GoVersion string
Os string
Arch string
}

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Prints the version",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
if shortVersion {
version.PrintShortVersion()
PrintShortVersion()
} else {
version.PrintLongVersion()
PrintLongVersion()
}
},
}
Expand All @@ -40,3 +68,33 @@ func init() {
versionCmd.Flags().BoolVar(&shortVersion, "short", false, "Print the short version")
RootCmd.AddCommand(versionCmd)
}

// PrintLongVersion prints verbose version information.
func PrintLongVersion() {
v := Version{
Tag: Tag,
SHA: SHA,
GoVersion: runtime.Version(),
Os: runtime.GOOS,
Arch: runtime.GOARCH,
Built: Built,
}

var wr bytes.Buffer
tmpl, err := template.New("version").Parse(versionTemplate)
if err != nil {
fmt.Println(err)
}

err = tmpl.Execute(&wr, v)
if err != nil {
fmt.Println(err)
}

fmt.Println(wr.String())
}

// PrintShortVersion prints the tag and sha.
func PrintShortVersion() {
fmt.Println(fmt.Sprintf("Devise %s-%s", Tag, SHA))
}
2 changes: 1 addition & 1 deletion pkg/conform.go → pkg/enforcer/enforcer.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package conform
package enforcer

import (
"fmt"
Expand Down
65 changes: 0 additions & 65 deletions pkg/version/version.go

This file was deleted.

0 comments on commit 19e4656

Please sign in to comment.