Skip to content

Commit

Permalink
feat: add filter support
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Sep 18, 2020
1 parent 08c432a commit ed69884
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions cmd/testdata/todo_filter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Todos Count 1
| FILENAME | MESSAGES | ASSIGNEE | LINE |
|-------------------------------|-------------------------------------|----------|------|
| ../_fixtures/todo/todo.phodal | add todo for other text like phodal | | 1 |
6 changes: 4 additions & 2 deletions cmd/todo.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/phodal/coca/pkg/application/todo"
"github.com/spf13/cobra"
"strconv"
"strings"
)

type RootCmdConfig struct {
Expand All @@ -26,7 +27,8 @@ var todoCmd = &cobra.Command{
Run: func(cmd *cobra.Command, args []string) {
path := cmd.Flag("path").Value.String()
app := todo.NewTodoApp()
filters := []string{".go", ".py", ".js", ".ts", ".java", ".kotlin", ".groovy"}

filters := strings.Split(todoCmdConfig.Extensions, ",")
todos := app.AnalysisPath(path, filters)

simple, _ := json.MarshalIndent(todos, "", "\t")
Expand Down Expand Up @@ -61,7 +63,7 @@ var todoCmd = &cobra.Command{

func init() {
todoCmd.SetOut(output)
todoCmd.PersistentFlags().StringVarP(&todoCmdConfig.Extensions, "ext", "e", ".java,.py,.go,.ts,.js", "ext=\".java,.go\"")
todoCmd.PersistentFlags().StringVarP(&todoCmdConfig.Extensions, "ext", "e", ".java,.py,.go,.ts,.js,.kt,.groovy,.gradle", "ext=\".java,.go\"")
todoCmd.PersistentFlags().StringVarP(&todoCmdConfig.Path, "path", "p", ".", "path")
todoCmd.PersistentFlags().BoolVarP(&todoCmdConfig.WithGit, "git", "g", false, "is with git info")

Expand Down
9 changes: 9 additions & 0 deletions cmd/todo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ func Test_ShouldOutputCount(t *testing.T) {
RunTestCmd(t, tests)
}

func Test_ShouldFilterTodo(t *testing.T) {
tests := []testcase.CmdTestCase{{
Name: "todo",
Cmd: "todo -p ../_fixtures/todo --ext=.phodal",
Golden: "testdata/todo_filter.txt",
}}
RunTestCmd(t, tests)
}

//TODO: update func for CI which clone depth = 1
func TestTodo(t *testing.T) {
tests := []testcase.CmdTestCase{{
Expand Down
1 change: 0 additions & 1 deletion pkg/application/todo/todo_app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ func TestNewTodoApp(t *testing.T) {
// todo: add suport for python
g.Expect(len(todos)).To(Equal(4))
g.Expect(todos[0].Line).To(Equal("3"))
//g.Expect(todos[0].Date).To(Equal("2019-12-28")) test: will failure in CI
g.Expect(todos[1].FileName).To(ContainSubstring(filepath.FromSlash("_fixtures/todo/Todo.java")))
g.Expect(todos[1].Author).To(ContainSubstring("Phodal Huang"))
g.Expect(todos[1].Line).To(Equal("6"))
Expand Down

0 comments on commit ed69884

Please sign in to comment.