1
0
mirror of https://github.com/strongdm/comply synced 2024-12-23 14:07:34 +00:00

replace dockerMustExist with pandocMustExist dependency on build and serve commands

This commit is contained in:
Justin McCarthy 2018-05-23 14:15:39 -07:00
parent 1b807da10e
commit bb4200ff43
No known key found for this signature in database
GPG Key ID: 900437410E142A48
3 changed files with 53 additions and 2 deletions

View File

@ -7,7 +7,10 @@ import (
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"time"
@ -96,6 +99,54 @@ func ticketingMustBeConfigured(c *cli.Context) error {
return nil
}
func pandocMustExist(c *cli.Context) error {
pandocErr := fmt.Errorf("Please install either Docker or the pandoc package and re-run `%s`", c.Command.Name)
err := pandocBinaryMustExist(c)
fmt.Println(err)
if err != nil {
err = dockerMustExist(c)
if err != nil {
return pandocErr
}
}
return nil
}
func pandocBinaryMustExist(c *cli.Context) error {
cmd := exec.Command("pandoc", "-v")
outputRaw, err := cmd.Output()
if err != nil {
return errors.Wrap(err, "error calling pandoc")
}
output := strings.TrimSpace((string(outputRaw)))
versionErr := errors.New("cannot determine pandoc version")
if !strings.HasPrefix(output, "pandoc") {
return versionErr
}
re := regexp.MustCompile(`pandoc (\d+)\.(\d+)`)
result := re.FindStringSubmatch(output)
if len(result) != 3 {
return versionErr
}
major, err := strconv.Atoi(result[1])
if err != nil {
return versionErr
}
minor, err := strconv.Atoi(result[2])
if err != nil {
return versionErr
}
if major < 2 || minor < 1 {
return errors.New("pandoc 2.1 or greater required")
}
return nil
}
func dockerMustExist(c *cli.Context) error {
dockerErr := fmt.Errorf("Docker must be available in order to run `%s`", c.Command.Name)

View File

@ -11,7 +11,7 @@ var buildCommand = cli.Command{
ShortName: "b",
Usage: "generate a static website summarizing the compliance program",
Action: buildAction,
Before: beforeAll(dockerMustExist, cleanContainers),
Before: beforeAll(pandocMustExist, cleanContainers),
}
func buildAction(c *cli.Context) error {

View File

@ -10,7 +10,7 @@ var serveCommand = cli.Command{
Name: "serve",
Usage: "live updating version of the build command",
Action: serveAction,
Before: beforeAll(dockerMustExist, cleanContainers),
Before: beforeAll(pandocMustExist, cleanContainers),
}
func serveAction(c *cli.Context) error {