optplus 0.0.8 → 0.0.16

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,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MDU0ODg5OTM1ZjZlNjQ3ZWM4NzA0NGNmYTRhOWY4NWYxYzI0NzJhZg==
5
- data.tar.gz: !binary |-
6
- NDMzYjM4Y2EyZmQ3MDU4N2RmNjA1MDQ0YTkyM2M4MjdiYTRkMTIxZg==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- NjRmMGU3Zjg3ZjJmOGI3MDE1MDJlODBlM2U5NWQ1NjA3ZjQyYzBmODg3OWM5
10
- MzA5YTE1ODRlMDNmMTdmYmNjYjhjNmQzNmRmZmRhMDM3YmZkMzJhOWQ5MGFj
11
- ZGM0Y2FkNmJjOTRlYjkwN2ZmOGE2MDY5MzkyYzMwZGUzZTY1YzA=
12
- data.tar.gz: !binary |-
13
- YWZkNDdlMzBmNzI5OTMwOTc4MGFlNDU5Njg4NGViNDE0Njk0ZDFhOTcwMmU3
14
- NDQ4ZDI1NTFmMjQ3ODQzODQ5MmM2NzJlZmYyZTZmMjVmOGZlOWFlMTc5YTUz
15
- MDUyYWFkYzI2MTI1MzUwOWQ0MzRiNGE4MzY0ZDZiOWM2ZmE5NWI=
2
+ SHA1:
3
+ metadata.gz: 837e2be0083321ed2ac1f4c2f7bc55c1364d5c1d
4
+ data.tar.gz: e6f5c0104b89eefa6d90a7a4fe37087820e95a77
5
+ SHA512:
6
+ metadata.gz: 90149013724f89a2d134c9092ee2714704113cf7a3edf0375f72fe7b77654ce103cd41ccef1443ddce4d20751ac6326144ad4337ea580deac499453d1cae47e0
7
+ data.tar.gz: 2d285f5e7484927b1ce73e87cef4b98b7f5f4d84dade24b4461938f7e69216f9593effaade57b7742c4383e9c53a33785c70d04ab1c5caa4c61da935b5c0226a
data/Bugs.rdoc CHANGED
@@ -1,5 +1,5 @@
1
1
  == Outstanding Bugs and Change Requests for Optplus
2
2
 
3
- [30-Aug-2013]
3
+ [06-Nov-2014]
4
4
 
5
- * Need to implement the project!
5
+ * Fails in nest_parser if there is no help defined in main class.
@@ -2,6 +2,38 @@
2
2
  # @title Change History
3
3
 
4
4
  == History
5
+ [optplus-0.0.16 28-Nov-2014]
6
+
7
+ Add instance attribute to read options hash
8
+
9
+ [optplus-0.0.15 12-Dec-2013]
10
+
11
+ Clean up spacing etc
12
+
13
+ [optplus-0.0.14 12-Dec-2013]
14
+
15
+ Added in a sort of man facility with --man to print out all the help in one go
16
+
17
+ [optplus-0.0.13 11-Dec-2013]
18
+
19
+ Set IO to output on $stderr - testing in RL to see if this is workable
20
+
21
+ [optplus-0.0.12 25-Oct-2013]
22
+
23
+ Test for @@_help before assuming it exists in nested parser (140)
24
+
25
+ [optplus-0.0.11 25-Oct-2013]
26
+
27
+ Add IO convenience methods for displyaing output and getting responses
28
+
29
+ [optplus-0.0.10 24-Oct-2013]
30
+
31
+ Add empty help hash if no help defined when calling run!
32
+
33
+ [optplus-0.0.9 24-Oct-2013]
34
+
35
+ Drop call to before_all in nested - should be called anyway by run!
36
+
5
37
  [optplus-0.0.8 13-Sep-2013]
6
38
 
7
39
  Release Candidate with nesting etc.
data/README.md CHANGED
@@ -49,16 +49,17 @@ Here is a simple example:
49
49
  end
50
50
 
51
51
  describe :show, 'show all of the items that match the string given'
52
+
53
+ help :show, "A more details description of the show action",
54
+ "that can again spread over multiple lines",
55
+ "and is displayed when the user types mycli show -h"
56
+
52
57
  def show
53
58
  matches = next_argument_or_error('You must provide a string to match')
54
59
 
55
60
  # do the stuff
56
61
 
57
62
  end
58
- help :show, "A more details description of the show action",
59
- "that can again spread over multiple lines",
60
- "and is displayed when the user types mycli show -h"
61
-
62
63
  end
63
64
 
64
65
  Mycli.run! # don't forget!
@@ -104,11 +105,11 @@ Using Optplus involves the following:
104
105
 
105
106
  > **describe** -- links an action (as a symbol) to a one line description.
