mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-11 18:11:21 +08:00
refactor: commands
This commit is contained in:
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -27,7 +27,7 @@ jobs:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
goos: ${{ matrix.goos }}
|
||||
goarch: ${{ matrix.goarch }}
|
||||
project_path: "./hrp" # go build ./hrp/main.go
|
||||
project_path: "./cli/hrp" # go build ./cli/hrp/main.go
|
||||
binary_name: "hrp"
|
||||
ldflags: "-s -w"
|
||||
extra_files: LICENSE README.md docs/CHANGELOG.md
|
||||
|
||||
2
Makefile
2
Makefile
@@ -11,7 +11,7 @@ test: ## run unit tests
|
||||
.PHONY: build
|
||||
build: ## build hrp cli tool
|
||||
@echo "[info] build hrp cli tool"
|
||||
@. hrp/scripts/build.sh
|
||||
@. cli/scripts/build.sh
|
||||
|
||||
.PHONY: help
|
||||
help: ## print make commands
|
||||
|
||||
@@ -29,13 +29,13 @@ See [CHANGELOG].
|
||||
You can install `hrp` with one shell command, which will download the latest version's released binary and install to the current system.
|
||||
|
||||
```bash
|
||||
$ curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/hrp/scripts/install.sh | bash
|
||||
$ curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/cli/scripts/install.sh | bash
|
||||
```
|
||||
|
||||
If you are a golang developer, you can also install `hrp` with `go get`.
|
||||
|
||||
```bash
|
||||
$ go get -u github.com/httprunner/hrp/hrp
|
||||
$ go get -u github.com/httprunner/hrp/cli/hrp
|
||||
```
|
||||
|
||||
Since installed, you will get a `hrp` command with multiple sub-commands.
|
||||
|
||||
@@ -55,7 +55,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(boomCmd)
|
||||
rootCmd.AddCommand(boomCmd)
|
||||
|
||||
boomCmd.Flags().Int64Var(&maxRPS, "max-rps", 0, "Max RPS that boomer can generate, disabled by default.")
|
||||
boomCmd.Flags().StringVar(&requestIncreaseRate, "request-increase-rate", "-1", "Request increase rate, disabled by default.")
|
||||
@@ -4,13 +4,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/cobra/doc"
|
||||
|
||||
"github.com/httprunner/hrp/hrp/cmd"
|
||||
)
|
||||
|
||||
// run this test to generate markdown docs
|
||||
// run this test to generate markdown docs for hrp command
|
||||
func TestGenMarkdownTree(t *testing.T) {
|
||||
err := doc.GenMarkdownTree(cmd.RootCmd, "./")
|
||||
err := doc.GenMarkdownTree(rootCmd, "../../../docs/cmd")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -52,7 +52,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(har2caseCmd)
|
||||
rootCmd.AddCommand(har2caseCmd)
|
||||
har2caseCmd.Flags().BoolVarP(&genJSONFlag, "to-json", "j", false, "convert to JSON format (default)")
|
||||
har2caseCmd.Flags().BoolVarP(&genYAMLFlag, "to-yaml", "y", false, "convert to JSON format")
|
||||
har2caseCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "specify output directory, default to the same dir with har file")
|
||||
@@ -11,8 +11,8 @@ import (
|
||||
"github.com/httprunner/hrp/internal/version"
|
||||
)
|
||||
|
||||
// RootCmd represents the base command when called without any subcommands
|
||||
var RootCmd = &cobra.Command{
|
||||
// rootCmd represents the base command when called without any subcommands
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "hrp",
|
||||
Short: "One-stop solution for HTTP(S) testing.",
|
||||
Long: `
|
||||
@@ -47,10 +47,10 @@ var (
|
||||
// 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() {
|
||||
RootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
RootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||
rootCmd.PersistentFlags().StringVarP(&logLevel, "log-level", "l", "INFO", "set log level")
|
||||
rootCmd.PersistentFlags().BoolVar(&logJSON, "log-json", false, "set log to json format")
|
||||
|
||||
if err := RootCmd.Execute(); err != nil {
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(runCmd)
|
||||
rootCmd.AddCommand(runCmd)
|
||||
runCmd.Flags().BoolVar(&continueOnFailure, "continue-on-failure", false, "continue running next step when failure occurs")
|
||||
runCmd.Flags().BoolVarP(&silentFlag, "silent", "s", false, "disable logging request & response details")
|
||||
runCmd.Flags().StringVarP(&proxyUrl, "proxy-url", "p", "", "set proxy url")
|
||||
@@ -24,5 +24,5 @@ var scaffoldCmd = &cobra.Command{
|
||||
}
|
||||
|
||||
func init() {
|
||||
RootCmd.AddCommand(scaffoldCmd)
|
||||
rootCmd.AddCommand(scaffoldCmd)
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/httprunner/hrp/hrp/cmd"
|
||||
"github.com/httprunner/hrp/cli/hrp/cmd"
|
||||
"github.com/httprunner/hrp/internal/sentry"
|
||||
)
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
# Usage:
|
||||
# $ make build
|
||||
# or
|
||||
# $ bash hrp/scripts/build.sh
|
||||
# $ bash cli/scripts/build.sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
@@ -15,7 +15,7 @@ mkdir -p "output"
|
||||
bin_path="output/hrp"
|
||||
|
||||
# build
|
||||
go build -ldflags '-s -w' -o "$bin_path" hrp/main.go
|
||||
go build -ldflags '-s -w' -o "$bin_path" cli/hrp/main.go
|
||||
|
||||
# check output and version
|
||||
ls -lh "$bin_path"
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
# install hrp with one shell command
|
||||
# curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/hrp/scripts/install.sh | bash
|
||||
# curl -sL https://raw.githubusercontent.com/httprunner/hrp/main/cli/scripts/install.sh | bash
|
||||
|
||||
set -e
|
||||
|
||||
@@ -31,5 +31,6 @@ Copyright 2021 debugtalk
|
||||
* [hrp boom](hrp_boom.md) - run load test with boomer
|
||||
* [hrp har2case](hrp_har2case.md) - Convert HAR to json/yaml testcase files
|
||||
* [hrp run](hrp_run.md) - run API test
|
||||
* [hrp startproject](hrp_startproject.md) - Create a scaffold project
|
||||
|
||||
###### Auto generated by spf13/cobra on 7-Jan-2022
|
||||
###### Auto generated by spf13/cobra on 8-Jan-2022
|
||||
|
||||
@@ -38,4 +38,4 @@ hrp boom [flags]
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 7-Jan-2022
|
||||
###### Auto generated by spf13/cobra on 8-Jan-2022
|
||||
|
||||
@@ -7,7 +7,7 @@ Convert HAR to json/yaml testcase files
|
||||
Convert HAR to json/yaml testcase files
|
||||
|
||||
```
|
||||
hrp har2case harPath... [flags]
|
||||
hrp har2case $har_path... [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
@@ -23,4 +23,4 @@ hrp har2case harPath... [flags]
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 7-Jan-2022
|
||||
###### Auto generated by spf13/cobra on 8-Jan-2022
|
||||
|
||||
@@ -7,7 +7,7 @@ run API test
|
||||
run yaml/json testcase files for API test
|
||||
|
||||
```
|
||||
hrp run path... [flags]
|
||||
hrp run $path... [flags]
|
||||
```
|
||||
|
||||
### Examples
|
||||
@@ -31,4 +31,4 @@ hrp run path... [flags]
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 7-Jan-2022
|
||||
###### Auto generated by spf13/cobra on 8-Jan-2022
|
||||
|
||||
19
docs/cmd/hrp_startproject.md
Normal file
19
docs/cmd/hrp_startproject.md
Normal file
@@ -0,0 +1,19 @@
|
||||
## hrp startproject
|
||||
|
||||
Create a scaffold project
|
||||
|
||||
```
|
||||
hrp startproject $project_name [flags]
|
||||
```
|
||||
|
||||
### Options
|
||||
|
||||
```
|
||||
-h, --help help for startproject
|
||||
```
|
||||
|
||||
### SEE ALSO
|
||||
|
||||
* [hrp](hrp.md) - One-stop solution for HTTP(S) testing.
|
||||
|
||||
###### Auto generated by spf13/cobra on 8-Jan-2022
|
||||
Reference in New Issue
Block a user