Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Phodal
Coca
提交
bcc14014
C
Coca
项目概览
Phodal
/
Coca
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
Coca
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
未验证
提交
bcc14014
编写于
1月 06, 2020
作者:
P
Phodal Huang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactor: [test] make todo & version test works correctly
上级
b813d8e0
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
28 addition
and
16 deletion
+28
-16
cmd/coca_test.go
cmd/coca_test.go
+5
-3
cmd/root.go
cmd/root.go
+6
-5
cmd/testdata/todo_normal.txt
cmd/testdata/todo_normal.txt
+5
-0
cmd/testdata/version.txt
cmd/testdata/version.txt
+1
-0
cmd/todo.go
cmd/todo.go
+5
-5
cmd/todo_test.go
cmd/todo_test.go
+1
-1
cmd/version.go
cmd/version.go
+1
-1
coca.go
coca.go
+4
-1
未找到文件。
cmd/coca_test.go
浏览文件 @
bcc14014
...
...
@@ -40,12 +40,14 @@ func executeActionCommandC(cmd string) (*cobra.Command, string, error) {
if
err
!=
nil
{
return
nil
,
""
,
err
}
buf
:=
new
(
bytes
.
Buffer
)
command
:=
NewRootCmd
(
buf
)
rootCm
d
.
SetOut
(
buf
)
rootCm
d
.
SetArgs
(
args
)
comman
d
.
SetOut
(
buf
)
comman
d
.
SetArgs
(
args
)
c
,
err
:=
rootCm
d
.
ExecuteC
()
c
,
err
:=
comman
d
.
ExecuteC
()
return
c
,
buf
.
String
(),
err
}
...
...
cmd/root.go
浏览文件 @
bcc14014
...
...
@@ -2,11 +2,11 @@ package cmd
import
(
"github.com/spf13/cobra"
"
os
"
"
io
"
)
var
(
output
=
os
.
Stdout
output
io
.
Writer
rootCmd
=
&
cobra
.
Command
{
Use
:
"coca"
,
Short
:
"A generator for Cobra based Applications"
,
...
...
@@ -14,7 +14,8 @@ var (
}
)
func
Execute
()
error
{
rootCmd
.
SetOut
(
output
)
return
rootCmd
.
Execute
()
func
NewRootCmd
(
out
io
.
Writer
)
*
cobra
.
Command
{
output
=
out
rootCmd
.
SetOut
(
out
)
return
rootCmd
}
cmd/testdata/todo_normal.txt
0 → 100644
浏览文件 @
bcc14014
Todos Count 0
+------+--------+----------+----------+------+
| DATE | AUTHOR | MESSAGES | FILENAME | LINE |
+------+--------+----------+----------+------+
+------+--------+----------+----------+------+
cmd/testdata/version.txt
浏览文件 @
bcc14014
Coca Version: 1.3.0 -- HEAD
\ No newline at end of file
cmd/todo.go
浏览文件 @
bcc14014
...
...
@@ -7,7 +7,6 @@ import (
"github.com/phodal/coca/cmd/cmd_util"
"github.com/phodal/coca/core/context/todo"
"github.com/spf13/cobra"
"os"
"strings"
)
...
...
@@ -32,7 +31,7 @@ var todoCmd = &cobra.Command{
simple
,
_
:=
json
.
MarshalIndent
(
todos
,
""
,
"
\t
"
)
cmd_util
.
WriteToCocaFile
(
"simple-todos.json"
,
string
(
simple
))
fmt
.
Println
(
"Todos Count
"
,
len
(
todos
))
fmt
.
Fprintf
(
output
,
"Todos Count %d
\n
"
,
len
(
todos
))
if
todoCmdConfig
.
WithGit
{
gitTodos
:=
app
.
BuildWithGitHistory
(
todos
)
...
...
@@ -40,7 +39,7 @@ var todoCmd = &cobra.Command{
cModel
,
_
:=
json
.
MarshalIndent
(
todos
,
""
,
"
\t
"
)
cmd_util
.
WriteToCocaFile
(
"todos.json"
,
string
(
cModel
))
table
:=
tablewriter
.
NewWriter
(
o
s
.
Stdo
ut
)
table
:=
tablewriter
.
NewWriter
(
o
utp
ut
)
table
.
SetHeader
([]
string
{
"Date"
,
"Author"
,
"Messages"
,
"FileName"
,
"Line"
})
for
_
,
todo
:=
range
gitTodos
{
table
.
Append
([]
string
{
todo
.
Date
,
todo
.
Author
,
strings
.
Join
(
todo
.
Message
,
"
\n
"
),
todo
.
FileName
,
todo
.
Line
})
...
...
@@ -52,8 +51,9 @@ var todoCmd = &cobra.Command{
}
func
init
()
{
rootCmd
.
AddCommand
(
todoCmd
)
todoCmd
.
SetOut
(
output
)
todoCmd
.
PersistentFlags
()
.
StringVarP
(
&
todoCmdConfig
.
Path
,
"path"
,
"p"
,
"."
,
"path"
)
todoCmd
.
PersistentFlags
()
.
BoolVarP
(
&
todoCmdConfig
.
WithGit
,
"git"
,
"g"
,
false
,
"path"
)
rootCmd
.
AddCommand
(
todoCmd
)
}
cmd/todo_test.go
浏览文件 @
bcc14014
...
...
@@ -8,7 +8,7 @@ func TestTodo(t *testing.T) {
tests
:=
[]
cmdTestCase
{{
name
:
"todo"
,
cmd
:
"todo -p . -g"
,
golden
:
""
,
golden
:
"
testdata/todo_normal.txt
"
,
}}
runTestCmd
(
t
,
tests
)
}
\ No newline at end of file
cmd/version.go
浏览文件 @
bcc14014
...
...
@@ -15,6 +15,6 @@ var versionCmd = &cobra.Command{
Use
:
"version"
,
Short
:
"version"
,
Run
:
func
(
cmd
*
cobra
.
Command
,
args
[]
string
)
{
fmt
.
Fprintf
(
output
,
"Coca Version: "
+
config
.
VERSION
+
" -- HEAD
\n
"
)
fmt
.
Fprintf
(
output
,
"Coca Version: "
+
config
.
VERSION
+
" -- HEAD"
)
},
}
\ No newline at end of file
coca.go
浏览文件 @
bcc14014
...
...
@@ -2,9 +2,12 @@ package main
import
(
"github.com/phodal/coca/cmd"
"os"
)
func
main
()
{
//defer profile.Refactoring().Stop()
cmd
.
Execute
()
output
:=
os
.
Stdout
rootCmd
:=
cmd
.
NewRootCmd
(
output
)
_
=
rootCmd
.
Execute
()
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录