106
107
 
107
- > **action_ method** -- for the action itself, having the same name as the symbol above
108
-
109
108
  > **help** - links the action to multi-line help text that will be displayed when
110
109
  the --help option is used with the action
111
110
 
111
+ > **action_ method** -- for the action itself, having the same name as the symbol above
112
+
112
113
  * And finally, if you need to tidy up afterwards you can define an after_actions
113
114
  method.
114
115
 
@@ -142,6 +143,10 @@ simply by calling helper methods:
142
143
  You can change the short-form switch by adding a different one:
143
144
 
144
145
  debug_option(opts, '-d')
146
+
147
+ Finally, there is a "--man" switch that generates a help manual (a bit like man)
148
+ by concatenating all of the help definitions into a single output. Particularly
149
+ useful if you have a complex utility with nested actions (see below).
145
150
 
146
151
  ### Options helpers
147
152
 
@@ -168,6 +173,11 @@ For example:
168
173
 
169
174
  You can always define instance variables if you prefer.
170
175
 
176
+ ### IO
177
+
178
+ Optplus uses a module of {Optplus::IO IO} helpers to provide coloured output and to ease asking
179
+ simple questions. Note all of the outputs are to $stderr rather than $stdout.
180
+
171
181
  ### Handling Errors
172
182
 
173
183
  Optplus should take care of parsing errors and the like without you having to get involved.
@@ -97,6 +97,7 @@ module Optplus
97
97
  def run!
98
98
 
99
99
  @_parent ||= nil
100
+ @_help ||= Hash.new
100
101
 
101
102
  begin
102
103
  me = self.new
@@ -201,6 +202,7 @@ module Optplus
201
202
  @klass = self.class
202
203
  @klass._help ||= Hash.new
203
204
  @_help = false
205
+ @_man = false
204
206
  @options = Hash.new
205
207
 
206
208
  self.before_all if self.respond_to?(:before_all)
@@ -245,6 +247,11 @@ module Optplus
245
247
  @_help = true
246
248
  end
247
249
 
250
+ opts.on_tail('--man', 'output man-like help') do
251
+ @_help = true
252
+ @_man = true
253
+ end
254
+
248
255
  end
249
256
 
250
257
  @_args = @_optparse.permute(ARGV)
@@ -262,6 +269,9 @@ module Optplus
262
269
  # provides convenient access to the name of the program
263
270
  attr_reader :program_name
264
271
 
272
+ # provides access to all the options set
273
+ attr_reader :options
274
+
265
275
  # add optparse option for debug mode
266
276
  #
267
277
  # @param [Optparse] opts being the optparse instance
@@ -328,8 +338,11 @@ module Optplus
328
338
 
329
339
 
330
340
  # @!visibility private
331
- def _get_help
332
- puts @_optparse.help
341
+ def _get_help(indent=0)
342
+ prefix = " " * indent
343
+ @_optparse.help.split("/n").each do |line|
344
+ puts prefix + line
345
+ end
333
346
  puts ""
334
347
  end
335
348
 
@@ -374,6 +387,10 @@ module Optplus
374
387
 
375
388
  # @!visibility private
376
389
  def _help_me
390
+ if @_man then
391
+ self.man
392
+ return
393
+ end
377
394
  # is there an action on the line?
378
395
  if _args.length > 0 then
379
396
  # yes, but is it legit?
@@ -411,6 +428,38 @@ module Optplus
411
428
 
412
429
  end
413
430
 
431
+ # output all the help in one go!
432
+ def man
433
+ puts "Help Manual for #{@program_name}"
434
+ puts ""
435
+ _get_help
436
+ @klass._help.each_pair do |action, help|
437
+ puts "Action: #{action}"
438
+ puts ""
439
+ if help.kind_of?(Array) then
440
+ help.each do |hline|
441
+ puts " " + hline
442
+ end
443
+ else
444
+
445
+ np = help.new(self)
446
+ np._get_help(2)
447
+ puts ""
448
+
449
+ help._help.each_pair do |subaction, subhelp|
450
+ puts " Subaction: #{subaction}"
451
+ puts ""
452
+ subhelp.each do |hline|
453
+ puts " " + hline
454
+ end
455
+ puts ""
456
+ end
457
+ end
458
+ puts " "
459
+ end
460
+ puts ""
461
+ end #man
462
+
414
463
  end
415
464
 
416
465
  end
