zan_tools 0.1.1 → 0.1.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: 773dd788ce7fe090d927b4c2382aa90b919de8b8e87c948ac6c10c8ebf4aabb9
4
- data.tar.gz: b96e41c83cdffaf83efc2a228e19168f4006024c61737a8bc6023657336d2bb2
3
+ metadata.gz: e870996ef60beb65a1f65303e557a192eca74e9118c5fc9d5e2a501b7813a89d
4
+ data.tar.gz: 382376d090cd27f457b488b5ed8779f4e42eac0084294366926f8b9797712f8e
5
5
  SHA512:
6
- metadata.gz: 3871144e1d71c6e5acff9f4b81bca111afab61ec5a8433b6c253921c3983735522c11754bd05ceb704a2139510c1f891f39d00fe6e08607f08b7ccc783a47dc3
7
- data.tar.gz: 36e001a58f93d2e78c9a578ebd9e4f6edee61eac68b2330f240f4b034034fd9a0bec5af0d1a5607e9b5db8f1c7b0f7d27d52d0dfade04fc5aee4918976f7dafd
6
+ metadata.gz: 9f95bc1544d8c565762f573970a4e1fd0b90ba25672f008fe2cd4c8f6b9ec64209ecfe0c4ab7b3c8183833af43fc2c8dffbd10a3c0f5ff8fe7f0881a5136e97f
7
+ data.tar.gz: 1ca110d0fa95fbb162158cf1c9b205aa6908c3cffa1c5230682c802a477949a57ec60677aa2732e550ff2ce8819f2c8859b13d3b6e84007883412d7ae08f9ff7
data/README.md CHANGED
@@ -18,8 +18,17 @@ Or install it yourself as:
18
18
  $ gem install zan_tools
19
19
 
20
20
  ## Usage
21
-
22
- TODO: Write usage instructions here
21
+ ```
22
+ $ zan_tools -h
23
+ Usage zan_tools COMMAND [options]
24
+ COMMAND
25
+ g/generate: 根据指定模板生成代码
26
+ generate options
27
+ -n, --name NAME 表名或者类名
28
+ -f, --fields FIELDS 字段列表,格式:字段1:类型2,字段2:类型2
29
+ -t, --template TEMPLATE 模板文件
30
+ -o, --output FILE 输出到指定文件
31
+ ```
23
32
 
24
33
  ## Development
25
34
 
@@ -14,7 +14,6 @@ module ZanTools
14
14
  opts.banner = "Usage zan_tools COMMAND [options]"
15
15
  opts.separator "COMMAND"
16
16
  opts.separator " g/generate: 根据指定模板生成代码"
17
-
18
17
  opts.separator "generate options"
19
18
  # generate命令参数
20
19
  opts.on("-n", "--name NAME", "表名或者类名") do |value|
@@ -30,16 +29,22 @@ module ZanTools
30
29
  raise "template file not exists"
31
30
  end
32
31
  end
32
+ opts.separator "common options"
33
33
  # 其他参数
34
34
  opts.on("-o", "--output FILE", "输出到指定文件") do |value|
35
35
  options[:output] = value
36
36
  end
37
+ opts.on("-v", "--version", "zan_tools版本") do |value|
38
+ options[:version] = ZanTools::VERSION
39
+ end
37
40
  end
38
41
  parser.parse!
39
42
 
40
43
  case ARGV[0]
41
44
  when 'g', 'generate'
42
45
  generate
46
+ else
47
+ puts options[:version] if options[:version]
43
48
  end
44
49
  rescue StandardError => e
45
50
  puts [e.class, e.message].join(': ')
@@ -2,6 +2,8 @@ require 'erb'
2
2
  require 'zan_tools/string'
3
3
 
4
4
  module ZanTools
5
+ class TemplateError < StandardError; end
6
+
5
7
  module Generatable
6
8
  def self.included(host_class)
7
9
  host_class.extend ClassMethods
@@ -32,6 +34,8 @@ module ZanTools
32
34
  def compile(tmpl)
33
35
  template = ERB.new(tmpl, nil, '-')
34
36
  template.result(binding)
37
+ rescue StandardError => e
38
+ raise TemplateError.new("#{e.class} - #{e.message}")
35
39
  end
36
40
  end
37
41
 
@@ -1,3 +1,3 @@
1
1
  module ZanTools
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zan_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - zigu
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-07 00:00:00.000000000 Z
11
+ date: 2018-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler