Skip to content

Commit

Permalink
feat: optimized execution instruction. (#3)
Browse files Browse the repository at this point in the history
Co-authored-by: yuanyou <[email protected]>
  • Loading branch information
elza2 and yuanyou authored Jan 12, 2023
1 parent 05d7cd1 commit 62e0fd8
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
go install github.com/elza2/go-cyclic@latest
# path 路径要设置为 go.mod 文件所在的路径.
# filter 过滤匹配的文件, 多个条件使用逗号隔开(,)
go-cyclic gocyclic --dir .path [--filter *_test.go]
go-cyclic --dir .path [--filter *_test.go]
```

运行测试
===============
```bash
git clone https://github.com/elza2/go-cyclic.git
# path 路径要设置为 go.mod 文件所在的路径.
go run ./main.go gocyclic --dir .path [--filter *_test.go]
go run ./main.go --dir .path [--filter *_test.go]
```

运行结果
Expand Down
8 changes: 0 additions & 8 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,3 @@ func HandleFilters(filter string) (filters []string, err error) {
}
return filters, nil
}

func init() {
cmd := &cobra.Command{
Use: "gocyclic",
Run: RunCyclic,
}
rootCmd.AddCommand(cmd)
}
16 changes: 6 additions & 10 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,16 @@ import (
"github.com/spf13/cobra"
)

const Service = "github.com/elza2/go-cyclic"
func Execute() {
rootCmd := &cobra.Command{
Run: RunCyclic,
}

var (
rootCmd = &cobra.Command{Use: Service}
)
rootCmd.PersistentFlags().String("dir", os.Getenv("dir"), "dir. eg: directory address of the go.mod file")
rootCmd.PersistentFlags().String("filter", os.Getenv("filter"), "dir. eg: filters out files of the specified type. separate multiple types with commas (,)")

func Execute() {
if err := rootCmd.Execute(); err != nil {
log.Println(err)
os.Exit(1)
}
}

func init() {
rootCmd.PersistentFlags().String("dir", os.Getenv("dir"), "dir. eg: directory address of the go.mod file")
rootCmd.PersistentFlags().String("filter", os.Getenv("filter"), "dir. eg: filters out files of the specified type. separate multiple types with commas (,)")
}

0 comments on commit 62e0fd8

Please sign in to comment.