@@ -0,0 +1,69 @@
1
+ #
2
+ # Author:: Robert Sharp
3
+ # Copyright:: Copyright (c) 2013 Robert Sharp
4
+ # License:: Open Software Licence v3.0
5
+ #
6
+ # This software is licensed for use under the Open Software Licence v. 3.0
7
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
8
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
9
+ # must themselves be licensed under the Open Software Licence v. 3.0
10
+ #
11
+ #
12
+ require 'colored'
13
+
14
+ module Optplus
15
+
16
+ # bunch of convenience methods to output messages and get inputs for
17
+ # command-line scripts
18
+ module IO
19
+
20
+ # lookup to map between symbols and responses
21
+ Answers = Hash.new(false).merge({:no=>'n', :yes=>'y', :skip=>'s', :diff=>'d', :list=>'l'})
22
+
23
+ def say(txt)
24
+ $stderr.puts txt
25
+ end
26
+
27
+ def say_ok(txt)
28
+ $stderr.puts txt.green
29
+ end
30
+
31
+ def warn(txt)
32
+ $stderr.puts txt.yellow
33
+ end
34
+
35
+ def alert(txt)
36
+ $stderr.puts txt.red.bold
37
+ end
38
+
39
+ def ask(question, default=:no, answers=nil)
40
+ answers ||= Answers
41
+ default = answers.keys.first unless answers.has_key?(default)
42
+ def_key = answers[default]
43
+ answer_options = answers.values.collect {|k| k == def_key ? k.upcase : k}.join('')
44
+ loop do
45
+ $stderr.print "#{question}(#{answer_options})? "
46
+ response = $stdin.gets[0,1].downcase
47
+ if response == '?' then
48
+ answers.each_pair do |key, val|
49
+ $stderr.puts "#{key}"
50
+ end
51
+ next
52
+ end
53
+ if answers.has_value?(response) then
54
+ return answers.key(response)
55
+ else
56
+ return default
57
+ end
58
+ end
59
+
60
+ end
61
+
62
+ def continue?(question, default=false)
63
+ def_response = default ? :yes : :no
64
+ response = ask(question, def_response, {:yes=>'y', :no=>'n'})
65
+ return response == :yes
66
+ end
67
+
68
+ end
69
+ end
@@ -77,7 +77,7 @@ module Optplus
77
77
  @klass = self.class
78
78
  @_parent = parent || @klass._parent
79
79
  self.before_all if self.respond_to?(:before_all)
80
- self.before_actions if self.respond_to?(:before_actions)
80
+ #self.before_actions if self.respond_to?(:before_actions)
81
81
  end
82
82
 
83
83
  # @!visibility private
@@ -127,30 +127,38 @@ module Optplus
127
127
  end
128
128
 
129
129
  # @!visibility private
130
- def _get_help
130
+ def _get_help(indent=0)
131
+ helps = []
132
+ prefix = " " * indent
133
+
131
134
  prog_name = File.basename($0, File.extname($0))
132
- puts "Usage: #{prog_name} #{self.class._banner}"
133
- puts ""
135
+ helps << "Usage: #{prog_name} #{self.class._banner}"
136
+ helps << ""
134
137
  self.class._description.each do |line|
135
- puts line
138
+ helps << line
136
139
  end
137
- puts ""
140
+ helps << ""
138
141
  flags = 0
139
142
  self.class._descriptions.each_pair do |action, description|
140
- flag = @klass._help.has_key?(action.to_sym) ? '(-h)' : ''
143
+ flag = @klass._help && @klass._help.has_key?(action.to_sym) ? '(-h)' : ''
141
144
  flags += 1 unless flag == ''
142
- puts " #{action} - #{description} #{flag}"
145
+ helps << " #{action} - #{description} #{flag}"
143
146
  end
144
147
 
145
148
  if flags > 0 then
146
- puts ""
147
- puts " (-h indicates actions with additional help)"
148
- puts ""
149
+ helps << ""
150
+ helps << " (-h indicates actions with additional help)"
151
+ helps << ""
149
152
  end
150
153
 
151
- puts ""
152
- puts "For full details of options etc:"
153
- puts " #{prog_name} -h"
154
+ helps << ""
155
+ helps << "For full details of options etc:"
156
+ helps << " #{prog_name} -h"
157
+
158
+ helps.each do |hline|
159
+ puts prefix + hline
160
+ end
161
+
154
162
  end
155
163
 
156
164
 
@@ -1,13 +1,13 @@
1
1
  # Created by Jevoom
2
2
  #
3
- # 13-Sep-2013
4
- # Release Candidate with nesting etc.
3
+ # 28-Nov-2014
4
+ # Add instance attribute to read options hash
5
5
 
6
6
  module Optplus
