mercenary 0.3.6 → 0.4.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
- SHA1:
3
- metadata.gz: ca6c5dbfbf851bbffdbfa00a4a68728173436c42
4
- data.tar.gz: 03fb71ec3b1ec16047939a42958aa3d84717af02
2
+ SHA256:
3
+ metadata.gz: 87a58db4aa958efbd3a0ffe819c56213857f57bb205d82b9794c58d68202a0d4
4
+ data.tar.gz: bee506d3c88e454f1ecbcc407a83217f456fa56b3b6d95e6a879f407719df51b
5
5
  SHA512:
6
- metadata.gz: b3564cbdae68c98af758a76f97d676b1a97064236aec734710d598e84d6fe659e1bec49498957b0fa3bac7ef5e34a200f56b0cefeb81eb3e03894dbfbedb5a51
7
- data.tar.gz: 68ae6947d6f430e1a67cd0a4ed63c440d0760bdb7eb9d97346e718f27756492a74990be05a92d2689bb36167e1be52648cc3a332e4749806e00c371cad9c6cff
6
+ metadata.gz: 2a2521dda60181328b8aeb2e2309a62216ce95b58f2fe5216dd98070aeb194c8b207510b2be6da610cc761b4d2ec413cb4c4a75e9088602de2309ee8a12b47a8
7
+ data.tar.gz: b79dc80683e108f6002c49e5c9733ee25c6494108b020c97c6153973abd396a7109121d1487649f7cabdbbfa488a2dd65cb55ae42d57029603117993377cd96f
data/.gitignore CHANGED
@@ -15,3 +15,4 @@ spec/reports
15
15
  test/tmp
16
16
  test/version_tmp
17
17
  tmp
18
+ vendor/bundle
@@ -0,0 +1,10 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ require: rubocop-jekyll
4
+ inherit_gem:
5
+ rubocop-jekyll: .rubocop.yml
6
+
7
+ AllCops:
8
+ TargetRubyVersion: 2.4
9
+ Exclude:
10
+ - vendor/**/*
@@ -0,0 +1,79 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-01-18 15:09:24 +0100 using RuboCop version 0.71.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 2
10
+ Jekyll/NoPAllowed:
11
+ Exclude:
12
+ - 'examples/help_dialogue.rb'
13
+
14
+ # Offense count: 2
15
+ Jekyll/NoPutsAllowed:
16
+ Exclude:
17
+ - 'lib/mercenary/command.rb'
18
+
19
+ # Offense count: 4
20
+ # Configuration parameters: AllowSafeAssignment.
21
+ Lint/AssignmentInCondition:
22
+ Exclude:
23
+ - 'lib/mercenary/command.rb'
24
+ - 'lib/mercenary/option.rb'
25
+ - 'lib/mercenary/presenter.rb'
26
+
27
+ # Offense count: 2
28
+ Lint/DuplicateMethods:
29
+ Exclude:
30
+ - 'lib/mercenary/command.rb'
31
+
32
+ # Offense count: 1
33
+ # Configuration parameters: AllowComments.
34
+ Lint/HandleExceptions:
35
+ Exclude:
36
+ - 'lib/mercenary/option.rb'
37
+
38
+ # Offense count: 1
39
+ Lint/UselessAssignment:
40
+ Exclude:
41
+ - 'lib/mercenary/presenter.rb'
42
+
43
+ # Offense count: 1
44
+ Metrics/AbcSize:
45
+ Max: 25
46
+
47
+ # Offense count: 1
48
+ # Configuration parameters: CountComments, ExcludedMethods.
49
+ # ExcludedMethods: refine
50
+ Metrics/BlockLength:
51
+ Max: 28
52
+
53
+ # Offense count: 6
54
+ # Cop supports --auto-correct.
55
+ # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
56
+ # URISchemes: http, https
57
+ Metrics/LineLength:
58
+ Max: 319
59
+
60
+ # Offense count: 1
61
+ # Configuration parameters: CountComments, ExcludedMethods.
62
+ Metrics/MethodLength:
63
+ Max: 24
64
+
65
+ # Offense count: 1
66
+ # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist, MethodDefinitionMacros.
67
+ # NamePrefix: is_, has_, have_
68
+ # NamePrefixBlacklist: is_, has_, have_
69
+ # NameWhitelist: is_a?
70
+ # MethodDefinitionMacros: define_method, define_singleton_method
71
+ Naming/PredicateName:
72
+ Exclude:
73
+ - 'spec/**/*'
74
+ - 'lib/mercenary/command.rb'
75
+
76
+ # Offense count: 1
77
+ Style/MissingRespondToMissing:
78
+ Exclude:
79
+ - 'lib/mercenary/presenter.rb'
@@ -1,12 +1,12 @@
1
1
  language: ruby
