mister_bin 0.4.1 → 0.5.0

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: 8d42d5b973bc5457bf2568e6331419442d0681c7d13d8bbe6a2b5019c4fbfe81
4
- data.tar.gz: 2f666761eda2b0da67f27826b68802eee416a20f6f9dc5701e8a3337099d05de
3
+ metadata.gz: 625bef48b831c9b258cbfbb1ea2e02e756604d8d09111d0db95aa670fcd5b002
4
+ data.tar.gz: fdb6c17c82ac45329073c95f9303359625ae76ea243db933d1b63df42833c533
5
5
  SHA512:
6
- metadata.gz: 7fb141b4d66f917a243f973c37a5d642432439875c91f00007a1defdfebfe4ee12f2db5c71b9048b4923f3212c85b83c4674829819f6c30ebf2c82aee452fbe9
7
- data.tar.gz: 600ed64a26b241db95deb41760d3ff7c541b7044fed583d1e2e8d4d8819576ae801f7c5a7d17a82c64b1c14a4bf43a9607ee845bf5f425cea9479497c8c41b56
6
+ metadata.gz: 7326953c18b22157cb2fc8eadd3d32fe88ba6878e63225fc1e08a0d96417a7a004c52e29fdc2c081c38fc40882b32f350f3c4e8216364d6c4c58d56ff441715b
7
+ data.tar.gz: e749163878edec4ea78846a6e309713225818016bb337831412c01032b77114539fe2f86aae02df375471a63a1ed0036be616c21c10d361a79dc04ca59ac9163
data/README.md CHANGED
@@ -200,13 +200,15 @@ version "0.1.1"
200
200
 
201
201
  # Usage patterns. You can use either a compact docopt notation, or provide
202
202
  # multiple usage calls.
203
- # The first two will create the same result as the last one.
204
203
  usage "app ls"
205
- usage "app ls --all"
206
204
  usage "app ls [--all]"
207
205
  usage "app new NAME"
208
206
 
209
207
  # Describe any subcommands
208
+ # Note that this has an additional important use:
209
+ # - For each command defined with the `command` directive, we will search
210
+ # for a method with the same name and a `_command` suffix.
211
+ # - If no such method is found, we will call the generic `run` method.
210
212
  command "ls", "Show list of files"
211
213
  command "new", "Pretend to create a new application"
212
214
 
@@ -234,8 +236,10 @@ Several examples of real world use of Mister Bin in the wild (well,
234
236
 
235
237
  - [Kojo][2] - Command line utility for generating config files from templates and definition files
236
238
  - [Madman][3] - The Markdown Swiss Army Knife
239
+ - [AudioAddict][4] - Command line utility for the AudioAddict radio network
237
240
 
238
241
 
239
242
  [1]: http://docopt.org/
240
243
  [2]: https://github.com/DannyBen/kojo
241
244
  [3]: https://github.com/DannyBen/madman
245
+ [4]: https://github.com/DannyBen/audio_addict
@@ -12,7 +12,9 @@ module MisterBin
12
12
 
13
13
  def execute(argv=[])
14
14
  args = Docopt.docopt docopt, version: maker.version, argv: argv
15
- exitcode = new.run args
15
+ instance = new
16
+ target = find_target_command instance, args
17
+ exitcode = instance.send target, args
16
18
  exitcode.is_a?(Numeric) ? exitcode : 0
17
19
 
18
20
  rescue Docopt::Exit => e
@@ -43,6 +45,7 @@ module MisterBin
43
45
  end
44
46
 
45
47
  def command(name, text)
48
+ target_commands << name.to_sym
46
49
  maker.commands << [name, text]
47
50
  end
48
51
 
@@ -58,7 +61,7 @@ module MisterBin
58
61
  maker.env_vars << [name, value]
59
62
  end
60
63
 
61
- protected
64
+ protected
62
65
 
63
66
  def maker
64
67
  @maker ||= DocoptMaker.new
@@ -68,6 +71,21 @@ module MisterBin
68
71
  maker.docopt
69
72
  end
70
73
 
74
+ private
75
+
76
+ def target_commands
77
+ @target_commands ||= []
78
+ end
79
+
80
+ def find_target_command(instance, args)
81
+ target_commands.each do |target|
82
+ method_name = :"#{target}_command"
83
+ return method_name if instance.respond_to? method_name and args[target.to_s]
84
+ end
85
+ :run
86
+ end
87
+
71
88
  end
89
+
72
90
  end
73
91
  end
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = "0.4.1"
2
+ VERSION = "0.5.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mister_bin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.1
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-27 00:00:00.000000000 Z
11
+ date: 2018-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole