2021-09-02 09:48:11 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 Qiniu Cloud (qiniu.com)
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-07-21 13:09:39 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-11-19 03:32:10 +00:00
|
|
|
"github.com/ar0c/goc/v2/pkg/client"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
2021-07-21 13:09:39 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var profileCmd = &cobra.Command{
|
2024-11-19 03:32:10 +00:00
|
|
|
Use: "profile",
|
|
|
|
Short: "Get coverage profile from service registry center",
|
|
|
|
Long: `Get code coverage profile for the services under test at runtime.`,
|
|
|
|
//Run: profile,
|
2021-07-21 13:09:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-02 06:36:41 +00:00
|
|
|
var (
|
2024-11-19 03:32:10 +00:00
|
|
|
profileHost string
|
|
|
|
profileOutput string // --output flag
|
|
|
|
profileIds []string
|
|
|
|
profileSkipPattern []string
|
|
|
|
profileExtra string
|
|
|
|
profileNeedPattern []string
|
2021-09-02 06:36:41 +00:00
|
|
|
)
|
2021-07-21 13:09:39 +00:00
|
|
|
|
|
|
|
func init() {
|
2021-09-08 02:54:18 +00:00
|
|
|
|
2024-11-19 03:32:10 +00:00
|
|
|
add1Flags := func(f *pflag.FlagSet) {
|
|
|
|
f.StringVar(&profileHost, "host", "127.0.0.1:7777", "specify the host of the goc server")
|
|
|
|
f.StringSliceVar(&profileIds, "id", nil, "specify the ids of the services")
|
|
|
|
f.StringVar(&profileExtra, "extra", "", "specify the regex expression of extra, only profile with extra information will be downloaded")
|
|
|
|
}
|
2021-09-08 02:54:18 +00:00
|
|
|
|
2024-11-19 03:32:10 +00:00
|
|
|
add2Flags := func(f *pflag.FlagSet) {
|
|
|
|
f.StringVarP(&profileOutput, "output", "o", "", "download cover profile")
|
|
|
|
f.StringSliceVar(&profileSkipPattern, "skip", nil, "skip specific packages in the profile")
|
|
|
|
f.StringSliceVarP(&profileNeedPattern, "need", "n", nil, "find specific packages in the profile")
|
|
|
|
}
|
2021-09-08 02:54:18 +00:00
|
|
|
|
2024-11-19 03:32:10 +00:00
|
|
|
add1Flags(getProfileCmd.Flags())
|
|
|
|
add2Flags(getProfileCmd.Flags())
|
2021-09-08 02:54:18 +00:00
|
|
|
|
2024-11-19 03:32:10 +00:00
|
|
|
add1Flags(clearProfileCmd.Flags())
|
2021-09-08 02:54:18 +00:00
|
|
|
|
2024-11-19 03:32:10 +00:00
|
|
|
profileCmd.AddCommand(getProfileCmd)
|
|
|
|
profileCmd.AddCommand(clearProfileCmd)
|
|
|
|
rootCmd.AddCommand(profileCmd)
|
2021-07-21 13:09:39 +00:00
|
|
|
}
|
|
|
|
|
2021-09-08 02:54:18 +00:00
|
|
|
var getProfileCmd = &cobra.Command{
|
2024-11-19 03:32:10 +00:00
|
|
|
Use: "get",
|
|
|
|
Run: getProfile,
|
2021-09-08 02:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func getProfile(cmd *cobra.Command, args []string) {
|
2024-11-19 03:32:10 +00:00
|
|
|
client.GetProfile(profileHost, profileIds, profileSkipPattern, profileExtra, profileOutput, profileNeedPattern)
|
2021-09-08 02:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var clearProfileCmd = &cobra.Command{
|
2024-11-19 03:32:10 +00:00
|
|
|
Use: "clear",
|
|
|
|
Run: clearProfile,
|
2021-09-08 02:54:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func clearProfile(cmd *cobra.Command, args []string) {
|
2024-11-19 03:32:10 +00:00
|
|
|
client.ClearProfile(profileHost, profileIds, profileExtra)
|
2021-07-21 13:09:39 +00:00
|
|
|
}
|