itools 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bfa7f1d61af3f21b4f830408a54445698ff087a9ad6d8e3b1d08e6dd01f37972
4
- data.tar.gz: 7c4ca8105259d3782e630882974fef2f7cc023ecde73b70ea39c17bd55ba8c16
3
+ metadata.gz: 3828da40e5decda6064bd9396562cf03881b545a77a4a2c37d90c7eaa6111d98
4
+ data.tar.gz: 57a66da5dbe207eefcfcb183d086ced229fbabc769a2cd98ac73e7740f37c57b
5
5
  SHA512:
6
- metadata.gz: e7a22fb5ff1357dee5500392ce0ad3d7d0e8c15fd8d5e7237b78e87c37f2c29ea5a153024e84a29767f5c4c8e026896af3e65a27461cca43d320c8fdc807a793
7
- data.tar.gz: 0455ce9866f4101234cb6c0cacc95195eb50d7d8641180d78afa009b204b98ac794e43f705ac1a17c717c4d4f828dde4651daccb5f6b3c76f3c7698e7194139f
6
+ metadata.gz: ac215d7c50ed990fed380008823cead05309cbab0a79d2b35043e0d694668e9d64ff0300eb01408908d0a410df7b1294e7e63aa3565b5da4eb1107ad05f59f6a
7
+ data.tar.gz: dfbb9d64c6dc07d983b0896e993550d81ee01f62b44a73aac40c7887312fd112929032f0a9bb33fc181ffb2962483c107237bda22145c26863b6d53791dcf701
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- itools (0.4.1)
4
+ itools (0.4.2)
5
5
  bundler (~> 1.17)
6
6
  gli (~> 2.17)
7
7
  rake (~> 10.0)
data/README.md CHANGED
@@ -19,21 +19,21 @@ SYNOPSIS
19
19
  itools [global options] command [command options] [arguments...]
20
20
 
21
21
  VERSION
22
- 0.3.0
22
+ 0.4.2
23
23
 
24
24
  GLOBAL OPTIONS
25
25
  --help - Show this message
26
26
  --version - Display the program version
27
27
 
28
28
  COMMANDS
29
+ count_code_line - count lines of code
29
30
  find - search unuse image
30
31
  help - Shows a list of commands or help for one command
31
32
  parse - Analyze the memory footprint of each part or component in Xcode project