2
- rvm:
3
- - 1.9.3
4
- - 2.0.0
5
- - 2.1
6
- sudo: false
7
2
  cache: bundler
3
+ rvm:
4
+ - 2.4
5
+ - 2.6
6
+
8
7
  before_script: bundle update
9
- script: "./script/cibuild"
8
+ script: script/cibuild
9
+
10
10
  notifications:
11
11
  email:
12
12
  recipients:
data/Gemfile CHANGED
@@ -1,4 +1,6 @@
1
- source 'https://rubygems.org'
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in mercenary.gemspec
4
6
  gemspec
@@ -1,3 +1,21 @@
1
+ ## 0.4.0 / 2020-01-18
2
+
3
+ ### Major Enhancements
4
+
5
+ * Drop Ruby 2.3 support
6
+
7
+ ### Minor Enhancements
8
+
9
+ * Remove parent command's flags from subcommand usage (#44)
10
+
11
+ ### Development Fixes
12
+
13
+ * Adopt Jekyll's rubocop config for consistency
14
+
15
+ ### Documentation
16
+
17
+ * fixes the readme (#52)
18
+
1
19
  ## 0.3.6 / 2016-04-07
2
20
 
3
21
  ### Bug Fixes
@@ -1,4 +1,4 @@
1
- Copyright (c) 2013-2014 Parker Moore
1
+ Copyright (c) 2013-present Parker Moore and the mercenary contributors
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -97,10 +97,9 @@ Fetches the program configuration hash.
97
97
 
98
98
  #### `#new`
99
99
 
100
- Create a new command. Accepts two arguments:
100
+ Create a new command. Accepts one argument:
101
101
 
102
102
  - `name` - the name of your command, as a symbol
103
- - `parent` - (optional) the parent Command
104
103
 
105
104
  #### `#version`
106
105
 
@@ -167,7 +166,7 @@ different class to create, e.g. `Array`, if you are expecting a particular class
167
166
  in your code from this option's value. The description is also optional, but
168
167
  it's highly recommended to include a description.
169
168
 
170
- #### `#alias`
169
+ #### `#alias`
171
170
 
172
171
  Specifies an alias for this command such that the alias may be used in place of
173
172
  the command during execution. Accepts one argument:
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
4
+ $LOAD_PATH.unshift File.join(__dir__, "..", "lib")
4
5
 
5
6
  require "mercenary"
6
7
 
@@ -9,23 +10,22 @@ require "mercenary"
9
10
  # be output to STDOUT.
10
11
 
11
12
  Mercenary.program(:help_dialogue) do |p|
12
-
13
13
  p.version "2.0.1"
14
- p.description 'An example of the help dialogue in Mercenary'
15
- p.syntax 'help_dialogue <subcommand>'
14
+ p.description "An example of the help dialogue in Mercenary"
15
+ p.syntax "help_dialogue <subcommand>"
16
16
 
17
17
  p.command(:some_subcommand) do |c|
18
- c.version '1.4.2'
19
- c.syntax 'some_subcommand <subcommand> [options]'
20
- c.description 'Some subcommand to do something'
21
- c.option 'an_option', '-o', '--option', 'Some option'
18
+ c.version "1.4.2"
19
+ c.syntax "some_subcommand <subcommand> [options]"
20
+ c.description "Some subcommand to do something"
21
+ c.option "an_option", "-o", "--option", "Some option"
22
22
  c.alias(:blah)
23
23
 
24
24
  c.command(:yet_another_sub) do |f|
25
- f.syntax 'yet_another_sub [options]'
26
- f.description 'Do amazing things'
27
- f.option 'blah', '-b', '--blah', 'Trigger blah flag'
28
- f.option 'heh', '-H ARG', '--heh ARG', 'Give a heh'
25
+ f.syntax "yet_another_sub [options]"
26
+ f.description "Do amazing things"
27
+ f.option "blah", "-b", "--blah", "Trigger blah flag"
28
+ f.option "heh", "-H ARG", "--heh ARG", "Give a heh"
29
29
 
30
30
  f.action do |args, options|
31
31
  print "Args: "
@@ -37,10 +37,9 @@ Mercenary.program(:help_dialogue) do |p|
37
37
  end
38
38
 
39
39
  p.command(:another_subcommand) do |c|
40
- c.syntax 'another_subcommand <subcommand> [options]'
41
- c.description 'Another subcommand to do something different.'
42
- c.option 'an_option', '-O', '--option', 'Some option'
43
- c.option 'another_options', '--pluginzzz', 'Set where the plugins should be found from'
40
+ c.syntax "another_subcommand <subcommand> [options]"
41
+ c.description "Another subcommand to do something different."
42
+ c.option "an_option", "-O", "--option", "Some option"
43
+ c.option "another_options", "--pluginzzz", "Set where the plugins should be found from"
44
44
  end
45
-
46
45
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
4
+ $LOAD_PATH.unshift File.join(__dir__, "..", "lib")
4
5
 
5
6
  require "mercenary"
6
7
 
@@ -9,18 +10,16 @@ require "mercenary"
9
10
  # be output to STDOUT.
10
11
 
11
12
  Mercenary.program(:logger_output) do |p|
12
-
13
13
  p.version "5.2.6"
14
- p.description 'An example of turning on logging for Mercenary.'
15
- p.syntax 'logger_output'
16
-
14
+ p.description "An example of turning on logging for Mercenary."
15
+ p.syntax "logger_output"
17
16
 
18
17
  p.logger.info "The default log level is INFO. So this will output."
19
18
  p.logger.debug "Since DEBUG is below INFO, this will not output."
20
19
 
21
20
  p.logger(Logger::DEBUG)
22
21
  p.logger.debug "Logger level now set to DEBUG. So everything will output."
23
-
22
+
24
23
  p.logger.debug "Example of DEBUG level message."
25
24
  p.logger.info "Example of INFO level message."
26
25
  p.logger.warn "Example of WARN level message."
@@ -28,12 +27,9 @@ Mercenary.program(:logger_output) do |p|
28
27
  p.logger.fatal "Example of FATAL level message."
29
28
  p.logger.unknown "Example of UNKNOWN level message."
30
29
 
31
- p.action do |args, options|
32
-
30
+ p.action do |_args, _options|
33
31
  p.logger(Logger::INFO)
34
32
  p.logger.debug "Logger level back to INFO. This line will not output."
35
33
  p.logger.info "This INFO message will output."
36
-
37
34
  end
38
-
39
35
  end
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- $:.unshift File.join(File.dirname(__FILE__), *%w{ .. lib })
4
+ $LOAD_PATH.unshift File.join(__dir__, "..", "lib")
4
5
 
5
6
  require "mercenary"
6
7
 
@@ -9,13 +10,11 @@ require "mercenary"
9
10
  # be output to STDOUT.
10
11
 
11
12
  Mercenary.program(:trace) do |p|
12
-
13
13
  p.version "2.0.1"
14
- p.description 'An example of traces in Mercenary'
15
- p.syntax 'trace <subcommand>'
14
+ p.description "An example of traces in Mercenary"
15
+ p.syntax "trace <subcommand>"
16
16
 
17
17
  p.action do |_, _|
18
- raise ArgumentError.new("YOU DID SOMETHING TERRIBLE YOU BUFFOON")
18
+ raise ArgumentError, "YOU DID SOMETHING TERRIBLE YOU BUFFOON"
19
19
  end
20
-
21
20
  end
@@ -1,12 +1,14 @@
1
- require File.expand_path("../mercenary/version", __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path("mercenary/version", __dir__)
2
4
  require "optparse"
3
5
  require "logger"
4
6
 
5
7
  module Mercenary
6
- autoload :Command, File.expand_path("../mercenary/command", __FILE__)
7
- autoload :Option, File.expand_path("../mercenary/option", __FILE__)
8
- autoload :Presenter, File.expand_path("../mercenary/presenter", __FILE__)
9
- autoload :Program, File.expand_path("../mercenary/program", __FILE__)
8
+ autoload :Command, File.expand_path("mercenary/command", __dir__)
9
+ autoload :Option, File.expand_path("mercenary/option", __dir__)
10
+ autoload :Presenter, File.expand_path("mercenary/presenter", __dir__)
11
+ autoload :Program, File.expand_path("mercenary/program", __dir__)
10
12
 
11
13
  # Public: Instantiate a new program and execute.
12
14
  #
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: false
2
+
1
3
  module Mercenary
2
4
  class Command
3
5
  attr_reader :name
@@ -47,9 +49,7 @@ module Mercenary
47
49
  def syntax(syntax = nil)
48
50
  @syntax = syntax if syntax
49
51
  syntax_list = []
50
- if parent
51
- syntax_list << parent.syntax.to_s.gsub(/<[\w\s-]+>/, '').gsub(/\[[\w\s-]+\]/, '').strip
52
- end
52
+ syntax_list << parent.syntax.to_s.gsub(%r!<[\w\s-]+>!, "").gsub(%r!\[[\w\s-]+\]!, "").strip if parent
53
53
  syntax_list << (@syntax || name.to_s)
54
54
  syntax_list.join(" ")
55
55
  end
@@ -72,11 +72,11 @@ module Mercenary
72
72
  # Returns the default command if there is one, `nil` otherwise
73
73
  def default_command(command_name = nil)
74
74
  if command_name
75
- if commands.has_key?(command_name)
75
+ if commands.key?(command_name)
76
76
  @default_command = commands[command_name] if command_name
77
77
  @default_command
78
78
  else
79
- raise ArgumentError.new("'#{command_name}' couldn't be found in this command's list of commands.")
79
+ raise ArgumentError, "'#{command_name}' couldn't be found in this command's list of commands."
80
80
  end
81
81
  else
82
82
  @default_command
@@ -133,11 +133,12 @@ module Mercenary
133
133
  # level - the logger level (a Logger constant, see docs for more info)
134
134
  #
135
135
  # Returns the instance of Logger
136
+
136
137
  def logger(level = nil)
137
138
  unless @logger
138
139
  @logger = Logger.new(STDOUT)
139
140
  @logger.level = level || Logger::INFO
140
- @logger.formatter = proc do |severity, datetime, progname, msg|
141
+ @logger.formatter = proc do |severity, _datetime, _progname, msg|
141
142
  "#{identity} | " << "#{severity.downcase.capitalize}:".ljust(7) << " #{msg}\n"
142
143
  end
143
144
  end
@@ -189,15 +190,15 @@ module Mercenary
189
190
  #
190
191
  # Returns nothing
191
192
  def add_default_options(opts)
192
- option 'show_help', '-h', '--help', 'Show this message'
193
- option 'show_version', '-v', '--version', 'Print the name and version'
194
- option 'show_backtrace', '-t', '--trace', 'Show the full backtrace when an error occurs'
193
+ option "show_help", "-h", "--help", "Show this message"
194
+ option "show_version", "-v", "--version", "Print the name and version"
195
+ option "show_backtrace", "-t", "--trace", "Show the full backtrace when an error occurs"
195
196
  opts.on("-v", "--version", "Print the version") do
196
197
  puts "#{name} #{version}"
197
198
  exit(0)
198
199
  end
199
200
 
200
- opts.on('-t', '--trace', 'Show full backtrace if an error occurs') do
201
+ opts.on("-t", "--trace", "Show full backtrace if an error occurs") do
201
202
  @trace = true
202
203
  end
203
204
 
@@ -228,7 +229,7 @@ module Mercenary
228
229
  # Returns true if this command is the parent of a command of name
229
230
  # 'sub_command' and false otherwise
230
231
  def has_command?(sub_command)
231
- commands.keys.include?(sub_command)
232
+ commands.key?(sub_command)
232
233
  end
233
234
 
234
235
  # Public: Identify this command
@@ -242,7 +243,7 @@ module Mercenary
242
243
  #
243
244
  # Returns a string containing the name and version if it exists
244
245
  def identity
245
- "#{full_name} #{version if version}".strip
246
+ "#{full_name} #{version}".strip
246
247
  end
247
248
 
248
249
  # Public: Get the name of the current command plus that of
@@ -251,7 +252,7 @@ module Mercenary
251
252
  # Returns the full name of the command
252
253
  def full_name
253
254
  the_name = []
254
- the_name << parent.full_name if parent && parent.full_name
255
+ the_name << parent.full_name if parent&.full_name
255
256
  the_name << name
256
257
  the_name.join(" ")
257
258
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercenary
2
4
  class Option
3
5
  attr_reader :config_key, :description, :short, :long, :return_type
@@ -11,10 +13,10 @@ module Mercenary
11
13
  #
12
14
  # Returns nothing
13
15
  def initialize(config_key, info)
14
- @config_key = config_key
16
+ @config_key = config_key
15
17
  while arg = info.shift
16
18
  begin
17
- @return_type = Object.const_get("#{arg}")
19
+ @return_type = Object.const_get(arg.to_s)
18
20
  next
19
21
  rescue NameError
20
22
  end
@@ -34,7 +36,7 @@ module Mercenary
34
36
  #
35
37
  # Returns the array which OptionParser#on wants
36
38
  def for_option_parser
37
- [short, long, return_type, description].flatten.reject{ |o| o.to_s.empty? }
39
+ [short, long, return_type, description].flatten.reject { |o| o.to_s.empty? }
38
40
  end
39
41
 
40
42
  # Public: Build a string representation of this option including the
@@ -51,8 +53,8 @@ module Mercenary
51
53
  def formatted_switches
52
54
  [
53
55
  switches.first.rjust(10),
54
- switches.last.ljust(13)
55
- ].join(", ").gsub(/ , /, ' ').gsub(/, /, ' ')
56
+ switches.last.ljust(13),
57
+ ].join(", ").gsub(%r! , !, " ").gsub(%r!, !, " ")
56
58
  end
57
59
 
58
60
  # Public: Hash based on the hash value of instance variables
@@ -70,6 +72,7 @@ module Mercenary
70
72
  # Returns true if all the instance variables are equal, false otherwise
71
73
  def eql?(other)
72
74
  return false unless self.class.eql?(other.class)
75
+
73
76
  instance_variables.map do |var|
74
77
  instance_variable_get(var).eql?(other.instance_variable_get(var))
75
78
  end.all?
@@ -82,6 +85,5 @@ module Mercenary
82
85
  def switches
83
86
  [short, long].map(&:to_s)
84
87
  end
85
-
86
88
  end
87
89
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercenary
2
4
  class Presenter
3
5
  attr_accessor :command
@@ -23,12 +25,16 @@ module Mercenary
23
25
  # Returns the string representation of the options
24
26
  def options_presentation
25
27
  return nil unless command_options_presentation || parent_command_options_presentation
28
+
26
29
  [command_options_presentation, parent_command_options_presentation].compact.join("\n")
27
30
  end
28
31
 
29
32
  def command_options_presentation
30
- return nil unless command.options.size > 0
31
- command.options.map(&:to_s).join("\n")
33
+ return nil if command.options.empty?
34
+
35
+ options = command.options
36
+ options -= command.parent.options if command.parent
37
+ options.map(&:to_s).join("\n")
32
38
  end
33
39
 
34
40
  # Public: Builds a string representation of the options for parent
@@ -37,6 +43,7 @@ module Mercenary
37
43
  # Returns the string representation of the options for parent commands
38
44
  def parent_command_options_presentation
39
45
  return nil unless command.parent
46
+
40
47
  Presenter.new(command.parent).options_presentation
41
48
  end
42
49
 
@@ -44,7 +51,8 @@ module Mercenary
44
51
  #
45
52
  # Returns the string representation of the subcommands
46
53
  def subcommands_presentation
47
- return nil unless command.commands.size > 0
54
+ return nil if command.commands.empty?
55
+
48
56
  command.commands.values.uniq.map(&:summarize).join("\n")
49
57
  end
50
58
 
@@ -52,7 +60,7 @@ module Mercenary
52
60
  #
53
61
  # Returns the command header as a String
54
62
  def command_header
55
- header = "#{command.identity}"
63
+ header = command.identity.to_s
56
64
  header << " -- #{command.description}" if command.description
57
65
  header
58
66
  end
@@ -83,11 +91,12 @@ module Mercenary
83
91
  #
84
92
  # Returns the value of whatever function is called
85
93
  def method_missing(meth, *args, &block)
86
- if meth.to_s =~ /^print_(.+)$/
87
- send("#{$1.downcase}_presentation")
94
+ if meth.to_s =~ %r!^print_(.+)$!
95
+ send("#{Regexp.last_match(1).downcase}_presentation")
88
96
  else
89
- super # You *must* call super if you don't handle the method,
90
- # otherwise you'll mess up Ruby's method lookup.
97
+ # You *must* call super if you don't handle the method,
98
+ # otherwise you'll mess up Ruby's method lookup.
99
+ super
91
100
  end
92
101
  end
93
102
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercenary
2
4
  class Program < Command
3
5
  attr_reader :optparse
@@ -31,7 +33,7 @@ module Mercenary
31
33
  @optparse.parse!(argv)
32
34
  rescue OptionParser::InvalidOption => e
33
35
  logger.error "Whoops, we can't understand your command."
34
- logger.error "#{e.message}"
36
+ logger.error e.message.to_s
35
37
  logger.error "Run your command again with the --help switch to see available options."
36
38
  abort
37
39
  end
@@ -40,7 +42,7 @@ module Mercenary
40
42
 
41
43
  begin
42
44
  cmd.execute(argv, @config)
43
- rescue => e
45
+ rescue StandardError => e
44
46
  if cmd.trace
45
47
  raise e
46
48
  else
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercenary
2
- VERSION = "0.3.6"
4
+ VERSION = "0.4.0"
3
5
  end
@@ -1,24 +1,28 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("lib", __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'mercenary/version'
5
+ require "mercenary/version"
5
6
 
6
7
  Gem::Specification.new do |spec|
7
8
  spec.name = "mercenary"
8
9
  spec.version = Mercenary::VERSION
9
10
  spec.authors = ["Tom Preston-Werner", "Parker Moore"]
10
11
  spec.email = ["tom@mojombo.com", "parkrmoore@gmail.com"]
11
- spec.description = %q{Lightweight and flexible library for writing command-line apps in Ruby.}
12
- spec.summary = %q{Lightweight and flexible library for writing command-line apps in Ruby.}
12
+ spec.description = "Lightweight and flexible library for writing command-line apps in Ruby."
13
+ spec.summary = "Lightweight and flexible library for writing command-line apps in Ruby."
13
14
  spec.homepage = "https://github.com/jekyll/mercenary"
14
15
  spec.license = "MIT"
15
16
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ spec.executables = spec.files.grep(%r!^bin/!) { |f| File.basename(f) }
19
+ spec.test_files = spec.files.grep(%r!^(test|spec|features)/!)
19
20
  spec.require_paths = ["lib"]
20
21
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.required_ruby_version = ">= 2.4.0"
23
+
24
+ spec.add_development_dependency "bundler"
22
25
  spec.add_development_dependency "rake"
23
26
  spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "rubocop-jekyll", "~> 0.10.0"
24
28
  end
@@ -3,4 +3,5 @@
3
3
  set -ex
4
4
 
5
5
  bundle exec rspec
6
- ./script/examples
6
+ script/fmt
7
+ script/examples
@@ -0,0 +1,4 @@
1
+ #!/bin/bash
2
+
3
+ echo "Rubocop $(bundle exec rubocop --version)"
4
+ bundle exec rubocop -S -D -E $@
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe(Mercenary::Command) do
4
-
5
6
  context "a basic command" do
6
7
  let(:command) { Mercenary::Command.new(:my_name) }
7
8
  let(:parent) { Mercenary::Command.new(:my_parent) }
@@ -17,7 +18,7 @@ describe(Mercenary::Command) do
17
18
  )
18
19
  end
19
20
  let(:add_sub) do
20
- Proc.new do |c|
21
+ proc do |c|
21
22
  c.command(:sub_command) { |p| }
22
23
  end
23
24
  end
@@ -56,7 +57,7 @@ describe(Mercenary::Command) do
56
57
 
57
58
  it "can set its options" do
58
59
  name = "show_drafts"
59
- opts = ['--drafts', 'Render posts in the _drafts folder']
60
+ opts = ["--drafts", "Render posts in the _drafts folder"]
60
61
  option = Mercenary::Option.new(name, opts)
61
62
  command.option name, *opts
62
63
  expect(command.options).to eql([option])
@@ -68,7 +69,7 @@ describe(Mercenary::Command) do
68
69
  end
69
70
 
70
71
  it "knows its identity" do
71
- command_with_parent.version '1.8.7'
72
+ command_with_parent.version "1.8.7"
72
73
  expect(command_with_parent.identity).to eql("my_parent i_have_parent 1.8.7")
73
74
  end
74
75
 
@@ -94,5 +95,4 @@ describe(Mercenary::Command) do
94
95
  end
95
96
  end
96
97
  end
97
-
98
98
  end
@@ -1,9 +1,11 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe(Mercenary::Option) do
4
6
  let(:config_key) { "largo" }
5
7
  let(:description) { "This is a description" }
6
- let(:switches) { ['-l', '--largo'] }
8
+ let(:switches) { ["-l", "--largo"] }
7
9
  let(:option) { described_class.new(config_key, [switches, description].flatten.reject(&:nil?)) }
8
10
 
9
11
  it "knows its config key" do
@@ -27,20 +29,20 @@ describe(Mercenary::Option) do
27
29
  end
28
30
 
29
31
  it "compares itself with other options well" do
30
- new_option = described_class.new(config_key, ['-l', '--largo', description])
32
+ new_option = described_class.new(config_key, ["-l", "--largo", description])
31
33
  expect(option.eql?(new_option)).to be(true)
32
34
  expect(option.hash.eql?(new_option.hash)).to be(true)
33
35
  end
34
36
 
35
37
  it "has a custom #hash" do
36
- expect(option.hash.to_s).to match(/\d+/)
38
+ expect(option.hash.to_s).to match(%r!\d+!)
37
39
  end
38
40
 
39
41
  context "with just the long switch" do
40
- let(:switches) { ['--largo'] }
42
+ let(:switches) { ["--largo"] }
41
43
 
42
44
  it "adds an empty string in place of the short switch" do
43
- expect(option.switches).to eql(['', '--largo'])
45
+ expect(option.switches).to eql(["", "--largo"])
44
46
  end
45
47
 
46
48
  it "sets its description properly" do
@@ -53,10 +55,10 @@ describe(Mercenary::Option) do
53
55
  end
54
56
 
55
57
  context "with just the short switch" do
56
- let(:switches) { ['-l'] }
58
+ let(:switches) { ["-l"] }
57
59
 
58
60
  it "adds an empty string in place of the long switch" do
59
- expect(option.switches).to eql(['-l', ''])
61
+ expect(option.switches).to eql(["-l", ""])
60
62
  end
61
63
 
62
64
  it "sets its description properly" do
@@ -79,5 +81,4 @@ describe(Mercenary::Option) do
79
81
  expect(option.switches).to eql(switches)
80
82
  end
81
83
  end
82
-
83
84
  end
@@ -1,4 +1,6 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe(Mercenary::Presenter) do
4
6
  let(:supercommand) { Mercenary::Command.new(:script_name) }
@@ -6,16 +8,20 @@ describe(Mercenary::Presenter) do
6
8
  let(:presenter) { described_class.new(command) }
7
9
 
8
10
  before(:each) do
9
- command.version '1.4.2'
10
- command.description 'Do all the things.'
11
- command.option 'one', '-1', '--one', 'The first option'
12
- command.option 'two', '-2', '--two', 'The second option'
11
+ supercommand.option "version", "-v", "--version", "Show version"
12
+ supercommand.option "help", "-h", "--help", "Help!"
13
+
14
+ command.version "1.4.2"
15
+ command.description "Do all the things."
16
+ command.option "help", "-h", "--help", "Help!"
17
+ command.option "one", "-1", "--one", "The first option"
18
+ command.option "two", "-2", "--two", "The second option"
13
19
  command.alias :cmd
14
20
  supercommand.commands[command.name] = command
15
21
  end
16
22
 
17
23
  it "knows how to present the command" do
18
- expect(presenter.command_presentation).to eql("script_name subcommand 1.4.2 -- Do all the things.\n\nUsage:\n\n script_name subcommand\n\nOptions:\n -1, --one The first option\n -2, --two The second option")
24
+ expect(presenter.command_presentation).to eql("script_name subcommand 1.4.2 -- Do all the things.\n\nUsage:\n\n script_name subcommand\n\nOptions:\n -1, --one The first option\n -2, --two The second option\n -v, --version Show version\n -h, --help Help!")
19
25
  end
20
26
 
21
27
  it "knows how to present the subcommands, without duplicates for aliases" do
@@ -27,7 +33,7 @@ describe(Mercenary::Presenter) do
27
33
  end
28
34
 
29
35
  it "knows how to present the options" do
30
- expect(presenter.options_presentation).to eql(" -1, --one The first option\n -2, --two The second option")
36
+ expect(presenter.options_presentation).to eql(" -1, --one The first option\n -2, --two The second option\n -v, --version Show version\n -h, --help Help!")
31
37
  end
32
38
 
33
39
  it "allows you to say print_* instead of *_presentation" do
@@ -1,7 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spec_helper"
2
4
 
3
5
  describe(Mercenary::Program) do
4
-
5
6
  context "a basic program" do
6
7
  let(:program) { Mercenary::Program.new(:my_name) }
7
8
 
@@ -15,5 +16,4 @@ describe(Mercenary::Program) do
15
16
  expect(program.version).to eq(version)
16
17
  end
17
18
  end
18
-
19
19
  end
@@ -1,6 +1,8 @@
1
- lib = File.expand_path('../../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path("../lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require 'mercenary'
5
+ require "mercenary"
4
6
 
5
7
  RSpec.configure do |config|
6
8
  config.run_all_when_everything_filtered = true
@@ -10,5 +12,5 @@ RSpec.configure do |config|
10
12
  # order dependency and want to debug it, you can fix the order by providing
11
13
  # the seed, which is printed after each run.
12
14
  # --seed 1234
13
- config.order = 'random'
15
+ config.order = "random"
14
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mercenary
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.6
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-04-08 00:00:00.000000000 Z
12
+ date: 2020-01-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - "~>"
18
+ - - ">="
19
19
  - !ruby/object:Gem::Version
20
- version: '1.3'
20
+ version: '0'
21
21
  type: :development
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - "~>"
25
+ - - ">="
26
26
  - !ruby/object:Gem::Version
27
- version: '1.3'
27
+ version: '0'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement
@@ -53,6 +53,20 @@ dependencies:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '3.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rubocop-jekyll
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 0.10.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 0.10.0
56
70
  description: Lightweight and flexible library for writing command-line apps in Ruby.
57
71
  email:
58
72
  - tom@mojombo.com
@@ -63,6 +77,8 @@ extra_rdoc_files: []
63
77
  files:
64
78
  - ".gitignore"
65
79
  - ".rspec"
80
+ - ".rubocop.yml"
81
+ - ".rubocop_todo.yml"
66
82
  - ".travis.yml"
67
83
  - Gemfile
68
84
  - History.markdown
@@ -83,6 +99,7 @@ files:
83
99
  - script/cibuild
84
100
  - script/console
85
101
  - script/examples
102
+ - script/fmt
86
103
  - spec/command_spec.rb
87
104
  - spec/option_spec.rb
88
105
  - spec/presenter_spec.rb
@@ -100,15 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
100
117
  requirements:
101
118
  - - ">="
102
119
  - !ruby/object:Gem::Version
103
- version: '0'
120
+ version: 2.4.0
104
121
  required_rubygems_version: !ruby/object:Gem::Requirement
105
122
  requirements:
106
123
  - - ">="
107
124
  - !ruby/object:Gem::Version
108
125
  version: '0'
109
126
  requirements: []
110
- rubyforge_project:
111
- rubygems_version: 2.5.1
127
+ rubygems_version: 3.0.6
112
128
  signing_key:
113
129
  specification_version: 4
114
130
  summary: Lightweight and flexible library for writing command-line apps in Ruby.