mister_bin 0.7.6 → 0.8.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: c0acb988ac9e4c15ffe3d81625b51b1e4a9bd6eefbeaa85ecb478b32e8be54c8
4
- data.tar.gz: 8518da9a10b5ff5d9934d9045d4364ac5bfd0564be0f773a35830c985a444d40
3
+ metadata.gz: 3487443d2b2758402bb54ce0a57afbde6e9d1bf6531dfa9b45183caf78b41c39
4
+ data.tar.gz: 13593c3486780bfff261d324382956d99afc130f96586a046c47d3271dca76e3
5
5
  SHA512:
6
- metadata.gz: 7a49296fd401d5adaf920fdbac936ee5c9d59e1bea4fa7b06fec226c19ae64f9ca29bdd3fe460a2ef4eadc28666edbb3dd7f4f90f5348678e7b6911c59bddca2
7
- data.tar.gz: 5079f114df50a5bd184f82255b3a2bfff8ab82701d5fb343cd91a8b597c65811d72930cf44edbd9954114248491ff2b88f87d67b0ac038131261ed84dbd5135b
6
+ metadata.gz: 3f6e796132ba220de7175363927d1e887e80d902022570905530f940d5db425fb43c33c12b842b77cec29027493ff9af465cfeaaaaf424e292d748ac4f3fd828
7
+ data.tar.gz: 7f9964a5522fb33dffdf8aa96e2f8381b93393f752d21e4005dd9ea3ff45469e0cc9d2f663ce539cbf8cdc94434f95de7198df97f4f8b09481b13f74dcd932ad
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]
@@ -15,7 +15,13 @@ module MisterBin
15
15
  end
16
16
 
17
17
  def route(key, to:)
18
- commands[key] = to
18
+ if key.is_a? Array
19
+ target = key.shift
20
+ commands[target] = to
21
+ key.each { |alias_name| aliases[alias_name] = target }
22
+ else
23
+ commands[key] = to
24
+ end
19
25
  end
20
26
 
21
27
  def route_all(to:)
@@ -36,6 +42,10 @@ module MisterBin
36
42
  end
37
43
  end
38
44
 
45
+ def aliases
46
+ @aliases ||= {}
47
+ end
48
+
39
49
  private
40
50
 
41
51
  def execute(argv)
@@ -54,11 +64,20 @@ module MisterBin
54
64
  command = argv[0]
55
65
  return argv if commands.has_key? command
56
66
 
57
- candidates = commands.keys.grep(/^#{command}/)
58
- argv[0] = candidates.first if candidates.count == 1
67
+ argv[0] = find_target_command argv[0]
59
68
  argv
60
69
  end
61
70
 
71
+ def find_target_command(input)
72
+ candidates = commands.keys.grep(/^#{input}/)
73
+ return candidates.first if candidates.count == 1
74
+
75
+ candidates = aliases.keys.grep(/^#{input}/)
76
+ return aliases[candidates.first] if candidates.count == 1
77
+
78
+ input
79
+ end
80
+
62
81
  def show_version
63
82
  puts version
64
83
  0
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = '0.7.6'
2
+ VERSION = '0.8.1'
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.1
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: []