coo 0.1.1
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 +7 -0
- data/.gitignore +53 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +214 -0
- data/LICENSE +21 -0
- data/README.md +2 -0
- data/Rakefile +44 -0
- data/TODO.md +16 -0
- data/bin/coo +40 -0
- data/coo.gemspec +26 -0
- data/lib/coo.rb +5 -0
- data/lib/coo/commands/git.rb +121 -0
- data/lib/coo/commands/pod.rb +140 -0
- data/lib/coo/helper/cm.rb +78 -0
- data/lib/coo/helper/file_hunter.rb +73 -0
- data/lib/coo/helper/git_helper.rb +138 -0
- data/lib/coo/helper/helper.rb +11 -0
- data/lib/coo/helper/podspec_helper.rb +75 -0
- data/lib/coo/helper/question.rb +116 -0
- data/lib/coo/helper/regexp_collection.rb +26 -0
- data/lib/coo/version.rb +3 -0
- metadata +122 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
module Coo
|
2
|
+
module Helper
|
3
|
+
class PodspecHelper
|
4
|
+
attr_accessor :path
|
5
|
+
attr_accessor :podspec_content
|
6
|
+
attr_accessor :version_regex
|
7
|
+
attr_accessor :version_match
|
8
|
+
attr_accessor :version_value
|
9
|
+
|
10
|
+
def initialize(path = nil, require_variable_prefix = true)
|
11
|
+
version_var_name = 'version'
|
12
|
+
variable_prefix = require_variable_prefix ? /\w\./ : //
|
13
|
+
@version_regex = /^(?<begin>[^#]*#{variable_prefix}#{version_var_name}\s*=\s*['"])(?<value>(?<major>[0-9]+)(\.(?<minor>[0-9]+))?(\.(?<patch>[0-9]+))?(?<appendix>(\.[0-9]+)*)?(-(?<prerelease>(.+)))?)(?<end>['"])/i
|
14
|
+
|
15
|
+
return unless (path || '').length > 0
|
16
|
+
puts("Could not find podspec file at path '#{path}'") unless File.exist?(path)
|
17
|
+
|
18
|
+
@path = File.expand_path(path)
|
19
|
+
podspec_content = File.read(path)
|
20
|
+
|
21
|
+
parse(podspec_content)
|
22
|
+
end
|
23
|
+
|
24
|
+
def parse(podspec_content)
|
25
|
+
@podspec_content = podspec_content
|
26
|
+
@version_match = @version_regex.match(@podspec_content)
|
27
|
+
puts("Could not find version in podspec content '#{@podspec_content}'") if @version_match.nil?
|
28
|
+
@version_value = @version_match[:value]
|
29
|
+
end
|
30
|
+
|
31
|
+
def bump_version(bump_type)
|
32
|
+
puts("Do not support bump of 'appendix', please use `update_version_appendix(appendix)` instead") if bump_type == 'appendix'
|
33
|
+
|
34
|
+
major = version_match[:major].to_i
|
35
|
+
minor = version_match[:minor].to_i || 0
|
36
|
+
patch = version_match[:patch].to_i || 0
|
37
|
+
|
38
|
+
case bump_type
|
39
|
+
when 'patch'
|
40
|
+
patch += 1
|
41
|
+
when 'minor'
|
42
|
+
minor += 1
|
43
|
+
patch = 0
|
44
|
+
when 'major'
|
45
|
+
major += 1
|
46
|
+
minor = 0
|
47
|
+
patch = 0
|
48
|
+
end
|
49
|
+
|
50
|
+
@version_value = "#{major}.#{minor}.#{patch}"
|
51
|
+
end
|
52
|
+
|
53
|
+
def update_version_appendix(appendix = nil)
|
54
|
+
new_appendix = appendix || @version_value[:appendix]
|
55
|
+
return if new_appendix.nil?
|
56
|
+
|
57
|
+
new_appendix = new_appendix.sub(".", "") if new_appendix.start_with?(".")
|
58
|
+
major = version_match[:major].to_i
|
59
|
+
minor = version_match[:minor].to_i || 0
|
60
|
+
patch = version_match[:patch].to_i || 0
|
61
|
+
|
62
|
+
@version_value = "#{major}.#{minor}.#{patch}.#{new_appendix}"
|
63
|
+
end
|
64
|
+
|
65
|
+
def update_podspec(version = nil)
|
66
|
+
new_version = version || @version_value
|
67
|
+
updated_podspec_content = @podspec_content.gsub(@version_regex, "#{@version_match[:begin]}#{new_version}#{@version_match[:end]}")
|
68
|
+
|
69
|
+
File.open(@path, "w") { |file| file.puts(updated_podspec_content) } unless Helper.test?
|
70
|
+
|
71
|
+
updated_podspec_content
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module Coo
|
2
|
+
module Helper
|
3
|
+
module Question
|
4
|
+
# @param [确认提示] remind_str
|
5
|
+
# @return [状态值 turn 为继续执行;false 为取消执行]
|
6
|
+
def self.make_sure?(remind_str = 'Are you sure you want to do this?')
|
7
|
+
answer = self.question_and_options(remind_str, false, 'yes', 'no')
|
8
|
+
flag = false
|
9
|
+
if answer == 0
|
10
|
+
puts 'Continue 🚀'.green
|
11
|
+
flag = true
|
12
|
+
else
|
13
|
+
puts 'Cancel 💥'.red
|
14
|
+
end
|
15
|
+
if block_given?
|
16
|
+
yield flag
|
17
|
+
end
|
18
|
+
flag
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.easy_make_sure?(remind_str = 'Are you sure you want to do this?')
|
22
|
+
answer = self.question_and_options(remind_str, true, 'yes', 'no')
|
23
|
+
flag = false
|
24
|
+
if answer == 0 || answer == -1
|
25
|
+
puts 'Continue 🚀'.green
|
26
|
+
flag = true
|
27
|
+
else
|
28
|
+
puts 'Cancel 💥'.red
|
29
|
+
end
|
30
|
+
if block_given?
|
31
|
+
yield flag
|
32
|
+
end
|
33
|
+
flag
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param [问题] question_str
|
37
|
+
# @param [是否允许直接点 enter 键] accept_enter
|
38
|
+
# @param [多个选项] options
|
39
|
+
# @return [选中的值, -1 为直接 enter; 其他值为选中值得下标]
|
40
|
+
def self.question_and_options(question_str, accept_enter, *options, &block)
|
41
|
+
if (question_str.to_s.empty? || options.length == 0)
|
42
|
+
puts 'question_and_options 参数错误'
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
option_str = '[ '
|
47
|
+
for i in 0...options.length
|
48
|
+
op = options[i].to_s
|
49
|
+
if op.empty?
|
50
|
+
puts 'question_and_options 参数错误'
|
51
|
+
exit
|
52
|
+
end
|
53
|
+
option_str = option_str.concat(op)
|
54
|
+
if i < options.length - 1
|
55
|
+
option_str = option_str.concat(' / ')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
option_str = option_str.concat(' ]')
|
59
|
+
|
60
|
+
show_str = question_str + ' ' + option_str
|
61
|
+
puts show_str.blue
|
62
|
+
|
63
|
+
answer = $stdin.gets.chomp.downcase
|
64
|
+
selected = -2
|
65
|
+
|
66
|
+
if answer.to_s.empty?
|
67
|
+
selected = -1
|
68
|
+
else
|
69
|
+
options.each_with_index do |opi, ii|
|
70
|
+
if answer == opi.to_s.downcase
|
71
|
+
selected = ii
|
72
|
+
break
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
lower_limit = 0
|
78
|
+
if accept_enter == true
|
79
|
+
lower_limit = -1
|
80
|
+
end
|
81
|
+
|
82
|
+
if selected < lower_limit
|
83
|
+
if block_given?
|
84
|
+
return self.question_and_options("💥 Input error, please input again!", accept_enter, *options, &block)
|
85
|
+
else
|
86
|
+
return self.question_and_options("💥 Input error, please input again!", accept_enter, *options)
|
87
|
+
end
|
88
|
+
|
89
|
+
else
|
90
|
+
if block_given?
|
91
|
+
value = ''
|
92
|
+
if selected >= 0
|
93
|
+
value = options[selected].to_s
|
94
|
+
end
|
95
|
+
yield selected, value
|
96
|
+
end
|
97
|
+
return selected
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def self.remind_input(question_str, valid_regexp = /[\s\S]*/, &block)
|
102
|
+
puts question_str.blue
|
103
|
+
answer = $stdin.gets.chomp
|
104
|
+
if valid_regexp.match(answer)
|
105
|
+
if block_given?
|
106
|
+
yield answer
|
107
|
+
end
|
108
|
+
return answer
|
109
|
+
else
|
110
|
+
return remind_input("💥 Input error, please input again!", valid_regexp, &block)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Coo
|
2
|
+
module Helper
|
3
|
+
module RegexpCollection
|
4
|
+
|
5
|
+
# @return [0个或多个 number alphabet undlerline hyphen]
|
6
|
+
def self.n_a_u_h_0_n
|
7
|
+
return /^[A-Za-z0-9_-]*$/
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.n_a_u_h_1_n
|
11
|
+
return /^[A-Za-z0-9_-]+$/
|
12
|
+
end
|
13
|
+
|
14
|
+
# @return [单个 number alphabet]
|
15
|
+
def self.n_a_1
|
16
|
+
return /^[0-9A-Za-z]$/
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_str?(str, valid_regexp)
|
20
|
+
return true if (valid_regexp.match(str))
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
data/lib/coo/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: coo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- ripperhe
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-10-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gli
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.18'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.18'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: terminal-table
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.8'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '12.3'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '12.3'
|
69
|
+
description:
|
70
|
+
email: 453942056@qq.com
|
71
|
+
executables:
|
72
|
+
- coo
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- Gemfile.lock
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- TODO.md
|
83
|
+
- bin/coo
|
84
|
+
- coo.gemspec
|
85
|
+
- lib/coo.rb
|
86
|
+
- lib/coo/commands/git.rb
|
87
|
+
- lib/coo/commands/pod.rb
|
88
|
+
- lib/coo/helper/cm.rb
|
89
|
+
- lib/coo/helper/file_hunter.rb
|
90
|
+
- lib/coo/helper/git_helper.rb
|
91
|
+
- lib/coo/helper/helper.rb
|
92
|
+
- lib/coo/helper/podspec_helper.rb
|
93
|
+
- lib/coo/helper/question.rb
|
94
|
+
- lib/coo/helper/regexp_collection.rb
|
95
|
+
- lib/coo/version.rb
|
96
|
+
homepage: https://github.com/ripperhe/coo
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
- lib
|
105
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
requirements: []
|
116
|
+
rubyforge_project:
|
117
|
+
rubygems_version: 2.6.8
|
118
|
+
signing_key:
|
119
|
+
specification_version: 4
|
120
|
+
summary: "A useful gem for iOS developer. \U0001F680"
|
121
|
+
test_files: []
|
122
|
+
has_rdoc:
|