dencli 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b59309b03abb2d1a44eda112c289335eed1a252bccd89404a4e5017ff876657f
4
- data.tar.gz: 0ecfaff2dd2928bfdc134ee3dc92737ae2776737e6ada66fd1432de5b470ab76
3
+ metadata.gz: 5f6fa7e69d426f92f554f31e17adc226687c6851b53f11750fe2887e856d7e99
4
+ data.tar.gz: 9e2b3b52bed172e5a3b17f8556bb5bc90a4fa613bc631d6ccf3eff5a7e6bcbdb
5
5
  SHA512:
6
- metadata.gz: d27d7f9d307e1e86684ebb7e771ff865d0d10e4cde501951947997e98d25aafff123826c1973e7615ab45edd7c2bd3d60eacefa56835eacd976a4e9a9f4ed2d8
7
- data.tar.gz: 70f63e628dcd9b7c2cc8da2302ef0dc33a170efc6281173c05f31b09657c0f4b616cd71faaa3ea09738e629b021e51e6018fda33535d2d34d8570caa0db32acc
6
+ metadata.gz: 3e8c379293addfafee9b688c1eb02c336616ce1e66522bb98d94966eacf3e5fa1a23f5e7df1de6f731d97700fd44ea1188f0f8e8f30e6729459799254348bf5f
7
+ data.tar.gz: ae7fe49dd995e7fd186fa7f52c4c9f85f4e35c5b70fc6f3e11a59082cb395ae50bab87e455475241e39048a2c559fe2336a4fad8809434577c117c3565efcaff
data/bin/example.rb CHANGED
@@ -4,8 +4,9 @@ require 'pathname'
4
4
  $:.unshift Pathname.new(__FILE__).dirname.dirname.join('lib').to_s
5
5
  require 'dencli'
6
6
 
7
- cli = DenCli.new 'example', "This is an example for generate a DenCli-API"
8
- cli.cmd( :args, "Expects and prints given arguments", &lambda {|a, b, c:, d:, e:|
7
+ cli = DenCli.new :example, "This is an example for generate a DenCli-API"
8
+ cli.cmd( :args, "Expects and prints given arguments",
9
+ &lambda {|a, b, c:, d:, e:|
9
10
  p a: a, b: b, c: c, d: d, e: e
10
11
  }).
11
12
  opt( :c, '-c=ForC', "Option c").
data/lib/dencli/cmd.rb CHANGED
@@ -80,8 +80,8 @@ class DenCli::CMD
80
80
  end
81
81
  end
82
82
 
83
- def commands *args, &exe
84
- yield self
83
+ def commands *args
84
+ yield name, self
85
85
  end
86
86
 
87
87
  def goto *args
data/lib/dencli/sub.rb CHANGED
@@ -4,6 +4,9 @@ class DenCli::Sub
4
4
  attr_reader :parent, :name, :description, :subs, :aliases
5
5
 
6
6
  def initialize parent, name, description
7
+ #DenCli::assert_type self, __method__, :name, name, Symbol
8
+ #DenCli::assert_type self, __method__, :parent, parent, DenCli, DenCli::Sub
9
+ #DenCli::assert_type self, __method__, :description, description, String
7
10
  @parent, @name, @description, @subs, @aliases = parent, name, "-> #{description}", {}, {}
8
11
  end
9
12
 
@@ -33,7 +36,7 @@ class DenCli::Sub
33
36
  end
34
37
 
35
38
  def commands &exe
36
- yield self
39
+ yield name, self
37
40
  @subs.each {|k, c| c.commands &exe }
38
41
  end
39
42
 
@@ -44,8 +47,8 @@ class DenCli::Sub
44
47
  end
45
48
 
46
49
  def self._help_commands output, subs
47
- m = subs.map {|c| x = c.usage.length; 25 < x ? 0 : x }.max
48
- subs.each do |c|
50
+ m = subs.map {|_name,c| x = c.usage.length; 25 < x ? 0 : x }.max
51
+ subs.each do |_name, c|
49
52
  if 25 < c.usage.length
50
53
  output << "% -#{m}s\n#{' ' * m} " % [c.usage]
51
54
  else
@@ -96,6 +99,10 @@ class DenCli::Sub
96
99
  end
97
100
 
98
101
  def _add name, min, obj, aliases
102
+ #DenCli::assert_type self, __method__, :name, name, Symbol, NilClass
103
+ #DenCli::assert_type self, __method__, :min, min, Integer, NilClass
104
+ #DenCli::assert_type self, __method__, :obj, obj, DenCli::Sub, DenCli::CMD
105
+ #DenCli::assert_type self, __method__, :aliases, aliases, Array, NilClass
99
106
  name = name.to_s unless name.nil?
100
107
  @subs[name] = obj
101
108
  DenCli.gen_aliases( name, min) {|a| @aliases[a] = obj }
@@ -1,3 +1,3 @@
1
1
  class DenCli
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
data/lib/dencli.rb CHANGED
@@ -1,6 +1,13 @@
1
1
  require 'optparse'
2
2
 
3
+
3
4
  class DenCli
5
+ def self.assert_type klass, method, argument_name, object, *types
6
+ unless types.any? {|type| object.is_a? type }
7
+ raise ArgumentError, "#{klass.name}.#{method} expects #{types.map( &:to_s).join '|' } for #{argument_name}, not: #{object.inspect}"
8
+ end
9
+ end
10
+
4
11
  class UsageError < ::RuntimeError
5
12
  end
6
13
  class UnknownCommand < UsageError
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dencli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Denis Knauf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec