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

add:one click install example #1053

Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions cmd/examples.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
"go.uber.org/zap"
)
Expand All @@ -24,6 +26,9 @@ var customHelpTemplate = `
Use "{{.CommandPath}} [command] --help" for more information about a command.
`

var withoutexampleOneClickInstall = `
Note: If installed keploy without One Click Install, use "keploy example --customSetup true"
`
var examples = `
Golang Application
Record:
Expand Down Expand Up @@ -58,16 +63,63 @@ Docker
keploy test -c "docker run -p 8080:8080 --name myContainerName --network myNetworkName myApplicationImage" --delay 1
`

var exampleOneClickInstall = `
Golang Application
Record:
keploy record -c "/path/to/user/app/binary"

Test:
keploy test -c "/path/to/user/app/binary" --delay 2

Node Application
Record:
keploy record -c “npm start --prefix /path/to/node/app"

Test:
keploy test -c “npm start --prefix /path/to/node/app" --delay 2

Java
Record:
keploy record -c "java -jar /path/to/java-project/target/jar"

Test:
keploy test -c "java -jar /path/to/java-project/target/jar" --delay 2

Docker
Record:
keploy record -c "docker run -p 8080:8080 --name myContainerName --network myNetworkName myApplicationImage"

Test:
keploy test -c "docker run -p 8080:8080 --name myContainerName --network myNetworkName myApplicationImage" --delay 1
`

type Example struct {
logger *zap.Logger
}

func (e *Example) GetCmd() *cobra.Command {
var customSetup bool
var exampleCmd = &cobra.Command{
Use: "example",
Short: "Example to record and test via keploy",
Example: examples,
Use: "example",
Short: "Example to record and test via keploy",
RunE: func(cmd *cobra.Command, args []string) error {
customSetup, err := cmd.Flags().GetBool("customSetup")
if err != nil {
e.logger.Error("failed to read the customSetup flag")
return err
}
if customSetup {
fmt.Println(examples)
} else {
fmt.Println(exampleOneClickInstall)
fmt.Println(withoutexampleOneClickInstall)
}
return nil
},
}
exampleCmd.SetHelpTemplate(customHelpTemplate)

exampleCmd.Flags().Bool("customSetup", customSetup, "Check if the user is using one click install")

return exampleCmd
}
2 changes: 1 addition & 1 deletion keploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,5 @@ installKeploy (){
installKeploy

if command -v keploy &> /dev/null; then
keploy example
keploy example --isOneClickInstall true
fi
Loading