32
33
  search - search str(or strs) in some file(or folder's file)
33
- searchFile - search File in folder
34
+ search_file - search File in folder
34
35
  search_unuse_class - search unuse class
35
- sizeFor - calculate the memory footprint of file or folder(contain file)
36
-
36
+ size_for - calculate the memory footprint of file or folder(contain file)
37
37
  ```
38
38
 
39
39
  ### 功能1:解析LinkMap
@@ -96,9 +96,9 @@ itools find /Users/zhanggui/zhanggui/tdp
96
96
  ### 功能4:计算文件大小
97
97
  命令
98
98
  ```
99
- itools sizeFor /Users/zhanggui/zhanggui/my 1000
99
+ itools size_for /Users/zhanggui/zhanggui/my 1000
100
100
  or
101
- itools sizeFor /Users/zhanggui/zhanggui/my
101
+ itools size_for /Users/zhanggui/zhanggui/my
102
102
  ```
103
103
  计算sizeFor后面跟的参数内容所占内存大小,如果参数为文件路径,则计算文件大小,如果是文件夹,会遍历所有文件,然后计算大小。第二个参数为计算系数(这个系数为1MB = 1024KB中的1024;windows为1024,mac为1000,不传默认为1024)。
104
104
  在中途会提示你输入要查找的文件后缀,不输入任何则表示查找文件夹下的所有文件,输入后缀则会计算特定文件类型包含的大小,例如:png,jpg,gif,这样会计算出文件夹中三种类型格式的图片所占有内存的大小。
@@ -106,7 +106,7 @@ or
106
106
  ### 功能5:查找文件
107
107
  命令
108
108
  ```
109
- itools searchFile /Users/zhanggui/zhanggui/my-dev/search_vc ViewController.m #第二个参数现在只支持单字符串查找
109
+ itools search_file /Users/zhanggui/zhanggui/my-dev/search_vc ViewController.m #第二个参数现在只支持单字符串查找
110
110
  ```
111
111
  查找/Users/zhanggui/zhanggui/my-dev/search_vc文件夹下所有的文件名包含ViewController.m的文件,并且输出到excel表格
112
112
 
@@ -116,6 +116,15 @@ itools searchFile /Users/zhanggui/zhanggui/my-dev/search_vc ViewController.m
116
116
  itools search_unuse_class /Users/zhanggui/zhanggui/my-dev/search_vc
117
117
  ```
118
118
  参数为工程所在的文件夹,例如/Users/zhanggui/zhanggui/my-dev/search_vc。查出的结果可能包含category或者extension,请拿结果作为参考,不作为最终要删除的文件。
119
+
120
+ ### 功能7:统计代码行数
121
+ 命令
122
+ ```
123
+ itools count_code_line 文件路径/文件夹路径
124
+ #例如
125
+ itools count_code_line /User/zhanggui/mydemoapp #统计mydemoapp项目的代码行数
126
+ ```
127
+ 该工具只统计了.m、.mm、.h、.cpp这几个文件,并且不包含单行注释以及空行。
119
128
  ## Contributing
120
129
 
121
130
  Bug reports and pull requests are welcome on GitHub at https://github.com/ScottZg/itools. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the
data/bin/itools CHANGED
@@ -56,4 +56,13 @@ command :search_file do |c|
56
56
  Itools::FileSearcher.searchFile(args)
57
57
  end
58
58
  end
59
+
60
+ # 统计代码行数
61
+ desc "count lines of code"
62
+ arg 'file name or folder'
63
+ command :count_code_line do |c|
64
+ c.action do |global_options, options, args|
65
+ Itools::CodeCouner.counter(args)
66
+ end
67
+ end
59
68
  exit run(ARGV)
@@ -4,4 +4,5 @@ require "itools/string_searcher"
4
4
  require "itools/find_unuse_img"
5
5
  require "itools/get_size"
6
6
  require "itools/file_handle"
7
- require "itools/class_unuse_finder"
7
+ require "itools/class_unuse_finder"
8
+ require "itools/count_code_line"
@@ -39,6 +39,8 @@ module Itools
39
39
  inheritance_str = ": #{f_result.fr_name}"
40
40
  contain_str = '@"' + f_result.fr_name + '"'
41
41
  reference_str = "#{f_result.fr_name}.h"
42
+
43
+ # if s_containet.match(/: #{f_result.fr_name}|@"#{f_result.fr_name}"|#{f_result.fr_name}.h/) != nil
42
44
  if s_containet.include?(inheritance_str) or s_containet.include?(contain_str) or s_containet.include?(reference_str)
43
45
  use_idxs << f_result
44
46
  puts "#{f_result.fr_name}已使用,剩余查找文件数#{@classes.size - use_idxs.size}..."
@@ -0,0 +1,48 @@
1
+ require 'find'
2
+ module Itools
3
+ class CodeCouner
4
+ attr_accessor :file_path, :line_number
5
+ def initialize(path)
6
+ @file_path = path
7
+ @line_number = 0
8
+ end
9
+ # 统计行数
10
+ def calculate_line_number
11
+ puts "\033[32m正在统计,请稍后...\033[0m"
12
+ if File.file?(@file_path)
13
+ File.read(@file_path).each_line do |line|
14
+ if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行
15
+ @line_number = @line_number + 1
16
+ end
17
+ end
18
+ return
19
+ end
20
+ if File::directory?(@file_path)
21
+ Find.find(@file_path) do |file|
22
+ if File.file?(file)
23
+ if File.extname(file).match(/^.[hm]m?$|.cpp/) #只统计.h/.m/.mm/.cpp几个文件
24
+ File.read(file).each_line do |line|
25
+ if line.match(/^\/\/|^$/) == nil #去掉单行注释和空行
26
+ @line_number = @line_number + 1
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ return
33
+ end
34
+ puts "\033[31m找不到指定路径的文件或者文件夹,请重新输入路径\033[0m"
35
+
36
+ end
37
+ def self.counter(args)
38
+ file = args[0]
39
+ if file.nil?
40
+ puts "\033[31m参数异常,请传入一个参数(项目目录/要统计的文件目录/要统计的文件)\033[0m"
41
+ return
42
+ end
43
+ counter = CodeCouner.new(file)
44
+ counter.calculate_line_number
45
+ puts "\033[32m统计#{counter.file_path}结束,共#{counter.line_number}行\033[0m"
46
+ end
47
+ end
48
+ end
@@ -1,3 +1,3 @@
1
1
  module Itools
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zhanggui
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-24 00:00:00.000000000 Z
11
+ date: 2018-12-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -93,6 +93,7 @@ files:
93
93
  - itools.gemspec
94
94
  - lib/itools.rb
95
95
  - lib/itools/class_unuse_finder.rb
96
+ - lib/itools/count_code_line.rb
96
97
  - lib/itools/file_handle.rb
97
98
  - lib/itools/find_unuse_img.rb
98
99
  - lib/itools/get_size.rb