mister_bin 0.7.6 → 0.8.0

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: c0acb988ac9e4c15ffe3d81625b51b1e4a9bd6eefbeaa85ecb478b32e8be54c8
4
- data.tar.gz: 8518da9a10b5ff5d9934d9045d4364ac5bfd0564be0f773a35830c985a444d40
3
+ metadata.gz: b8b37499324199dee43edefc92606a2a697ce9dd132c6ef11803a6037e259c23
4
+ data.tar.gz: 5bd2375c5eea1a0a936cdbde439d8864975bc068ab61ac24a79f6c52ef2987a8
5
5
  SHA512:
6
- metadata.gz: 7a49296fd401d5adaf920fdbac936ee5c9d59e1bea4fa7b06fec226c19ae64f9ca29bdd3fe460a2ef4eadc28666edbb3dd7f4f90f5348678e7b6911c59bddca2
7
- data.tar.gz: 5079f114df50a5bd184f82255b3a2bfff8ab82701d5fb343cd91a8b597c65811d72930cf44edbd9954114248491ff2b88f87d67b0ac038131261ed84dbd5135b
6
+ metadata.gz: e31a33f9192da8ad523bc29a299bc373d39dcedbc8dc96d39e4a90e748a5e4321189eaea462a1823ee88226f2d22bcebf8fab05cfca5850219ef9d2fb094560b
7
+ data.tar.gz: 97c81e608bc71af98922ce740792dc0ee0d235a1dca08c18f6383fe9aa87a23d0d09cb620c564ad3066cd848d0918a0c499e1e43075205058b18051cf8bf9f4f
data/README.md CHANGED
@@ -13,7 +13,9 @@ interfaces for your gem or other Ruby application.
13
13
 
14
14
  ## Installation
15
15
 
16
- $ gem install mister_bin
16
+ ```
17
+ $ gem install mister_bin
18
+ ```
17
19
 
18
20
  ## Feature Highlights
19
21
 
@@ -21,7 +23,8 @@ interfaces for your gem or other Ruby application.
21
23
  - Each command is defined with a separate class for maximum testability and
22
24
  scalability.
23
25
  - Commands can have subcommands.
24
- - Designed for gem developers.
26
+ - Commands can have aliases.
27
+ - Designed primarily for gem developers.
25
28
 
26
29
  ## Examples
27
30
 
@@ -122,6 +125,15 @@ runner.route 'greet', to: GreetCommand
122
125
  runner.route 'config', to: ConfigCommand
123
126
  ```
124
127
 
128
+ The first argument to the `route` method can be an array. In this case, the
129
+ first element of the array will be considered the primary command name, and the
130
+ other elements will be considered aliases.
131
+
132
+ ```ruby
133
+ runner = MisterBin::Runner.new
134
+ runner.route %w[dir ls list], to: DirCommand
135
+ ```
136
+
125
137
  If you wish to route all commands to the same class, you can use:
126
138
 
127
139
  ```ruby
@@ -149,7 +161,7 @@ class GreetCommand < MisterBin::Command
149
161
  param "NAME", "The recipient of the greeting"
150
162
 
151
163
  def run
152
- # args hash is available everywhere in the calss
164
+ # args hash is available everywhere in the class
153
165
  name = args['NAME'] || 'Luke'
154
166
  puts "#{name}... I am your father..."
155
167
  end
@@ -241,7 +253,7 @@ terminal.start
241
253
  The `MisterBin::Terminal.new` command accepts an optional second argument. If
242
254
  provided, it should be a options hash:
243
255
 
