Skip to content

Commit

Permalink
Improve command logging (elastic#79)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtojek authored Aug 31, 2020
1 parent 5f815c0 commit 66b92d5
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
4 changes: 4 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ func setupBuildCommand() *cobra.Command {
}

func buildCommandAction(cmd *cobra.Command, args []string) error {
cmd.Println("Build the package")

err := builder.BuildPackage()
if err != nil {
return errors.Wrap(err, "building package failed")
}

cmd.Println("Done")
return nil
}
4 changes: 4 additions & 0 deletions cmd/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func setupFormatCommand() *cobra.Command {
}

func formatCommandAction(cmd *cobra.Command, args []string) error {
cmd.Println("Format the package")

packageRoot, found, err := packages.FindPackageRoot()
if err != nil {
return errors.Wrap(err, "locating package root failed")
Expand All @@ -42,5 +44,7 @@ func formatCommandAction(cmd *cobra.Command, args []string) error {
if err != nil {
return errors.Wrapf(err, "formatting the integration failed (path: %s, failFast: %t)", packageRoot, ff)
}

cmd.Println("Done")
return nil
}
10 changes: 9 additions & 1 deletion cmd/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ func setupLintCommand() *cobra.Command {
}

func lintCommandAction(cmd *cobra.Command, args []string) error {
cmd.Println("Lint the package")

packageRootPath, found, err := packages.FindPackageRoot()
if !found {
return errors.New("package root not found")
Expand All @@ -31,5 +33,11 @@ func lintCommandAction(cmd *cobra.Command, args []string) error {
return errors.Wrap(err, "locating package root failed")
}

return validator.ValidateFromPath(packageRootPath)
err = validator.ValidateFromPath(packageRootPath)
if err != nil {
return errors.Wrap(err, "linting package failed")
}

cmd.Println("Done")
return nil
}
4 changes: 4 additions & 0 deletions cmd/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func setupPromoteCommand() *cobra.Command {
}

func promoteCommandAction(cmd *cobra.Command, args []string) error {
cmd.Println("Promote packages")

// Setup GitHub
err := github.EnsureAuthConfigured()
if err != nil {
Expand Down Expand Up @@ -113,6 +115,8 @@ func promoteCommandAction(cmd *cobra.Command, args []string) error {
return errors.Wrapf(err, "opening PR with removed packages failed (head: %s, base: %s)", newDestinationStage, destinationStage)
}
cmd.Println("Pull request with removed packages:", url)

cmd.Println("Done")
return nil
}

Expand Down
24 changes: 18 additions & 6 deletions cmd/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ var availableServices = map[string]struct{}{
func setupStackCommand() *cobra.Command {
upCommand := &cobra.Command{
Use: "up",
Short: "Boot up the testing stack",
Short: "Boot up the stack",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println("Boot up the Elastic stack")

daemonMode, err := cmd.Flags().GetBool(cobraext.DaemonModeFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.DaemonModeFlagName)
Expand Down Expand Up @@ -54,6 +56,8 @@ func setupStackCommand() *cobra.Command {
if err != nil {
return errors.Wrap(err, "booting up the stack failed")
}

cmd.Println("Done")
return nil
},
}
Expand All @@ -64,20 +68,26 @@ func setupStackCommand() *cobra.Command {

downCommand := &cobra.Command{
Use: "down",
Short: "Take down the testing stack",
Short: "Take down the stack",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println("Take down the Elastic stack")

err := stack.TearDown()
if err != nil {
return errors.Wrap(err, "tearing down the stack failed")
}

cmd.Println("Done")
return nil
},
}

updateCommand := &cobra.Command{
Use: "update",
Short: "Updates the stack to the most recent versions.",
Short: "Update the stack to the most recent versions",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println("Update the Elastic stack")

stackVersion, err := cmd.Flags().GetString(cobraext.StackVersionFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.StackVersionFlagName)
Expand All @@ -89,14 +99,16 @@ func setupStackCommand() *cobra.Command {
if err != nil {
return errors.Wrap(err, "failed updating the stack images")
}

cmd.Println("Done")
return nil
},
}
updateCommand.Flags().StringP(cobraext.StackVersionFlagName, "", stack.DefaultVersion, cobraext.StackVersionDescription)

shellInitCommand := &cobra.Command{
Use: "shellinit",
Short: "Initiate environment variables",
Short: "Export environment variables",
RunE: func(cmd *cobra.Command, args []string) error {
shell, err := stack.ShellInit()
if err != nil {
Expand All @@ -109,8 +121,8 @@ func setupStackCommand() *cobra.Command {

cmd := &cobra.Command{
Use: "stack",
Short: "Manage the testing environment",
Long: "Use stack command to boot up and take down the local testing stack.",
Short: "Manage the Elastic stack",
Long: "Use stack command to boot up and take down the local Elastic stack.",
}
cmd.AddCommand(
upCommand,
Expand Down
9 changes: 8 additions & 1 deletion cmd/testrunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ func setupTestCommand() *cobra.Command {
Short: "Run test suite for the package",
Long: "Use test runners to verify if the package collects logs and metrics properly.",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.Println("Run test suite for the package")

if len(args) > 0 {
return fmt.Errorf("unsupported test type: %s", args[0])
}

return cobraext.ComposeCommandActions(cmd, args, testTypeCmdActions...)
}}

Expand All @@ -42,7 +45,7 @@ func setupTestCommand() *cobra.Command {
testTypeCmd := &cobra.Command{
Use: string(testType),
Short: fmt.Sprintf("Run %s tests", testType),
Long: fmt.Sprintf("Run %s tests for a package", testType),
Long: fmt.Sprintf("Run %s tests for the package", testType),
RunE: action,
}

Expand All @@ -54,6 +57,8 @@ func setupTestCommand() *cobra.Command {

func testTypeCommandActionFactory(testType testrunner.TestType) cobraext.CommandAction {
return func(cmd *cobra.Command, args []string) error {
cmd.Printf("Run %s tests for the package\n", testType)

failOnMissing, err := cmd.Flags().GetBool(cobraext.FailOnMissingFlagName)
if err != nil {
return cobraext.FlagParsingError(err, cobraext.FailOnMissingFlagName)
Expand Down Expand Up @@ -97,6 +102,8 @@ func testTypeCommandActionFactory(testType testrunner.TestType) cobraext.Command
return errors.Wrapf(err, "error running package %s tests", testType)
}
}

cmd.Println("Done")
return nil
}
}
3 changes: 0 additions & 3 deletions internal/builder/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package builder

import (
"fmt"
"os"
"path/filepath"

Expand Down Expand Up @@ -57,8 +56,6 @@ func FindBuildPackagesDirectory() (string, bool, error) {
}

func buildPackage(sourcePath string) error {
fmt.Printf("Building package: %s\n", sourcePath)

buildDir, found, err := FindBuildPackagesDirectory()
if err != nil {
return errors.Wrap(err, "locating build directory failed")
Expand Down

0 comments on commit 66b92d5

Please sign in to comment.