7
- # version set to 0.0.8
8
- Version = '0.0.8'
9
- # date set to 13-Sep-2013
10
- Version_Date = '13-Sep-2013'
11
- #ident string set to: optplus-0.0.8 13-Sep-2013
12
- Ident = 'optplus-0.0.8 13-Sep-2013'
7
+ # version set to 0.0.16
8
+ Version = '0.0.16'
9
+ # date set to 28-Nov-2014
10
+ Version_Date = '28-Nov-2014'
11
+ #ident string set to: optplus-0.0.16 28-Nov-2014
12
+ Ident = 'optplus-0.0.16 28-Nov-2014'
13
13
  end
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ #
4
+ #
5
+ # = Test IO
6
+ #
7
+ # == Optplus
8
+ #
9
+ # Author:: Robert Sharp
10
+ # Copyright:: Copyright (c) 2013 Robert Sharp
11
+ # License:: Open Software Licence v3.0
12
+ #
13
+ # This software is licensed for use under the Open Software Licence v. 3.0
14
+ # The terms of this licence can be found at http://www.opensource.org/licenses/osl-3.0.php
15
+ # and in the file copyright.txt. Under the terms of this licence, all derivative works
16
+ # must themselves be licensed under the Open Software Licence v. 3.0
17
+ #
18
+ #
19
+ #
20
+
21
+ require 'optplus/IO'
22
+
23
+ include Optplus::IO
24
+
25
+ say "hello"
26
+
27
+ say_ok "That's OK"
28
+
29
+ warn "This is getting tricky"
30
+
31
+ alert "Too late!"
32
+
33
+ if ask("Overwrite?") == :yes then
34
+ warn "Overwriting"
35
+ else
36
+ alert "You really should have"
37
+ end
38
+
39
+ if continue?("Do you want to continue?") then
40
+ say_ok "Continuing"
41
+ else
42
+ warn "Not continuing"
43
+ end
44
+
45
+ if continue?("Do you want to stop?", true) then
46
+ say_ok "Stopped"
47
+ else
48
+ warn "Not stopping"
49
+ end
50
+
51
+ colour = ask("What colour?", :red, {red:'r', green:'g', blue:'b'})
52
+
53
+ say "You chose #{colour.to_s}"
54
+
metadata CHANGED
@@ -1,36 +1,33 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: optplus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dr Robert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-13 00:00:00.000000000 Z
11
+ date: 2014-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: !binary |-
15
- Y29sb3JlZA==
14
+ name: colored
16
15
  requirement: !ruby/object:Gem::Requirement
17
16
  requirements:
18
- - - ! '>='
17
+ - - '>='
19
18
  - !ruby/object:Gem::Version
20
19
  version: '0'
21
20
  type: :runtime
22
21
  prerelease: false
23
22
  version_requirements: !ruby/object:Gem::Requirement
24
23
  requirements:
25
- - - ! '>='
24
+ - - '>='
26
25
  - !ruby/object:Gem::Version
27
26
  version: '0'
28
- description: ! 'Wraps Optparser into a class to enable thor-like scripting with a
29
- few meta-methods
30
-
27
+ description: |-
28
+ Wraps Optparser into a class to enable thor-like scripting with a few meta-methods
31
29
  and a built-in command or action dispatcher. Its much smaller than Thor and aimed
32
-
33
- at saving time when scripting with Optparser.'
30
+ at saving time when scripting with Optparser.
34
31
  email: robert@osburn-sharp.ath.cx
35
32
  executables:
36
33
  - optplus
@@ -53,6 +50,7 @@ files:
53
50
  - lib/optplus/version.rb
54
51
  - lib/optplus/errors.rb
55
52
  - lib/optplus/nested.rb
53
+ - lib/optplus/IO.rb
56
54
  - lib/optplus.rb
57
55
  - bin/optplus
58
56
  - bin/optplus-installer
@@ -61,7 +59,8 @@ files:
61
59
  - test/conf.d/optplus.rb
62
60
  - test/my_parser.rb
63
61
  - test/my_nested_parser.rb
64
- homepage: ''
62
+ - test/io.rb
63
+ homepage: https://github.com/osburn-sharp
65
64
  licenses:
66
65
  - Open Software Licence v3.0
67
66
  metadata: {}
@@ -72,17 +71,17 @@ require_paths:
72
71
  - lib
73
72
  required_ruby_version: !ruby/object:Gem::Requirement
74
73
  requirements:
75
- - - ! '>='
74
+ - - '>='
76
75
  - !ruby/object:Gem::Version
77
76
  version: '0'
78
77
  required_rubygems_version: !ruby/object:Gem::Requirement
79
78
  requirements:
80
- - - ! '>='
79
+ - - '>='
81
80
  - !ruby/object:Gem::Version
82
81
  version: '0'
83
82
  requirements: []
84
83
  rubyforge_project:
85
- rubygems_version: 2.0.7
84
+ rubygems_version: 2.0.14
86
85
  signing_key:
87
86
  specification_version: 4
88
87
  summary: A simple wrapper class to make optparser-based scripts easy to write.