Skip to content

Commit

Permalink
Fix RuboCop issues
Browse files Browse the repository at this point in the history
  • Loading branch information
timriley committed Aug 7, 2023
1 parent 2a0aa19 commit b602a69
Show file tree
Hide file tree
Showing 16 changed files with 26 additions and 32 deletions.
6 changes: 1 addition & 5 deletions lib/dry/cli/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,7 @@ module ClassMethods

# @since 0.7.0
# @api private
attr_reader :subcommands

# @since 0.7.0
# @api private
attr_writer :subcommands
attr_accessor :subcommands
end

# Set the description of the command
Expand Down
5 changes: 3 additions & 2 deletions lib/dry/cli/command_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def set(name, command, aliases)

# @since 0.1.0
# @api private
#
# rubocop:disable Metrics/AbcSize
def get(arguments)
@_mutex.synchronize do
node = @root
Expand All @@ -56,7 +56,7 @@ def get(arguments)
result = LookupResult.new(node, args, names, false)
break
elsif tmp.leaf?
args = arguments[i + 1..-1]
args = arguments[i + 1..]
names = arguments[0..i]
node = tmp
result = LookupResult.new(node, args, names, true)
Expand All @@ -72,6 +72,7 @@ def get(arguments)
result
end
end
# rubocop:enable Metrics/AbcSize

# Node of the registry
#
Expand Down
6 changes: 3 additions & 3 deletions lib/dry/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def self.call(command, arguments, prog_name)
# @since 0.1.0
# @api private
#
# rubocop:disable Metrics/AbcSize
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
def self.parse_required_params(command, arguments, prog_name, parsed_options)
parsed_params = match_arguments(command.arguments, arguments)
parsed_required_params = match_arguments(command.required_arguments, arguments)
Expand Down Expand Up @@ -67,14 +67,14 @@ def self.parse_required_params(command, arguments, prog_name, parsed_options)
parsed_options = parsed_options.merge(args: unused_arguments) if unused_arguments.any?
Result.success(parsed_options)
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity

def self.match_arguments(command_arguments, arguments)
result = {}

command_arguments.each_with_index do |cmd_arg, index|
if cmd_arg.array?
result[cmd_arg.name] = arguments[index..-1]
result[cmd_arg.name] = arguments[index..]
break
else
result[cmd_arg.name] = arguments.at(index)
Expand Down
2 changes: 1 addition & 1 deletion spec/support/files.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
end

failure_message do |actual|
"expected that `#{actual}' would be have content '#{expected}', but it has '#{File.read(actual)}'" # rubocop:disable Metrics/LineLength
"expected that `#{actual}' would be have content '#{expected}', but it has '#{File.read(actual)}'"
end
end
2 changes: 1 addition & 1 deletion spec/support/fixtures/based
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"
require_relative "../../../lib/dry/cli/command"

Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures/baz
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"

require_relative "baz_command"
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures/foo
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# frozen_string_literal: true

# rubocop:disable Layout/LineLength
$LOAD_PATH.unshift __dir__ + "/../../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../../lib"
require "dry/cli"

module Foo
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures/infinites
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"

module Infinites
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures/inline
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../../lib"
require "dry/cli"
require_relative "../../../lib/dry/cli/inline"

Expand Down
3 changes: 1 addition & 2 deletions spec/support/fixtures/shared_commands.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/LineLength
module Commands
class Command < Dry::CLI::Command
end
Expand Down Expand Up @@ -442,6 +441,7 @@ class InitializedCommand < Dry::CLI::Command
attr_reader :prop

def initialize(prop:)
super()
@prop = prop
end

Expand Down Expand Up @@ -593,4 +593,3 @@ class Addons < Base
]
end
end
# rubocop:enable Metrics/LineLength
2 changes: 1 addition & 1 deletion spec/support/fixtures/with_block.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"
require_relative "shared_commands"

