todo.go 914 字节
Newer Older
P
Phodal Huang 已提交
1 2 3
package cmd

import (
P
Phodal Huang 已提交
4
	"github.com/olekukonko/tablewriter"
P
Phodal Huang 已提交
5 6
	"github.com/phodal/coca/core/domain/todo"
	"github.com/spf13/cobra"
P
Phodal Huang 已提交
7 8
	"os"
	"strings"
P
Phodal Huang 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
)

type RootCmdConfig struct {
	Path string
}

var (
	rootCmdConfig RootCmdConfig
)

var todoCmd = &cobra.Command{
	Use:   "todo",
	Short: "scan todo",
	Long:  ``,
	Run: func(cmd *cobra.Command, args []string) {
		path := cmd.Flag("path").Value.String()
		if path != "" {
			app := todo.NewTodoApp()
P
Phodal Huang 已提交
27 28 29 30 31 32 33 34 35
			todos := app.AnalysisPath(path)

			table := tablewriter.NewWriter(os.Stdout)
			table.SetHeader([]string{"Date", "Author", "Messages", "FileName", "Line"})
			for _, todo := range todos {
				table.Append([]string{todo.Date, todo.Author, strings.Join(todo.Message, "\n"), todo.FileName, todo.Line})
			}

			table.Render()
P
Phodal Huang 已提交
36 37 38 39 40 41 42 43 44
		}
	},
}

func init() {
	rootCmd.AddCommand(todoCmd)

	todoCmd.PersistentFlags().StringVarP(&rootCmdConfig.Path, "path", "p", ".", "path")
}