refactor: refactor cmd parameter

上级 3bde6500
...@@ -12,7 +12,9 @@ import ( ...@@ -12,7 +12,9 @@ import (
) )
type CallCmdConfig struct { type CallCmdConfig struct {
Path string Path string
ClassName string
RemoveName string
} }
var ( var (
...@@ -27,9 +29,6 @@ var callGraphCmd = &cobra.Command{ ...@@ -27,9 +29,6 @@ var callGraphCmd = &cobra.Command{
var parsedDeps []core_domain.CodeDataStruct var parsedDeps []core_domain.CodeDataStruct
dependence := callCmdConfig.Path dependence := callCmdConfig.Path
className := cmd.Flag("className").Value.String()
remove := cmd.Flag("remove").Value.String()
if dependence != "" { if dependence != "" {
analyser := NewCallGraph() analyser := NewCallGraph()
file := cmd_util.ReadFile(dependence) file := cmd_util.ReadFile(dependence)
...@@ -39,9 +38,9 @@ var callGraphCmd = &cobra.Command{ ...@@ -39,9 +38,9 @@ var callGraphCmd = &cobra.Command{
_ = json.Unmarshal(file, &parsedDeps) _ = json.Unmarshal(file, &parsedDeps)
content := analyser.Analysis(className, parsedDeps) content := analyser.Analysis(callCmdConfig.ClassName, parsedDeps)
if remove != "" { if callCmdConfig.RemoveName != "" {
content = strings.ReplaceAll(content, remove, "") content = strings.ReplaceAll(content, callCmdConfig.RemoveName, "")
} }
cmd_util.WriteToCocaFile("call.dot", content) cmd_util.WriteToCocaFile("call.dot", content)
...@@ -53,7 +52,7 @@ var callGraphCmd = &cobra.Command{ ...@@ -53,7 +52,7 @@ var callGraphCmd = &cobra.Command{
func init() { func init() {
rootCmd.AddCommand(callGraphCmd) rootCmd.AddCommand(callGraphCmd)
callGraphCmd.PersistentFlags().StringP("className", "c", "", "path") callGraphCmd.PersistentFlags().StringVarP(&callCmdConfig.ClassName, "className", "c", "", "class")
callGraphCmd.PersistentFlags().StringVarP(&callCmdConfig.Path, "dependence", "d", config.CocaConfig.ReporterPath+"/deps.json", "get dependence file") callGraphCmd.PersistentFlags().StringVarP(&callCmdConfig.Path, "dependence", "d", config.CocaConfig.ReporterPath+"/deps.json", "get dependence file")
callGraphCmd.PersistentFlags().StringP("remove", "r", "", "remove package ParamName") callGraphCmd.PersistentFlags().StringVarP(&callCmdConfig.RemoveName, "remove", "r", "", "remove package ParamName")
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册