cyclops 0.0.2 → 0.0.3

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
  SHA1:
3
- metadata.gz: 6d0e5695fc7b7b274971d1c42b8ae2c7266fa948
4
- data.tar.gz: cd55963cf675f1aab5237350891107d765b2a873
3
+ metadata.gz: 9c7bfa77550e65e5f43540c3eb45b68c39d8699e
4
+ data.tar.gz: 778b46e92d8b22c33eea63f03177459608a4615f
5
5
  SHA512:
6
- metadata.gz: 21b58077fff8522f9e282c48e09c1033ceae6d10d9c461fd5970292fe402ca37055bc143393e3e90561f11df383007a2248378f303524e3ae68da1dd6a76bb44
7
- data.tar.gz: 19a3144344c714b3a5b44851bb61b5127f37d1c69483002fd3677ecd40e252575aa2dbc34ab9d2616239fd751c04365c620ff7f091d90ee7f97f5fbc6c5556f8
6
+ metadata.gz: 66d0e27a997554bb1bfbaab940b3c7a84f6709f5d7e337a6c5b22679b33e5af4fb51d47951a60d45d697c36a9935dbaf312b8a1aa2643cf0731d2fac27dc87c8
7
+ data.tar.gz: ed78fac887806de5c77d631d8aa1099569a50a353756794b454656fcc3cd908e5cfe9cae0a6a374ed6571a0926dbdb069574cd373a2a23901b77a22cae5676c5
data/ChangeLog CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
3
  = Revision history for cyclops
4
4
 
5
+ == 0.0.3 [2014-04-14]
6
+
7
+ * Always set symbol key in options hash.
8
+
5
9
  == 0.0.2 [2014-04-12]
6
10
 
7
11
  * Prevent Cyclops::VERSION from clobbering Subclass::VERSION.
data/README CHANGED
@@ -2,12 +2,13 @@
2
2
 
3
3
  == VERSION
4
4
 
5
- This documentation refers to cyclops version 0.0.2
5
+ This documentation refers to cyclops version 0.0.3
6
6
 
7
7
 
8
8
  == DESCRIPTION
9
9
 
10
- As if there weren't enough CLI libraries already...
10
+ Provides a convenient interface around optparse. As if there weren't
11
+ enough CLI libraries already...
11
12
 
12
13
 
13
14
  == LINKS
