mister_bin 0.7.1 → 0.7.2

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: 513b43b53f6ec698926a9ab1238141b687b2e26b6fc874bac1573445b56b6d16
4
- data.tar.gz: 8b7b49dc14d2a87675f9956e8b3307fe7b16a9e32b815f07f2fb1383466c29a0
3
+ metadata.gz: ddbb5dc8eedf74546e9ef64f0350f8d8c66dd54e3178add8b7a5df40f92661ed
4
+ data.tar.gz: 785e3517267fa3d36d54fe0fab06eecb0b35067c11fed79a05183fd3352783ee
5
5
  SHA512:
6
- metadata.gz: 18acd89e58ee2fb9c57b60328233299cb28271f97f29624b94146f3112d55235af278631ca256e1557e6796c3662e82198f6907e67c70e00a83fb86776fba515
7
- data.tar.gz: 666fdc19987cc2a0eeb2859325b25f6dd5cc90c5e62a309a1af958fda2991567dce62301a7c97d6a62f745e2b201acb363e12ec8e8726feba18b84baccbd85cb
6
+ metadata.gz: 698068f7f0fe7b8105d07e13ac6758f955ae16450fe27162bef782852dc1cbdfcce77bcd15ff9b3df5d9d1872c5d661773167e88af9c7adb3064650d658960c6
7
+ data.tar.gz: 79d047bb38ca948ad5b548eb641f26e50b95064fbae0abb9d51fc7841d1a53538f15b770820d4bfa5bc725d6a7d581a42c64937f10cb6744fbfa3d49b29c37ff
data/README.md CHANGED
@@ -2,7 +2,7 @@ Mister Bin
2
2
  ==================================================
3
3
 
