Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Break a part CLI and CLI tests into their respective packages #290

Merged
merged 5 commits into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
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