data/Rakefile CHANGED
@@ -7,7 +7,8 @@ begin
7
7
  gem: {
8
8
  name: %q{cyclops},
9
9
  version: Cyclops::VERSION,
10
- summary: %q{A command-line option parser.},
10
+ summary: %q{A command-line option parser based on optparse.},
11
+ description: %q{Provides a convenient interface around optparse.},
11
12
  author: %q{Jens Wille},
12
13
  email: %q{jens.wille@gmail.com},
13
14
  license: %q{AGPL-3.0},
@@ -40,48 +40,62 @@ class Cyclops
40
40
  super
41
41
  end
42
42
 
43
+ # Delegates to #on with some convenience shortcuts.
44
+ #
45
+ # If +name+ is a Symbol, installs both long and short options.
46
+ # If the first element of +args+ is a Symbol, this is installed
47
+ # as the short option, otherwise the first character of +name+ is
48
+ # installed as the short option.
49
+ #
50
+ # If +name+ is a String, installs only the long option.
51
+ #
52
+ # If +name+ contains an argument name, separated by double underscore,
53
+ # additionally sets the CLI's +name+ option (as a Symbol) to the
54
+ # provided value and calls the optional block with that value. If
55
+ # the argument name ends with a question mark, the value is marked
56
+ # as optional.
43
57
  def option(name, *args, &block)
44
58
  if name =~ /(\w+)__(\w+)(\?)?\z/
45
59
  sym = name.is_a?(Symbol)
46
60
 
47
61
  name, arg, opt = $1, $2, !!$3
48
- name = name.to_sym if sym
49
-
50
- args = __on_opts(name, *args)
62
+ __on_opts(name, args, sym)
51
63
 
52
64
  arg = "[#{arg}]" if opt
53
65
  args.grep(/\A--/).first << " #{arg}"
54
66
 
55
67
  on(*args) { |value|
56
- cli.options[name] = value
68
+ cli.options[name.to_sym] = value
57
69
  yield value if block_given?
58
70
  }
59
71
  else
60
- on(*__on_opts(name, *args), &block)
72
+ on(*__on_opts(name, args), &block)
61
73
  end
62
74
  end
63
75
 
76
+ # Delegates to #on with some convenience shortcuts.
77
+ #
78
+ # If +name+ is a Symbol, installs both long and short options.
79
+ # If the first element of +args+ is a Symbol, this is installed
80
+ # as the short option, otherwise the first character of +name+ is
81
+ # installed as the short option.
82
+ #
83
+ # If +name+ is a String, installs only the long option.
84
+ #
85
+ # Sets the CLI's +name+ option (as a Symbol) to +true+ and calls
86
+ # the optional block (with no argument).
64
87
  def switch(name, *args)
65
- on(*__on_opts(name, *args)) {
66
- cli.options[name] = true
88
+ on(*__on_opts(name, args)) {
89
+ cli.options[name.to_sym] = true
67
90
  yield if block_given?
68
91
  }
69
92
  end
70
93
 
71
94
  private
72
95
 
73
- def __on_opts(name, *args)
74
- case name
75
- when Symbol
76
- long = "--#{name.to_s.tr('_', '-')}"
77
-
78
- args.unshift(args.first.is_a?(Symbol) ?
79
- "-#{args.shift}" : long[1, 2], long)
80
- when String
81
- args.unshift("--#{name}")
82
- else
83
- args.unshift(name)
84
- end
96
+ def __on_opts(name, args, sym = name.is_a?(Symbol))
97
+ args.insert(0, "-#{args[0].is_a?(Symbol) ? args.shift : name[0]}") if sym
98
+ args.insert(sym ? 1 : 0, "--#{name.to_s.tr('_', '-')}")
85
99
  end
86
100
 
87
101
  end
@@ -4,7 +4,7 @@ class Cyclops
4
4
 
5
5
  MAJOR = 0
6
6
  MINOR = 0
7
- TINY = 2
7
+ TINY = 3
8
8
 
9
9
  class << self
10
10
 
metadata CHANGED
@@ -1,35 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cyclops
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jens Wille
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain:
11
- - |
12
- -----BEGIN CERTIFICATE-----
13
- MIIDMDCCAhigAwIBAgIBADANBgkqhkiG9w0BAQUFADA+MQswCQYDVQQDDAJ3dzEb
14
- MBkGCgmSJomT8ixkARkWC2JsYWNrd2ludGVyMRIwEAYKCZImiZPyLGQBGRYCZGUw
15
- HhcNMTMwMTMxMDkyMjIyWhcNMTQwMTMxMDkyMjIyWjA+MQswCQYDVQQDDAJ3dzEb
16
- MBkGCgmSJomT8ixkARkWC2JsYWNrd2ludGVyMRIwEAYKCZImiZPyLGQBGRYCZGUw
17
- ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDVXmfa6rbTwKOvtuGoROc1
18
- I4qZjgLX0BA4WecYB97PjwLJmJ1hRvf9JulVCJYYmt5ZEPPXbgi9xLbcp6ofGmnC
19
- i68/kbhcz20/fRUtIJ2phU3ypQTEd2pFddpL7SR2FxLkzvvg5E6nslGn7o2erDpO
20
- 8sm610A3xsgT/eNIr9QA7k4pHh18X1KvZKmmQR4/AjVyKmKawzauKUoHHepjvjVs
21
- s0pVoM7UmOmrS4SafQ3OwUo37f19CVdN2/FW7z3e5+iYhKxdIFdhniX9iDWtA3Jn
22
- 7oUOtiolhCRK4P/c30UjTCDkRkOldsWciFUasROJ5VAV2SVv7FtGHoQLDZ/++tRr
23
- AgMBAAGjOTA3MAkGA1UdEwQCMAAwHQYDVR0OBBYEFIAPWU4BEoYUe82hY/0EkoGd
24
- Oo/WMAsGA1UdDwQEAwIEsDANBgkqhkiG9w0BAQUFAAOCAQEAf2YnB0mj42of22dA
25
- MimgJCAEgB3H5aHbZ6B5WVnFvrC2UUnhP+/kLj/6UgOfqcasy4Xh62NVGuNrf7rF
26
- 7NMN87XwexGuU2GCpIMUd6VCTA7zMP2OWuXEcba7jT5OtiI55buO0J4CRtyeX1XF
27
- qwlGgx4ItcGhMTlDFXj3IkpeVtjD8O7yWE21bHf9lLURmqK/r9KjoxrrVi7+cESJ
28
- H19TDW3R9p594jCl1ykPs3dz/0Bk+r1HTd35Yw+yBbyprSJb4S7OcRRHCryuo09l
29
- NBGyZvOBuqUp0xostWSk0dfxyn/YQ7eqvQRGBhK1VGa7Tg/KYqnemDE57+VOXrua
30
- 59wzaA==
31
- -----END CERTIFICATE-----
32
- date: 2014-04-12 00:00:00.000000000 Z
10
+ cert_chain: []
11
+ date: 2014-04-14 00:00:00.000000000 Z
33
12
  dependencies:
34
13
  - !ruby/object:Gem::Dependency
35
14
  name: highline
@@ -87,7 +66,7 @@ dependencies:
87
66
  - - ">="
88
67
  - !ruby/object:Gem::Version
89
68
  version: '0'
90
- description: A command-line option parser.
69
+ description: Provides a convenient interface around optparse.
91
70
  email: jens.wille@gmail.com
92
71
  executables: []
93
72
  extensions: []
@@ -109,14 +88,13 @@ licenses:
109
88
  metadata: {}
110
89
  post_install_message: |2+
111
90
 
112
- cyclops-0.0.2 [2014-04-12]:
91
+ cyclops-0.0.3 [2014-04-14]:
113
92
 
114
- * Prevent Cyclops::VERSION from clobbering Subclass::VERSION.
115
- * Fixed error in OptionParser convenience methods.
93
+ * Always set symbol key in options hash.
116
94
 
117
95
  rdoc_options:
118
96
  - "--title"
119
- - cyclops Application documentation (v0.0.2)
97
+ - cyclops Application documentation (v0.0.3)
120
98
  - "--charset"
121
99
  - UTF-8
122
100
  - "--line-numbers"
@@ -140,5 +118,5 @@ rubyforge_project:
140
118
  rubygems_version: 2.2.2
141
119
  signing_key:
142
120
  specification_version: 4
143
- summary: A command-line option parser.
121
+ summary: A command-line option parser based on optparse.
144
122
  test_files: []