docs: update hrp cmd docs

This commit is contained in:
lilong.129
2025-04-24 22:31:03 +08:00
parent 9473345ec9
commit 03c0d6ee42
47 changed files with 587 additions and 117 deletions

View File

@@ -57,5 +57,5 @@ func getAndroidDevices() (devices []*gadb.Device, err error) {
}
func init() {
androidRootCmd.AddCommand(listAndroidDevicesCmd)
CmdAndroidRoot.AddCommand(listAndroidDevicesCmd)
}

View File

@@ -9,7 +9,7 @@ import (
var serial string
var androidRootCmd = &cobra.Command{
var CmdAndroidRoot = &cobra.Command{
Use: "adb",
Short: "simple utils for android device management",
PersistentPreRun: func(cmd *cobra.Command, args []string) {},
@@ -22,7 +22,3 @@ func getDevice(serial string) (*uixt.AndroidDevice, error) {
}
return device, nil
}
func Init(rootCmd *cobra.Command) {
rootCmd.AddCommand(androidRootCmd)
}

View File

@@ -66,5 +66,5 @@ func init() {
installCmd.Flags().BoolVarP(&replace, "replace", "r", false, "replace existing application")
installCmd.Flags().BoolVarP(&downgrade, "downgrade", "d", false, "allow version code downgrade (debuggable packages only)")
installCmd.Flags().BoolVarP(&grant, "grant", "g", false, "grant all runtime permissions")
androidRootCmd.AddCommand(installCmd)
CmdAndroidRoot.AddCommand(installCmd)
}

View File

@@ -46,5 +46,5 @@ var screencapAndroidDevicesCmd = &cobra.Command{
func init() {
screencapAndroidDevicesCmd.Flags().StringVarP(&serial, "serial", "s", "", "filter by device's serial")
androidRootCmd.AddCommand(screencapAndroidDevicesCmd)
CmdAndroidRoot.AddCommand(screencapAndroidDevicesCmd)
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/httprunner/httprunner/v5/internal/sdk"
)
var buildCmd = &cobra.Command{
var CmdBuild = &cobra.Command{
Use: "build $path ...",
Short: "build plugin for testing",
Long: `build python/go plugin for testing`,
@@ -33,7 +33,5 @@ var buildCmd = &cobra.Command{
var output string
func init() {
rootCmd.AddCommand(buildCmd)
buildCmd.Flags().StringVarP(&output, "output", "o", "", "funplugin product output path, default: cwd")
CmdBuild.Flags().StringVarP(&output, "output", "o", "", "funplugin product output path, default: cwd")
}

View File

@@ -1,14 +1,16 @@
package cmd
package main
import (
"testing"
"github.com/httprunner/httprunner/v5/cmd"
"github.com/spf13/cobra/doc"
"github.com/stretchr/testify/assert"
)
// run this test to generate markdown docs for hrp command
func TestGenMarkdownTree(t *testing.T) {
err := doc.GenMarkdownTree(rootCmd, "../../docs/cmd")
addAllCommands()
err := doc.GenMarkdownTree(cmd.RootCmd, "../../docs/cmd")
assert.Nil(t, err)
}

View File

@@ -7,8 +7,25 @@ import (
"github.com/getsentry/sentry-go"
"github.com/httprunner/httprunner/v5/cmd"
"github.com/httprunner/httprunner/v5/cmd/adb"
"github.com/httprunner/httprunner/v5/cmd/ios"
"github.com/httprunner/httprunner/v5/code"
)
func addAllCommands() {
// adds all child commands to the root command and sets flags appropriately.
cmd.RootCmd.AddCommand(cmd.CmdBuild)
cmd.RootCmd.AddCommand(cmd.CmdConvert)
cmd.RootCmd.AddCommand(cmd.CmdPytest)
cmd.RootCmd.AddCommand(cmd.CmdRun)
cmd.RootCmd.AddCommand(cmd.CmdScaffold)
cmd.RootCmd.AddCommand(cmd.CmdServer)
cmd.RootCmd.AddCommand(cmd.CmdWiki)
cmd.RootCmd.AddCommand(ios.CmdIOSRoot)
cmd.RootCmd.AddCommand(adb.CmdAndroidRoot)
}
func main() {
defer func() {
if err := recover(); err != nil {
@@ -21,6 +38,9 @@ func main() {
}
}()
exitCode := cmd.Execute()
addAllCommands()
err := cmd.RootCmd.Execute()
exitCode := code.GetErrorCode(err)
os.Exit(exitCode)
}

View File

@@ -14,7 +14,7 @@ import (
"github.com/httprunner/httprunner/v5/internal/builtin"
)
var convertCmd = &cobra.Command{
var CmdConvert = &cobra.Command{
Use: "convert $path...",
Short: "convert multiple source format to HttpRunner JSON/YAML/gotest/pytest cases",
Args: cobra.MinimumNArgs(1),
@@ -105,18 +105,16 @@ var (
)
func init() {
rootCmd.AddCommand(convertCmd)
CmdConvert.Flags().BoolVar(&fromJSONFlag, "from-json", true, "load from json case format")
CmdConvert.Flags().BoolVar(&fromYAMLFlag, "from-yaml", false, "load from yaml case format")
CmdConvert.Flags().BoolVar(&fromHARFlag, "from-har", false, "load from HAR format")
CmdConvert.Flags().BoolVar(&fromPostmanFlag, "from-postman", false, "load from postman format")
CmdConvert.Flags().BoolVar(&fromCurlFlag, "from-curl", false, "load from curl format")
convertCmd.Flags().BoolVar(&fromJSONFlag, "from-json", true, "load from json case format")
convertCmd.Flags().BoolVar(&fromYAMLFlag, "from-yaml", false, "load from yaml case format")
convertCmd.Flags().BoolVar(&fromHARFlag, "from-har", false, "load from HAR format")
convertCmd.Flags().BoolVar(&fromPostmanFlag, "from-postman", false, "load from postman format")
convertCmd.Flags().BoolVar(&fromCurlFlag, "from-curl", false, "load from curl format")
CmdConvert.Flags().BoolVar(&toJSONFlag, "to-json", true, "convert to JSON case scripts")
CmdConvert.Flags().BoolVar(&toYAMLFlag, "to-yaml", false, "convert to YAML case scripts")
CmdConvert.Flags().BoolVar(&toPyTestFlag, "to-pytest", false, "convert to pytest scripts")
convertCmd.Flags().BoolVar(&toJSONFlag, "to-json", true, "convert to JSON case scripts")
convertCmd.Flags().BoolVar(&toYAMLFlag, "to-yaml", false, "convert to YAML case scripts")
convertCmd.Flags().BoolVar(&toPyTestFlag, "to-pytest", false, "convert to pytest scripts")
convertCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory")
convertCmd.Flags().StringVarP(&profilePath, "profile", "p", "", "specify profile path to override headers and cookies")
CmdConvert.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory")
CmdConvert.Flags().StringVarP(&profilePath, "profile", "p", "", "specify profile path to override headers and cookies")
}

View File

@@ -71,5 +71,5 @@ var appType string
func init() {
listAppsCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
listAppsCmd.Flags().StringVarP(&appType, "type", "t", "user", "filter application type [user|system|internal|all]")
iosRootCmd.AddCommand(listAppsCmd)
CmdIOSRoot.AddCommand(listAppsCmd)
}

View File

@@ -74,5 +74,5 @@ var listDevicesCmd = &cobra.Command{
var udid string
func init() {
iosRootCmd.AddCommand(listDevicesCmd)
CmdIOSRoot.AddCommand(listDevicesCmd)
}

View File

@@ -7,7 +7,7 @@ import (
"github.com/httprunner/httprunner/v5/uixt/option"
)
var iosRootCmd = &cobra.Command{
var CmdIOSRoot = &cobra.Command{
Use: "ios",
Short: "simple utils for ios device management",
}
@@ -19,7 +19,3 @@ func getDevice(udid string) (*uixt.IOSDevice, error) {
}
return device, nil
}
func Init(rootCmd *cobra.Command) {
rootCmd.AddCommand(iosRootCmd)
}

View File

@@ -49,5 +49,5 @@ var installCmd = &cobra.Command{
func init() {
installCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's serial")
iosRootCmd.AddCommand(installCmd)
CmdIOSRoot.AddCommand(installCmd)
}

View File

@@ -79,5 +79,5 @@ func init() {
mountCmd.Flags().BoolVar(&unmountDeveloperDiskImage, "reset", false, "unmount developer disk images")
mountCmd.Flags().StringVarP(&developerDiskImageDir, "dir", "d", defaultDeveloperDiskImageDir, "specify developer disk image directory")
mountCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
iosRootCmd.AddCommand(mountCmd)
CmdIOSRoot.AddCommand(mountCmd)
}

View File

@@ -46,5 +46,5 @@ var isAll bool
func init() {
psCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
psCmd.Flags().BoolVarP(&isAll, "all", "a", false, "print all processes including system processes")
iosRootCmd.AddCommand(psCmd)
CmdIOSRoot.AddCommand(psCmd)
}

View File

@@ -40,5 +40,5 @@ var rebootCmd = &cobra.Command{
func init() {
rebootCmd.Flags().StringVarP(&udid, "udid", "u", "", "specify device by udid")
iosRootCmd.AddCommand(rebootCmd)
CmdIOSRoot.AddCommand(rebootCmd)
}

View File

@@ -36,5 +36,5 @@ var tunnelCmd = &cobra.Command{
}
func init() {
iosRootCmd.AddCommand(tunnelCmd)
CmdIOSRoot.AddCommand(tunnelCmd)
}

View File

@@ -56,5 +56,5 @@ func init() {
uninstallCmd.Flags().StringVarP(&udid, "udid", "u", "", "filter by device's serial")
uninstallCmd.Flags().StringVarP(&bundleId, "bundleId", "b", "", "bundleId to uninstall")
iosRootCmd.AddCommand(uninstallCmd)
CmdIOSRoot.AddCommand(uninstallCmd)
}

View File

@@ -52,5 +52,5 @@ func init() {
xctestCmd.Flags().StringVarP(&bundleID, "bundleID", "b", "com.gtf.wda.runner.xctrunner", "specify ios bundleID")
xctestCmd.Flags().StringVarP(&testRunnerBundleID, "testRunnerBundleID", "t", "com.gtf.wda.runner.xctrunner", "specify ios testRunnerBundleID")
xctestCmd.Flags().StringVarP(&xctestConfig, "xctestConfig", "x", "GtfWdaRunner.xctest", "specify ios xctestConfig")
iosRootCmd.AddCommand(xctestCmd)
CmdIOSRoot.AddCommand(xctestCmd)
}

View File

@@ -13,7 +13,7 @@ import (
"github.com/httprunner/httprunner/v5/internal/sdk"
)
var pytestCmd = &cobra.Command{
var CmdPytest = &cobra.Command{
Use: "pytest $path ...",
Short: "run API test with pytest",
Args: cobra.MinimumNArgs(1),
@@ -38,10 +38,6 @@ var pytestCmd = &cobra.Command{
},
}
func init() {
rootCmd.AddCommand(pytestCmd)
}
func runPytest(args []string) error {
args = append([]string{"run"}, args...)
return myexec.ExecPython3Command("httprunner", args...)

View File

@@ -4,14 +4,11 @@ import (
"github.com/spf13/cobra"
hrp "github.com/httprunner/httprunner/v5"
"github.com/httprunner/httprunner/v5/cmd/adb"
"github.com/httprunner/httprunner/v5/cmd/ios"
"github.com/httprunner/httprunner/v5/code"
"github.com/httprunner/httprunner/v5/internal/version"
)
// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
var RootCmd = &cobra.Command{
Use: "hrp",
Short: "All-in-One Testing Framework for API, UI and Performance",
Long: `
@@ -62,16 +59,8 @@ var (
venv string
)
// Execute adds all child commands to the root command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the rootCmd.
func Execute() int {
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format (default colorized console)")
rootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
ios.Init(rootCmd)
adb.Init(rootCmd)
err := rootCmd.Execute()
return code.GetErrorCode(err)
func init() {
RootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format (default colorized console)")
RootCmd.PersistentFlags().StringVar(&venv, "venv", "", "specify python3 venv path")
}

View File

@@ -7,7 +7,7 @@ import (
)
// runCmd represents the run command
var runCmd = &cobra.Command{
var CmdRun = &cobra.Command{
Use: "run $path...",
Short: "run API test with go engine",
Long: `run yaml/json testcase files for API test`,
@@ -38,15 +38,14 @@ var (
)
func init() {
rootCmd.AddCommand(runCmd)
runCmd.Flags().BoolVarP(&continueOnFailure, "continue-on-failure", "c", false, "continue running next step when failure occurs")
runCmd.Flags().BoolVar(&requestsLogOff, "log-requests-off", false, "turn off request & response details logging")
runCmd.Flags().BoolVar(&httpStatOn, "http-stat", false, "turn on HTTP latency stat (DNSLookup, TCP Connection, etc.)")
runCmd.Flags().BoolVar(&pluginLogOn, "log-plugin", false, "turn on plugin logging")
runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url")
runCmd.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary")
runCmd.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report")
runCmd.Flags().Float32Var(&caseTimeout, "case-timeout", 3600, "set testcase timeout (seconds)")
CmdRun.Flags().BoolVarP(&continueOnFailure, "continue-on-failure", "c", false, "continue running next step when failure occurs")
CmdRun.Flags().BoolVar(&requestsLogOff, "log-requests-off", false, "turn off request & response details logging")
CmdRun.Flags().BoolVar(&httpStatOn, "http-stat", false, "turn on HTTP latency stat (DNSLookup, TCP Connection, etc.)")
CmdRun.Flags().BoolVar(&pluginLogOn, "log-plugin", false, "turn on plugin logging")
CmdRun.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url")
CmdRun.Flags().BoolVarP(&saveTests, "save-tests", "s", false, "save tests summary")
CmdRun.Flags().BoolVarP(&genHTMLReport, "gen-html-report", "g", false, "generate html report")
CmdRun.Flags().Float32Var(&caseTimeout, "case-timeout", 3600, "set testcase timeout (seconds)")
}
func makeHRPRunner() *hrp.HRPRunner {

View File

@@ -9,7 +9,7 @@ import (
"github.com/httprunner/httprunner/v5/internal/scaffold"
)
var scaffoldCmd = &cobra.Command{
var CmdScaffold = &cobra.Command{
Use: "startproject $project_name",
Aliases: []string{"scaffold"},
Short: "create a scaffold project",
@@ -49,10 +49,9 @@ var (
)
func init() {
rootCmd.AddCommand(scaffoldCmd)
scaffoldCmd.Flags().BoolVarP(&force, "force", "f", false, "force to overwrite existing project")
scaffoldCmd.Flags().BoolVar(&genPythonPlugin, "py", true, "generate hashicorp python plugin")
scaffoldCmd.Flags().BoolVar(&genGoPlugin, "go", false, "generate hashicorp go plugin")
scaffoldCmd.Flags().BoolVar(&ignorePlugin, "ignore-plugin", false, "ignore function plugin")
scaffoldCmd.Flags().BoolVar(&empty, "empty", false, "generate empty project")
CmdScaffold.Flags().BoolVarP(&force, "force", "f", false, "force to overwrite existing project")
CmdScaffold.Flags().BoolVar(&genPythonPlugin, "py", true, "generate hashicorp python plugin")
CmdScaffold.Flags().BoolVar(&genGoPlugin, "go", false, "generate hashicorp go plugin")
CmdScaffold.Flags().BoolVar(&ignorePlugin, "ignore-plugin", false, "ignore function plugin")
CmdScaffold.Flags().BoolVar(&empty, "empty", false, "generate empty project")
}

View File

@@ -8,7 +8,7 @@ import (
)
// serverCmd represents the server command
var serverCmd = &cobra.Command{
var CmdServer = &cobra.Command{
Use: "server start",
Short: "start hrp server",
Long: `start hrp server, call httprunner by HTTP`,
@@ -29,7 +29,6 @@ var (
)
func init() {
rootCmd.AddCommand(serverCmd)
serverCmd.Flags().IntVarP(&port, "port", "p", 8082, "port to run the server on")
serverCmd.Flags().StringVarP(&mcpConfigPath, "mcp-config", "c", "$HOME/.hrp/mcp.json", "path to the MCP config file")
CmdServer.Flags().IntVarP(&port, "port", "p", 8082, "port to run the server on")
CmdServer.Flags().StringVarP(&mcpConfigPath, "mcp-config", "c", "$HOME/.hrp/mcp.json", "path to the MCP config file")
}

View File

@@ -10,7 +10,7 @@ import (
"github.com/httprunner/httprunner/v5/internal/wiki"
)
var wikiCmd = &cobra.Command{
var CmdWiki = &cobra.Command{
Use: "wiki",
Aliases: []string{"info", "docs", "doc"},
Short: "visit https://httprunner.com",
@@ -26,7 +26,3 @@ var wikiCmd = &cobra.Command{
return wiki.OpenWiki()
},
}
func init() {
rootCmd.AddCommand(wikiCmd)
}