ニノです。
ソースコードのステップ数を集計したり、前回とのステップ数の差分を集計したい
そんな時に便利な、WindowsでもMacでも使えるシンプルなコマンドラインツール「cloc」をご紹介します。
準備
[Windowsの場合] 以下のサイトの Latest version のリンクから、clocのexeファイルをダウンロードします。(現時点での最新版は、cloc-1.72.exe)
http://cloc.sourceforge.net
[Macの場合] 以下のコマンドでclocをインストールします。
$ brew install cloc
ステップ数をカウント .
基本的な使い方は、次のようなコマンドをコマンドライン上で実行します。
cloc [対象のディレクトリやファイル]
実際に実行すると、以下のように結果が返ってきます。
(実行コマンドの “cloc-1.72.exe” の部分は、環境に応じて置き換えてください)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
C:\cloc>cloc-1.72.exe sample1
3 text files.
3 unique files.
4 files ignored.
github.com/AlDanial/cloc v 1.72T=0.50 s (6.0 files/s, 1614.0 lines/s)
-------------------------------------------------------------------------------
Language filesblankcomment code
-------------------------------------------------------------------------------
JavaScript 1 73 58457
CSS116175
HTML 100 37
-------------------------------------------------------------------------------
SUM: 3 74 64669
-------------------------------------------------------------------------------
|
「blank」は空行、「comment」はコメント行、「code」は空行とコメント行を除いた行数を表します。
ファイル単位でカウントしたい場合は、以下のように「–by-file」オプションを指定します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
C:\cloc>cloc-1.72.exe --by-file sample1
3 text files.
3 unique files.
4 files ignored.
github.com/AlDanial/cloc v 1.72T=0.50 s (6.0 files/s, 1614.0 lines/s)
-------------------------------------------------------------------------------------
File blankcomment code
-------------------------------------------------------------------------------------
sample1\js\index.js 73 58457
sample1\css\index.css16175
sample1\html\index.html00 37
-------------------------------------------------------------------------------------
SUM:74 64669
-------------------------------------------------------------------------------------
|
カウント結果を外部ファイルとして出力
「–out」オプションでファイル名を指定することで、結果を外部ファイルとして出力することもできます。
- テキストファイルとして出力する場合
cloc-1.72.exe --by-file sample1 --out="step.txt"
-
CSVファイルとして出力する場合
cloc-1.72.exe --by-file sample1 --csv --out="step.csv"
CSVファイル出力は、後から整理するのに便利でおすすめです。
ステップ数の差分をカウント
ステップ数の差分をカウントすることもできます。
「sample1」と「sample2」の差分をファイル単位で集計したい場合、次のように実行します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
C:\cloc>cloc-1.72.exe --diff --by-file sample1 sample2
3 text files.
3 text files.
8 files ignored.
github.com/AlDanial/cloc v 1.72T=0.50 s (2.0 files/s, 2.0 lines/s)
-------------------------------------------------------------------------------------
File blankcomment code
-------------------------------------------------------------------------------------
sample1\html\index.html
same00 33
modified003
added 104
removed 001
sample1\js\index.js
same0 56437
modified004
added13 18 21
removed 02 16
sample1\css\index.css
same06175
modified000
added 006
removed 000
-------------------------------------------------------------------------------------
SUM:
same0 62645
modified007
added14 18 31
removed 02 17
-------------------------------------------------------------------------------------
|
各ファイルごとに、以下の行数をカウントしてくれます。
– same : 変更なしの行数
– modified : 変更された行数
– added : 追加された行数
– removed : 削除された行数
もちろん、カウント結果をCSVファイル等に出力することもできます。
cloc-1.72.exe --by-file sample1 sample2 --csv --out="diff.csv"
シンプルに導入できる、ステップ数カウントツール「cloc」のご紹介でした。