4
4
  [![Gem Version](https://badge.fury.io/rb/mister_bin.svg)](https://badge.fury.io/rb/mister_bin)
5
- [![Build Status](https://travis-ci.com/DannyBen/mister_bin.svg?branch=master)](https://travis-ci.com/DannyBen/mister_bin)
5
+ [![Build Status](https://github.com/DannyBen/mister_bin/workflows/Test/badge.svg)](https://github.com/DannyBen/mister_bin/actions?query=workflow%3ATest)
6
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/ae82443a99c2839d8ba8/maintainability)](https://codeclimate.com/github/DannyBen/mister_bin/maintainability)
7
7
 
8
8
  ---
@@ -69,7 +69,7 @@ Creating a command line utility with Mister Bin involves at least two files:
69
69
  2. One or more subcommand files. These files use the DSL, and will usually be
70
70
  placed in your `lib/<your gem>/commands` folder.
71
71
 
72
- WHen executing the commands, you can use only the first letters of the
72
+ When executing the commands, you can use only the first letters of the
73
73
  command name. Mister Bin will search for the command that starts with your
74
74
  input, and if it finds one and one only, it will execute it. For example,
75
75
  if you have a `server` command, you can execute it with `yourapp s` if it
@@ -195,7 +195,7 @@ These classes can use any of the below DSL commands, and must define a
195
195
 
196
196
  ### Command DSL
197
197
 
198
- The DSL is designed to create a [docopt][1] document. Most commands are
198
+ The DSL is designed to create a [docopt] document. Most commands are
199
199
  optional.
200
200
 
201
201
  The below example outlines all available DSL commands.
@@ -244,7 +244,7 @@ example "app ls --all"
244
244
 
245
245
  Interactive Terminal
246
246
  --------------------------------------------------
247
- Mister Bin comes with an interactive terminal thaht allows you to set up a
247
+ Mister Bin comes with an interactive terminal that allows you to set up a
248
248
  console that sends all commands to your runner.
249
249
 
250
250
  ![Demo](https://raw.githubusercontent.com/DannyBen/mister_bin/master/demo/terminal.gif)
@@ -297,7 +297,7 @@ end
297
297
  ```
298
298
 
299
299
  These are the available options. All string options are displayed with
300
- the [Colsole][5] `say` command so they support color markers.
300
+ the [Colsole] `say` command so they support color markers.
301
301
 
302
302
  #### `header`
303
303
 
@@ -346,18 +346,21 @@ In the Wild
346
346
  Several examples of real world use of Mister Bin in the wild (well,
347
347
  "In the Back Yard" really...).
348
348
 
349
- - [AudioAddict][4] - Command line utility for the AudioAddict radio network
350
- - [Madman][3] - The Markdown Swiss Army Knife
351
- - [Kojo][2] - Command line utility for generating config files from templates
352
- and definition files
353
- - [Jobly][6] - Compact job server with API, CLI and Web UI
354
- - [Slacktail][7] - Command line utility for following your Slack chat from the terminal
355
-
356
-
357
- [1]: http://docopt.org/
358
- [2]: https://github.com/DannyBen/kojo
359
- [3]: https://github.com/DannyBen/madman
360
- [4]: https://github.com/DannyBen/audio_addict
361
- [5]: https://github.com/dannyben/colsole
362
- [6]: https://github.com/dannyben/jobly
363
- [7]: https://github.com/dannyben/slacktail
349
+ - [AudioAddict] - Command line utility for the AudioAddict radio network
350
+ - [Bashly] - Bash command line framework and CLI Generator
351
+ - [Jobly] - Compact job server with API, CLI and Web UI
352
+ - [Kojo] - Command line utility for generating config files from templates and definition files
353
+ - [Madman] - The Markdown Swiss Army Knife
354
+ - [Slacktail] - Command line utility for following your Slack chat from the terminal
355
+ - [Site Link Analyzer] - Command line utility for finding broken links in a site
356
+
357
+
358
+ [docopt]: http://docopt.org/
359
+ [Kojo]: https://github.com/DannyBen/kojo
360
+ [Madman]: https://github.com/DannyBen/madman
361
+ [AudioAddict]: https://github.com/DannyBen/audio_addict
362
+ [Colsole]: https://github.com/dannyben/colsole
363
+ [Jobly]: https://github.com/dannyben/jobly
364
+ [Slacktail]: https://github.com/dannyben/slacktail
365
+ [Site Link Analyzer]: https://github.com/dannyben/sla
366
+ [Bashly]: https://github.com/DannyBen/bashly
@@ -7,21 +7,19 @@ module MisterBin
7
7
 
8
8
  attr_reader :args
9
9
 
10
- def initialize(args = nil)
11
- @args = args
10
+ def execute(argv = [])
11
+ @args = Docopt.docopt self.class.docopt, version: self.class.meta.version, argv: argv
12
+ target = self.class.find_target_command self, args
13
+ exitcode = send target
14
+ exitcode.is_a?(Numeric) ? exitcode : 0
15
+ rescue Docopt::Exit => e
16
+ puts e.message
17
+ 1
12
18
  end
13
19
 
14
20
  class << self
15
- def execute(argv=[])
16
- args = Docopt.docopt docopt, version: meta.version, argv: argv
17
- instance = new args
18
- target = find_target_command instance, args
19
- exitcode = instance.send target
20
- exitcode.is_a?(Numeric) ? exitcode : 0
21
-
22
- rescue Docopt::Exit => e
23
- puts e.message
24
- 1
21
+ def execute(argv = [])
22
+ new.execute argv
25
23
  end
26
24
 
27
25
  # DSL
@@ -67,14 +65,10 @@ module MisterBin
67
65
  @meta ||= CommandMeta.new
68
66
  end
69
67
 
70
- protected
71
-
72
68
  def docopt
73
69
  meta.docopt
74
70
  end
75
71
 
76
- private
77
-
78
72
  def target_commands
79
73
  @target_commands ||= []
80
74
  end
@@ -82,11 +76,10 @@ module MisterBin
82
76
  def find_target_command(instance, args)
83
77
  target_commands.each do |target|
84
78
  method_name = :"#{target}_command"
85
- return method_name if instance.respond_to? method_name and args[target.to_s]
79
+ return method_name if instance.respond_to?(method_name) && args[target.to_s]
86
80
  end
87
81
  :run
88
82
  end
89
-
90
83
  end
91
84
  end
92
85
  end
@@ -1,9 +1,8 @@
1
1
  require 'colsole'
2
2
 
3
3
  module MisterBin
4
-
5
4
  # This class is responsible for holding all the meta data for a command and
6
- # for generating a text string ready to be used by Docopt.
5
+ # for generating a text string ready to be used by Docopt.
7
6
  class CommandMeta
8
7
  include Colsole
9
8
 
@@ -23,8 +22,10 @@ module MisterBin
23
22
  end
24
23
 
25
24
  def docopt
26
- [summary_string, help_string, usage_string, commands_string,
27
- options_string, params_string, env_string, examples_string].compact.join "\n"
25
+ [
26
+ summary_string, help_string, usage_string, commands_string,
27
+ options_string, params_string, env_string, examples_string
28
+ ].compact.join "\n"
28
29
  end
29
30
 
30
31
  def description
@@ -38,60 +39,63 @@ module MisterBin
38
39
  private
39
40
 
40
41
  def summary_string
41
- summary ? word_wrap(summary) + "\n" : nil
42
+ summary ? "#{word_wrap(summary)}\n" : nil
42
43
  end
43
44
 
44
45
  def help_string
45
- help ? word_wrap(help) + "\n" : nil
46
+ help ? "#{word_wrap(help)}\n" : nil
46
47
  end
47
48
 
48
49
  def usage_string
49
- result = ["Usage:"]
50
+ result = ['Usage:']
50
51
  usages.each { |text| result << word_wrap(" #{text}") }
51
- result << ""
52
+ result << ''
52
53
  result.join "\n"
53
54
  end
54
55
 
55
56
  def options_string
56
- result = ["Options:"]
57
+ result = ['Options:']
57
58
  options.each do |option|
58
59
  result << " #{option[0]}"
59
60
  result << word_wrap(" #{option[1]}")
60
- result << ""
61
+ result << ''
61
62
  end
62
63
 
63
- result << " -h --help"
64
+ result << ' -h --help'
64
65
  result << " Show this help\n"
65
66
 
66
67
  if version
67
- result << " --version"
68
+ result << ' --version'
68
69
  result << " Show version number\n"
69
70
  end
70
-
71
+
71
72
  result.join "\n"
72
73
  end
73
74
 
74
75
  def params_string
75
76
  return nil if params.empty?
77
+
76
78
  key_value_block 'Parameters:', params
77
79
  end
78
80
 
79
81
  def env_string
80
82
  return nil if env_vars.empty?
83
+
81
84
  key_value_block 'Environment Variables:', env_vars
82
85
  end
83
86
 
84
87
  def commands_string
85
88
  return nil if commands.empty?
89
+
86
90
  key_value_block 'Commands:', commands
87
91
  end
88
92
 
89
93
  def examples_string
90
94
  return nil if examples.empty?
91
95
 
92
- result = ["Examples:"]
96
+ result = ['Examples:']
93
97
  examples.each { |text| result << word_wrap(" #{text}") }
94
- result << ""
98
+ result << ''
95
99
  result.join "\n"
96
100
  end
97
101
 
@@ -100,11 +104,10 @@ module MisterBin
100
104
  pairs.each do |key, value|
101
105
  result << " #{key}"
102
106
  result << word_wrap(" #{value}")
103
- result << ""
107
+ result << ''
104
108
  end
105
109
 
106
110
  result.join "\n"
107
111
  end
108
-
109
112
  end
110
113
  end
@@ -6,7 +6,7 @@ module MisterBin
6
6
 
7
7
  attr_reader :header, :footer, :version, :commands, :handler
8
8
 
9
- def initialize(opts={})
9
+ def initialize(opts = {})
10
10
  @header = opts[:header]
11
11
  @footer = opts[:footer]
12
12
  @version = opts[:version]
@@ -22,22 +22,22 @@ module MisterBin
22
22
  @handler = to
23
23
  end
24
24
 
25
- def run(argv=[])
25
+ def run(argv = [])
26
26
  if handler
27
27
  handler.execute argv
28
28
  elsif argv.empty?
29
29
  show_subs
30
- elsif argv == ['--help'] or argv == ['-h']
30
+ elsif (argv == ['--help']) || (argv == ['-h'])
31
31
  show_help
32
- elsif version and (argv == ['--version'] or argv == ['-v'])
32
+ elsif version && ((argv == ['--version']) || (argv == ['-v']))
33
33
  puts version
34
- return 1
34
+ 1
35
35
  else
36
36
  execute argv
37
37
  end
38
38
  end
39
39
 
40
- private
40
+ private
41
41
 
42
42
  def execute(argv)
43
43
  argv = normalize_argv_command argv
@@ -54,19 +54,20 @@ module MisterBin
54
54
  def normalize_argv_command(argv)
55
55
  command = argv[0]
56
56
  return argv if commands.has_key? command
57
- candidates = commands.keys.select { |key| key =~ /^#{command}/ }
57
+
58
+ candidates = commands.keys.grep(/^#{command}/)
58
59
  argv[0] = candidates.first if candidates.count == 1
59
60
  argv
60
61
  end
61
62
 
62
63
  def show_subs
63
64
  if commands.empty?
64
- say "No subcommands found"
65
+ say 'No subcommands found'
65
66
  else
66
67
  show_subs!
67
68
  end
68
69
 
69
- return 1
70
+ 1
70
71
  end
71
72
 
72
73
  def show_subs!
@@ -74,8 +75,8 @@ module MisterBin
74
75
  max_summary_size = terminal_width - longest_key - 6
75
76
 
76
77
  say "#{header}\n" if header
77
-
78
- say "Commands:"
78
+
79
+ say 'Commands:'
79
80
  commands.each do |key, command|
80
81
  summary = command.meta.description
81
82
  summary = summary[0..max_summary_size].strip
@@ -87,12 +88,12 @@ module MisterBin
87
88
 
88
89
  def show_help
89
90
  if commands.empty?
90
- say "No subcommands found"
91
+ say 'No subcommands found'
91
92
  else
92
93
  show_help!
93
94
  end
94
95
 
95
- return 1
96
+ 1
96
97
  end
97
98
 
98
99
  def show_help!
@@ -100,17 +101,15 @@ module MisterBin
100
101
 
101
102
  commands.each do |key, command|
102
103
  meta = command.meta
103
- next unless meta.help or meta.summary
104
+ next unless meta.help || meta.summary
104
105
 
105
106
  say "!txtgrn!#{key}"
106
107
  help = meta.help || meta.summary
107
108
  say word_wrap " #{help}"
108
- say ""
109
+ say ''
109
110
  end
110
111
 
111
- say "#{footer}" if footer
112
+ say footer.to_s if footer
112
113
  end
113
-
114
-
115
114
  end
116
- end
115
+ end
@@ -8,7 +8,7 @@ module MisterBin
8
8
 
9
9
  attr_reader :runner, :options
10
10
 
11
- def initialize(runner, options=nil)
11
+ def initialize(runner, options = nil)
12
12
  @runner = runner
13
13
  @options = options || {}
14
14
  end
@@ -18,7 +18,7 @@ module MisterBin
18
18
  end
19
19
 
20
20
  def start
21
- Readline.completion_append_character = " "
21
+ Readline.completion_append_character = ' '
22
22
  Readline.completion_proc = autocomplete_handler if autocomplete
23
23
 
24
24
  welcome_messages
@@ -57,9 +57,9 @@ module MisterBin
57
57
  command = Shellwords.shellwords input
58
58
 
59
59
  if reserved_commands.include? command.first
60
- reserved_commands[command.first].call command[1..-1]
61
- elsif !disable_system_shell and command.first&.start_with? system_character
62
- system input[1..-1]
60
+ reserved_commands[command.first].call command[1..]
61
+ elsif !disable_system_shell && command.first&.start_with?(system_character)
62
+ system input[1..]
63
63
  else
64
64
  runner.run command
65
65
  end
@@ -70,7 +70,7 @@ module MisterBin
70
70
  end
71
71
 
72
72
  def exit_commands
73
- @exit_commands ||= options[:exit_commands] || ['exit', 'q']
73
+ @exit_commands ||= options[:exit_commands] || %w[exit q]
74
74
  end
75
75
 
76
76
  def header
@@ -78,7 +78,7 @@ module MisterBin
78
78
  end
79
79
 
80
80
  def input_loop
81
- while input = Readline.readline(prompt, true) do
81
+ while (input = Readline.readline prompt, true)
82
82
  break unless execute input
83
83
  end
84
84
  end
@@ -93,7 +93,7 @@ module MisterBin
93
93
 
94
94
  def safe_input_loop
95
95
  input_loop
96
- # :nocov:
96
+ # :nocov:
97
97
  rescue Interrupt
98
98
  say exit_message if exit_message
99
99
  false
@@ -102,7 +102,7 @@ module MisterBin
102
102
  say "!txtred!#{e.class}"
103
103
  say e.message
104
104
  true
105
- # :nocov:
105
+ # :nocov:
106
106
  end
107
107
 
108
108
  def show_usage
@@ -117,6 +117,5 @@ module MisterBin
117
117
  say header if header
118
118
  runner.run if show_usage
119
119
  end
120
-
121
120
  end
122
121
  end
@@ -1,3 +1,3 @@
1
1
  module MisterBin
2
- VERSION = "0.7.1"
3
- end
2
+ VERSION = '0.7.2'
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.7.1
4
+ version: 0.7.2
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: 2019-09-28 00:00:00.000000000 Z
11
+ date: 2022-11-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.5'
19
+ version: '0.7'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0.5'
26
+ version: '0.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: docopt
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -54,7 +54,8 @@ files:
54
54
  homepage: https://github.com/dannyben/mister_bin
55
55
  licenses:
56
56
  - MIT
57
- metadata: {}
57
+ metadata:
58
+ rubygems_mfa_required: 'true'
58
59
  post_install_message:
59
60
  rdoc_options: []
60
61
  require_paths:
@@ -63,14 +64,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
64
  requirements:
64
65
  - - ">="
65
66
  - !ruby/object:Gem::Version
66
- version: 2.3.0
67
+ version: 2.6.0
67
68
  required_rubygems_version: !ruby/object:Gem::Requirement
68
69
  requirements:
69
70
  - - ">="
70
71
  - !ruby/object:Gem::Version
71
72
  version: '0'
72
73
  requirements: []
73
- rubygems_version: 3.0.4
74
+ rubygems_version: 3.3.14
74
75
  signing_key:
75
76
  specification_version: 4
76
77
  summary: Command line interface for your gems