244
- ```
256
+ ```ruby
245
257
  terminal = MisterBin::Terminal.new runner, {
246
258
  header: "Welcome",
247
259
  autocomplete: %w[--help greet]
@@ -253,7 +265,7 @@ commands that are not handled by your runner. For example, this piece of code
253
265
  will capture the `/cd ...` command from the terminal and pass it to your
254
266
  block:
255
267
 
256
- ```
268
+ ```ruby
257
269
  terminal = MisterBin::Terminal.new runner
258
270
  terminal.on '/cd' do |args|
259
271
  Dir.chdir args[0] if args[0]
@@ -1,4 +1,5 @@
1
1
  require 'colsole'
2
+ require 'debug'
2
3
 
3
4
  module MisterBin
4
5
  class Runner
@@ -15,7 +16,13 @@ module MisterBin
15
16
  end
16
17
 
17
18
  def route(key, to:)
18
- commands[key] = to
19
+ if key.is_a? Array
20
+ target = key.shift
21
+ commands[target] = to
22
+ key.each { |alias_name| aliases[alias_name] = target }
23
+ else
24
+ commands[key] = to
25
+ end
19
26
  end
20
27
 
21
28
  def route_all(to:)
@@ -36,6 +43,10 @@ module MisterBin
36
43
  end
37
44
  end
38
45
 
46
+ def aliases
47
+ @aliases ||= {}
48
+ end
49
+
39
50
  private
40
51
 
41
52
  def execute(argv)
@@ -54,11 +65,20 @@ module MisterBin
54
65
  command = argv[0]
55
66
  return argv if commands.has_key? command
56
67
 
57
- candidates = commands.keys.grep(/^#{command}/)
58
- argv[0] = candidates.first if candidates.count == 1
68
+ argv[0] = find_target_command argv[0]
59
69
  argv
60
70
  end
61
71
 
72
+ def find_target_command(input)
73
+ candidates = commands.keys.grep(/^#{input}/)
74
+ return candidates.first if candidates.count == 1
75
+
76
+ candidates = aliases.keys.grep(/^#{input}/)
77
+ return aliases[candidates.first] if candidates.count == 1
78
+
79
+ input
80
+ end
81
+
62
82
  def show_version
63
83
  puts version
64
84
  0
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = '0.7.6'
2
+ VERSION = '0.8.0'
3
3
  end
data/lib/mister_bin.rb CHANGED
@@ -1,6 +1,6 @@
1
- require 'mister_bin/command'
2
- require 'mister_bin/command_meta'
3
- require 'mister_bin/runner'
4
- require 'mister_bin/terminal'
5
-
6
- require 'byebug' if ENV['BYEBUG']
1
+ module MisterBin
2
+ autoload :Command, 'mister_bin/command'
3
+ autoload :CommandMeta, 'mister_bin/command_meta'
4
+ autoload :Runner, 'mister_bin/runner'
5
+ autoload :Terminal, 'mister_bin/terminal'
6
+ 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.7.6
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-24 00:00:00.000000000 Z
11
+ date: 2024-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -67,8 +67,11 @@ homepage: https://github.com/dannyben/mister_bin
67
67
  licenses:
68
68
  - MIT
69
69
  metadata:
70
+ bug_tracker_uri: https://github.com/DannyBen/mister_bin/issues
71
+ changelog_uri: https://github.com/DannyBen/mister_bin/blob/master/CHANGELOG.md
72
+ source_code_uri: https://github.com/DannyBen/mister_bin
70
73
  rubygems_mfa_required: 'true'
71
- post_install_message:
74
+ post_install_message:
72
75
  rdoc_options: []
73
76
  require_paths:
74
77
  - lib
@@ -76,15 +79,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
79
  requirements:
77
80
  - - ">="
78
81
  - !ruby/object:Gem::Version
79
- version: '2.7'
82
+ version: '3.0'
80
83
  required_rubygems_version: !ruby/object:Gem::Requirement
81
84
  requirements:
82
85
  - - ">="
83
86
  - !ruby/object:Gem::Version
84
87
  version: '0'
85
88
  requirements: []
86
- rubygems_version: 3.4.7
87
- signing_key:
89
+ rubygems_version: 3.5.23
90
+ signing_key:
88
91
  specification_version: 4
89
92
  summary: Command line interface for your gems
90
93
  test_files: []