2020-05-21 06:30:41 +00:00
|
|
|
/*
|
2020-05-25 16:19:20 +00:00
|
|
|
Copyright 2020 Qiniu Cloud (qiniu.com)
|
2020-05-21 06:30:41 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2020-05-21 06:58:40 +00:00
|
|
|
package cmd
|
2020-05-21 06:30:41 +00:00
|
|
|
|
|
|
|
import (
|
2020-06-14 11:37:27 +00:00
|
|
|
"github.com/qiniu/goc/pkg/cover"
|
2020-05-21 06:30:41 +00:00
|
|
|
"github.com/spf13/cobra"
|
2020-06-14 11:38:41 +00:00
|
|
|
"github.com/spf13/viper"
|
2020-05-21 06:30:41 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var coverCmd = &cobra.Command{
|
|
|
|
Use: "cover",
|
2020-05-29 02:50:15 +00:00
|
|
|
Short: "Do cover for the target source",
|
|
|
|
Long: `Do cover for the target source. You can select different cover mode (set, count, atomic), default: count`,
|
|
|
|
Example: `
|
|
|
|
# Do cover for the current path, default center: http://127.0.0.1:7777, default cover mode: count.
|
|
|
|
goc cover
|
|
|
|
|
|
|
|
# Do cover for the current path, default cover mode: count.
|
|
|
|
goc cover --center=http://127.0.0.1:7777
|
|
|
|
|
|
|
|
# Do cover for the target path, cover mode: atomic.
|
|
|
|
goc cover --center=http://127.0.0.1:7777 --target=/path/to/target --mode=atomic
|
|
|
|
`,
|
2020-06-12 09:51:10 +00:00
|
|
|
Hidden: true,
|
2020-05-21 06:30:41 +00:00
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2020-06-12 09:51:10 +00:00
|
|
|
var buildFlags string
|
|
|
|
buildFlags = viper.GetString("buildflags")
|
2020-07-06 13:20:39 +00:00
|
|
|
cover.Execute(buildFlags, "", target, coverMode.String(), agentPort.String(), center)
|
2020-05-21 06:30:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2020-06-12 09:51:10 +00:00
|
|
|
coverCmd.Flags().StringVar(&target, "target", ".", "target folder to cover")
|
|
|
|
addCommonFlags(coverCmd.Flags())
|
2020-05-21 06:30:41 +00:00
|
|
|
rootCmd.AddCommand(coverCmd)
|
|
|
|
}
|