From 2ec2b86c05c026dd0ceb2547462db93adc0f8a76 Mon Sep 17 00:00:00 2001 From: debugtalk Date: Sat, 8 Jan 2022 15:10:37 +0800 Subject: [PATCH] refactor: commands --- .github/workflows/release.yml | 2 +- Makefile | 2 +- README.md | 4 ++-- {hrp => cli}/README.md | 0 {hrp => cli/hrp}/cmd/boom.go | 2 +- {docs => cli/hrp}/cmd/doc_test.go | 6 ++---- {hrp => cli/hrp}/cmd/har2case.go | 2 +- {hrp => cli/hrp}/cmd/root.go | 10 +++++----- {hrp => cli/hrp}/cmd/run.go | 2 +- {hrp => cli/hrp}/cmd/scaffold.go | 2 +- {hrp => cli/hrp}/main.go | 2 +- {hrp => cli}/scripts/build.sh | 4 ++-- {hrp => cli}/scripts/install.sh | 2 +- docs/cmd/hrp.md | 3 ++- docs/cmd/hrp_boom.md | 2 +- docs/cmd/hrp_har2case.md | 4 ++-- docs/cmd/hrp_run.md | 4 ++-- docs/cmd/hrp_startproject.md | 19 +++++++++++++++++++ 18 files changed, 45 insertions(+), 27 deletions(-) rename {hrp => cli}/README.md (100%) rename {hrp => cli/hrp}/cmd/boom.go (98%) rename {docs => cli/hrp}/cmd/doc_test.go (53%) rename {hrp => cli/hrp}/cmd/har2case.go (97%) rename {hrp => cli/hrp}/cmd/root.go (91%) rename {hrp => cli/hrp}/cmd/run.go (98%) rename {hrp => cli/hrp}/cmd/scaffold.go (93%) rename {hrp => cli/hrp}/main.go (81%) rename {hrp => cli}/scripts/build.sh (78%) rename {hrp => cli}/scripts/install.sh (98%) create mode 100644 docs/cmd/hrp_startproject.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f4f12fde..297b913c 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/Makefile b/Makefile index f9133fbb..b75eb2cc 100644 --- a/Makefile +++ b/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 diff --git a/README.md b/README.md index 4ec957ac..e1daa8a5 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/hrp/README.md b/cli/README.md similarity index 100% rename from hrp/README.md rename to cli/README.md diff --git a/hrp/cmd/boom.go b/cli/hrp/cmd/boom.go similarity index 98% rename from hrp/cmd/boom.go rename to cli/hrp/cmd/boom.go index b19c239a..35a7d6a9 100644 --- a/hrp/cmd/boom.go +++ b/cli/hrp/cmd/boom.go @@ -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.") diff --git a/docs/cmd/doc_test.go b/cli/hrp/cmd/doc_test.go similarity index 53% rename from docs/cmd/doc_test.go rename to cli/hrp/cmd/doc_test.go index 2ab82020..0f254e29 100644 --- a/docs/cmd/doc_test.go +++ b/cli/hrp/cmd/doc_test.go @@ -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) } diff --git a/hrp/cmd/har2case.go b/cli/hrp/cmd/har2case.go similarity index 97% rename from hrp/cmd/har2case.go rename to cli/hrp/cmd/har2case.go index 4269dbee..4e08ea41 100644 --- a/hrp/cmd/har2case.go +++ b/cli/hrp/cmd/har2case.go @@ -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") diff --git a/hrp/cmd/root.go b/cli/hrp/cmd/root.go similarity index 91% rename from hrp/cmd/root.go rename to cli/hrp/cmd/root.go index 0b60831a..916e6db8 100644 --- a/hrp/cmd/root.go +++ b/cli/hrp/cmd/root.go @@ -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) } } diff --git a/hrp/cmd/run.go b/cli/hrp/cmd/run.go similarity index 98% rename from hrp/cmd/run.go rename to cli/hrp/cmd/run.go index 274c7424..23d3de9f 100644 --- a/hrp/cmd/run.go +++ b/cli/hrp/cmd/run.go @@ -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") diff --git a/hrp/cmd/scaffold.go b/cli/hrp/cmd/scaffold.go similarity index 93% rename from hrp/cmd/scaffold.go rename to cli/hrp/cmd/scaffold.go index 2e2fed45..d70db7eb 100644 --- a/hrp/cmd/scaffold.go +++ b/cli/hrp/cmd/scaffold.go @@ -24,5 +24,5 @@ var scaffoldCmd = &cobra.Command{ } func init() { - RootCmd.AddCommand(scaffoldCmd) + rootCmd.AddCommand(scaffoldCmd) } diff --git a/hrp/main.go b/cli/hrp/main.go similarity index 81% rename from hrp/main.go rename to cli/hrp/main.go index c3c613f1..b39dc828 100644 --- a/hrp/main.go +++ b/cli/hrp/main.go @@ -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" ) diff --git a/hrp/scripts/build.sh b/cli/scripts/build.sh similarity index 78% rename from hrp/scripts/build.sh rename to cli/scripts/build.sh index 60f0f41a..37678976 100644 --- a/hrp/scripts/build.sh +++ b/cli/scripts/build.sh @@ -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" diff --git a/hrp/scripts/install.sh b/cli/scripts/install.sh similarity index 98% rename from hrp/scripts/install.sh rename to cli/scripts/install.sh index 038e0493..b76f0adc 100644 --- a/hrp/scripts/install.sh +++ b/cli/scripts/install.sh @@ -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 diff --git a/docs/cmd/hrp.md b/docs/cmd/hrp.md index cb05f56f..93352005 100644 --- a/docs/cmd/hrp.md +++ b/docs/cmd/hrp.md @@ -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 diff --git a/docs/cmd/hrp_boom.md b/docs/cmd/hrp_boom.md index f81e3723..36e4851c 100644 --- a/docs/cmd/hrp_boom.md +++ b/docs/cmd/hrp_boom.md @@ -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 diff --git a/docs/cmd/hrp_har2case.md b/docs/cmd/hrp_har2case.md index da27b051..79315570 100644 --- a/docs/cmd/hrp_har2case.md +++ b/docs/cmd/hrp_har2case.md @@ -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 diff --git a/docs/cmd/hrp_run.md b/docs/cmd/hrp_run.md index 5564d2e4..20523b8d 100644 --- a/docs/cmd/hrp_run.md +++ b/docs/cmd/hrp_run.md @@ -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 diff --git a/docs/cmd/hrp_startproject.md b/docs/cmd/hrp_startproject.md new file mode 100644 index 00000000..c22b9f47 --- /dev/null +++ b/docs/cmd/hrp_startproject.md @@ -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