forked from opencontrol/compliance-masonry
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request opencontrol#290 from redhatrises/cli_fixes
Break a part CLI and CLI tests into their respective packages
- Loading branch information
Showing
308 changed files
with
165,259 additions
and
5,055 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
}) | ||
}) | ||
}) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.