Expand Down
4 changes: 2 additions & 2 deletions spec/support/fixtures/with_registry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"
require_relative "shared_commands"

Expand Down Expand Up @@ -62,7 +62,7 @@ module Commands
register "options-with-aliases", ::Commands::OptionsWithAliases
register "variadic default", ::Commands::VariadicArguments
register "variadic with-mandatory", ::Commands::MandatoryAndVariadicArguments
register "variadic with-mandatory-and-options", ::Commands::MandatoryOptionsAndVariadicArguments # rubocop:disable Metrics/LineLength
register "variadic with-mandatory-and-options", ::Commands::MandatoryOptionsAndVariadicArguments

register "generate webpack", ::Webpack::CLI::Generate
register "hello", ::Webpack::CLI::Hello
Expand Down
2 changes: 1 addition & 1 deletion spec/support/fixtures/with_zero_arity_block.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

$LOAD_PATH.unshift __dir__ + "/../../lib"
$LOAD_PATH.unshift "#{__dir__}/../../lib"
require "dry/cli"
require_relative "shared_commands"

Expand Down
2 changes: 1 addition & 1 deletion spec/support/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def self.included(base)
base.class_eval do
before do
@original_path = ENV["PATH"]
ENV["PATH"] = __dir__ + "/fixtures:" + ENV["PATH"]
ENV["PATH"] = "#{__dir__}/fixtures:#{ENV["PATH"]}"
end

after do
Expand Down
6 changes: 2 additions & 4 deletions spec/support/shared_examples/commands.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# frozen_string_literal: true

# rubocop:disable Metrics/LineLength
RSpec.shared_examples "Commands" do |cli|
let(:cli) { cli }

Expand Down Expand Up @@ -96,7 +95,7 @@
context "and with an unknown value passed" do
it "prints error" do
error = capture_error { cli.call(arguments: %w[console --engine=unknown]) }
expect(error).to eq("ERROR: \"rspec console\" was called with arguments \"--engine=unknown\"\n") # rubocop:disable Metrics/LineLength
expect(error).to eq("ERROR: \"rspec console\" was called with arguments \"--engine=unknown\"\n")
end
end
end
Expand Down Expand Up @@ -145,7 +144,7 @@

it "with unknown param" do
error = capture_error { cli.call(arguments: %w[new bookshelf --unknown 1234]) }
expect(error).to eq("ERROR: \"rspec new\" was called with arguments \"bookshelf --unknown 1234\"\n") # rubocop:disable Metrics/LineLength
expect(error).to eq("ERROR: \"rspec new\" was called with arguments \"bookshelf --unknown 1234\"\n")
end

it "no required" do
Expand Down Expand Up @@ -297,4 +296,3 @@
end
end
end
# rubocop:enable Metrics/LineLength
10 changes: 5 additions & 5 deletions spec/support/shared_examples/subcommands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,17 +87,17 @@
end

it "more than one param and with optional params" do
output = capture_output { cli.call(arguments: %w[generate action web users#index --url=/signin]) } # rubocop:disable Metrics/LineLength
expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>false, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength
output = capture_output { cli.call(arguments: %w[generate action web users#index --url=/signin]) }
expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>false, :url=>\"/signin\"}\n")
end

it "more than one param and with boolean params" do
output = capture_output { cli.call(arguments: %w[generate action web users#index --skip-view --url=/signin]) } # rubocop:disable Metrics/LineLength
expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>true, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength
output = capture_output { cli.call(arguments: %w[generate action web users#index --skip-view --url=/signin]) }
expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>true, :url=>\"/signin\"}\n")
end

it "more than required params" do
output = capture_output { cli.call(arguments: %w[destroy action web users#index unexpected_param]) } # rubocop:disable Metrics/LineLength
output = capture_output { cli.call(arguments: %w[destroy action web users#index unexpected_param]) }
expect(output).to eq("destroy action - app: web, action: users#index\n")
end

Expand Down

0 comments on commit b602a69

Please sign in to comment.