Skip to content

Commit

Permalink
Merge pull request opencontrol#290 from redhatrises/cli_fixes
Browse files Browse the repository at this point in the history
 Break a part CLI and CLI tests into their respective packages
  • Loading branch information
shawndwells authored Jun 8, 2018
2 parents 3ef42d3 + 2cf623a commit 553bce0
Show file tree
Hide file tree
Showing 308 changed files with 165,259 additions and 5,055 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

- run:
name: Build the program
command: go build cmd/compliance-masonry/compliance-masonry.go cmd/compliance-masonry/diff.go
command: go build cmd/compliance-masonry/compliance-masonry.go
- run:
name: Run tests
command: ./.circleci/coverage.sh
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ build:
$(GO) build \
$(DEBUGFLAGS) \
-o $(BUILD_DIR)/$(PROGNAME) \
./masonry-go.go ./diff.go
cmd/compliance-masonry/compliance-masonry.go

all: build

Expand All @@ -50,7 +50,7 @@ platforms:
output_name="$(BUILD_DIR)/$$GOOS-$$GOARCH/$(PROGNAME)"; \
[ $$GOOS = "windows" ] && output_name="$$output_name.exe"; \
echo "Building $(PROGNAME) version $(VERSION) for $$GOOS on $$GOARCH"; \
GOOS=$$GOOS GOARCH=$$GOARCH $(GO) build -o $$output_name ./masonry-go.go ./diff.go; \
GOOS=$$GOOS GOARCH=$$GOARCH $(GO) build -o $$output_name cmd/compliance-masonry/compliance-masonry.go; \
[ -d $(BUILD_DIR)/$$GOOS-$$GOARCH/ ] && cp {LICENSE.md,README.md} $(BUILD_DIR)/$$GOOS-$$GOARCH/; \
done

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ install:
set PATH=%PATH%;%GOPATH%\bin
build_script:
- cmd: go build cmd/compliance-masonry/compliance-masonry.go cmd/compliance-masonry/diff.go
- cmd: go build cmd/compliance-masonry/compliance-masonry.go
test_script:
- cmd: FOR /F %%A IN ('glide novendor') DO go test -v %%A || exit /b 1
136 changes: 4 additions & 132 deletions cmd/compliance-masonry/compliance-masonry.go
Original file line number Diff line number Diff line change
@@ -1,142 +1,14 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"os"
"path/filepath"

"github.com/codegangsta/cli"
"github.com/opencontrol/compliance-masonry/pkg/cli/docs"
"github.com/opencontrol/compliance-masonry/pkg/cli/docs/gitbook"
"github.com/opencontrol/compliance-masonry/pkg/cli/get"
"github.com/opencontrol/compliance-masonry/tools/constants"
"github.com/opencontrol/compliance-masonry/tools/fs"
"github.com/opencontrol/compliance-masonry/version"
"github.com/opencontrol/compliance-masonry/pkg/cmd/masonry"
)

var exportPath, markdownPath, opencontrolDir string

// NewCLIApp creates a new instances of the CLI
func NewCLIApp() *cli.App {
app := cli.NewApp()
app.Name = "Compliance Masonry"
app.Usage = "Open Control CLI Tool"
app.Version = version.Version
app.Flags = []cli.Flag{
cli.BoolFlag{
Name: "verbose",
Usage: "Indicates whether to run the command with verbosity.",
},
}
app.Before = func(c *cli.Context) error {
// Resets the log to output to nothing
log.SetOutput(ioutil.Discard)
if c.Bool("verbose") {
log.SetOutput(os.Stderr)
log.Println("Running with verbosity")
}
return nil
}
app.Commands = []cli.Command{
{
Name: "get",
Aliases: []string{"g"},
Usage: "Install compliance dependencies",
Flags: []cli.Flag{
cli.StringFlag{
Name: "dest",
Value: constants.DefaultDestination,
Usage: "Location to download the repos.",
},
cli.StringFlag{
Name: "config",
Value: constants.DefaultConfigYaml,
Usage: "Location of system yaml",
},
},
Action: func(c *cli.Context) error {
f := fs.OSUtil{}
config := c.String("config")
configBytes, err := f.OpenAndReadFile(config)
if err != nil {
fmt.Fprintf(app.Writer, "%v\n", err.Error())
os.Exit(1)
}
wd, err := os.Getwd()
if err != nil {
fmt.Fprintf(app.Writer, "%v\n", err.Error())
os.Exit(1)
}
destination := filepath.Join(wd, c.String("dest"))
err = get.Get(destination, configBytes)
if err != nil {
return cli.NewExitError(err.Error(), 1)
}
fmt.Fprintf(app.Writer, "%v\n", "Compliance Dependencies Installed")
return nil
},
},
{
Name: "docs",
Aliases: []string{"d"},
Usage: "Create Documentation",
Subcommands: []cli.Command{
{
Name: "gitbook",
Aliases: []string{"g"},
Usage: "Create Gitbook Documentation",
Flags: []cli.Flag{
cli.StringFlag{
Name: "opencontrols, o",
Value: "opencontrols",
Usage: "Set opencontrols directory",
Destination: &opencontrolDir,
},
cli.StringFlag{
Name: "exports, e",
Value: "exports",
Usage: "Sets the export directory",
Destination: &exportPath,
},
cli.StringFlag{
Name: "markdowns, m",
Value: "markdowns",
Usage: "Sets the markdowns directory",
Destination: &markdownPath,
},
},
Action: func(c *cli.Context) error {
config := gitbook.Config{
Certification: c.Args().First(),
OpencontrolDir: opencontrolDir,
ExportPath: exportPath,
MarkdownPath: markdownPath,
}
warning, errMessages := docs.MakeGitbook(config)
if warning != "" {
fmt.Fprintf(app.Writer, "%v\n", warning)
}
if errMessages != nil && len(errMessages) > 0 {
err := cli.NewMultiError(errMessages...)
return cli.NewExitError(err.Error(), 1)
}
fmt.Fprintf(app.Writer, "%v\n", "New Gitbook Documentation Created")
return nil
},
},
},
},
diffCommand,
}
return app
}

func main() {
app := NewCLIApp()
err := app.Run(os.Args)
if err != nil {
log.Fatalln(err)
if err := masonry.Run(); err != nil {
os.Exit(1)
}
os.Exit(0)
}
33 changes: 33 additions & 0 deletions cmd/compliance-masonry/compliance-masonry_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package main_test

import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"github.com/opencontrol/compliance-masonry/pkg/tests"
)

var usage = `
Usage:
compliance-masonry [flags]
compliance-masonry [command]
Available Commands:
diff Compliance Diff Gap Analysis
docs Create compliance documentation
get Install compliance dependencies
help Help about any command
Flags:
-h, --help help for compliance-masonry
--verbose Run with verbosity
-v, --version Print the version
`

var _ = Describe("Masonry CLI", func() {
Describe("When the CLI is run with no commands", func() {
It("should list the available commands", func() {
output := masonry_test.Masonry()
Eventually(output.Out.Contents).Should(ContainSubstring(usage))
})
})
})
123 changes: 0 additions & 123 deletions cmd/compliance-masonry/compliance_masonry_test.go

This file was deleted.

48 changes: 0 additions & 48 deletions cmd/compliance-masonry/diff.go

This file was deleted.

Loading

0 comments on commit 553bce0

Please sign in to comment.