Skip to content

Commit

Permalink
Fixing args expansion for Ruby 3.0.0 (#32)
Browse files Browse the repository at this point in the history
* Fixing args expansion for Ruby 3.0.0

* Rubocop changes
  • Loading branch information
kigster authored Feb 12, 2021
1 parent 2459414 commit bf59ebe
Show file tree
Hide file tree
Showing 46 changed files with 500 additions and 285 deletions.
20 changes: 18 additions & 2 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
inherit_from: .rubocop_todo.yml

inherit_gem:
relaxed-rubocop: .rubocop.yml

require:
- rubocop-rspec
- rubocop-rake

AllCops:
TargetRubyVersion: 2.3
NewCops: enable
TargetRubyVersion: 2.6

Style/Alias:
Enabled: false
Expand Down Expand Up @@ -47,6 +54,10 @@ Style/FormatString:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleformatstring

Style/StringConcatenation:
Enabled: false


Style/IfUnlessModifier:
Enabled: false
StyleGuide: https://relaxed.ruby.style/#styleifunlessmodifier
Expand Down Expand Up @@ -223,7 +234,7 @@ Style/BarePercentLiterals:
Style/FormatStringToken:
Enabled: false

Style/MethodMissingSuper:
Lint/MissingSuper:
Enabled: false

Style/MissingRespondToMissing:
Expand Down Expand Up @@ -376,3 +387,8 @@ Style/HashTransformKeys:
Style/HashTransformValues:
Enabled: true

Lint/ConstantDefinitionInBlock:
Enabled: false

Lint/Debugger:
Enabled: false
115 changes: 115 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2021-02-12 15:04:35 UTC using RuboCop version 1.9.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 6
RSpec/AnyInstance:
Exclude:
- 'spec/sym/app/cli_spec.rb'
- 'spec/sym/app/password/providers_spec.rb'

# Offense count: 97
# Configuration parameters: Prefixes.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 5
# Configuration parameters: Max.
RSpec/ExampleLength:
Exclude:
- 'spec/sym/app/cli_spec.rb'
- 'spec/sym/app/commands_spec.rb'
- 'spec/sym/app/input/handler_spec.rb'
- 'spec/sym/app/password/cache_spec.rb'
- 'spec/sym/sym_spec.rb'

# Offense count: 20
RSpec/ExpectInHook:
Exclude:
- 'spec/sym/app/cli_spec.rb'
- 'spec/sym/app/commands/print_key_spec.rb'
- 'spec/sym/app/password/providers_spec.rb'
- 'spec/sym/app/private_key/detector_spec.rb'
- 'spec/sym/app/private_key/handler_spec.rb'
- 'spec/sym/application_spec.rb'
- 'spec/sym/magic_file_spec.rb'

# Offense count: 11
RSpec/LeakyConstantDeclaration:
Exclude:
- 'spec/integration/sym_cli_spec.rb'
- 'spec/support/contexts.rb'
- 'spec/sym/app/cli_spec.rb'
- 'spec/sym/app/keychain_spec.rb'

# Offense count: 1
RSpec/LetSetup:
Exclude:
- 'spec/sym/app/cli_spec.rb'

# Offense count: 20
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 36
RSpec/MultipleExpectations:
Max: 6

# Offense count: 14
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 9

# Offense count: 11
# Configuration parameters: IgnoreSharedExamples.
RSpec/NamedSubject:
Exclude:
- 'spec/sym/app/commands_spec.rb'
- 'spec/sym/app/password/providers_spec.rb'

# Offense count: 10
RSpec/NestedGroups:
Max: 6

# Offense count: 1
RSpec/OverwritingSetup:
Exclude:
- 'spec/sym/app/commands/generate_key_spec.rb'

# Offense count: 12
RSpec/RepeatedDescription:
Exclude:
- 'spec/sym/app/commands_spec.rb'
- 'spec/sym/app/password/providers_spec.rb'

# Offense count: 2
RSpec/RepeatedExampleGroupDescription:
Exclude:
- 'spec/sym/app/password/providers_spec.rb'

# Offense count: 2
RSpec/ScatteredSetup:
Exclude:
- 'spec/integration/sym_cli_spec.rb'

# Offense count: 10
RSpec/StubbedMock:
Exclude:
- 'spec/support/contexts.rb'
- 'spec/sym/app/cli_spec.rb'
- 'spec/sym/app/commands/print_key_spec.rb'
- 'spec/sym/app/input/handler_spec.rb'
- 'spec/sym/app/private_key/detector_spec.rb'
- 'spec/sym/application_spec.rb'

# Offense count: 4
Rake/Desc:
Exclude:
- 'Rakefile'
7 changes: 6 additions & 1 deletion README.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
= *sym*_Symmetric Encryption for Humans_
= **Sym**_Symmetric Encryption for Humans_
:source-highlighter: rouge
:rouge-style: base16.monokai
:icons: font
:toc:
:sectnum:
:toclevel: 4
Expand Down Expand Up @@ -47,6 +50,8 @@ Additionally, Sym comes with a helpful BASH wrapper `symit`.

== Supported Ruby Versions

NOTE: Ruby 3.0.0 is only supported by Sym version 3.0.1 and later.

Sym currently builds and runs on the following ruby versions on Travis CI:

.Ruby Version Compatibility
Expand Down
4 changes: 2 additions & 2 deletions exe/keychain
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env ruby

lib_path = File.expand_path(File.dirname(__FILE__) + '/../lib')
lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$LOAD_PATH << lib_path if File.exist?(lib_path) && !$LOAD_PATH.include?(lib_path)

require 'sym'
Expand All @@ -9,7 +9,7 @@ require 'sym/app/keychain'
require 'colored2'

def usage
puts 'Usage: ' + 'keychain'.bold.blue + ' name [ add <contents> | find | delete ]'.bold.green
puts "Usage: #{'keychain'.bold.blue}#{' name [ add <contents> | find | delete ]'.bold.green}"
exit 0
end

Expand Down
6 changes: 3 additions & 3 deletions exe/sym
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

require_relative '../lib/ruby_warnings'

lib_path = File.expand_path(File.dirname(__FILE__) + '/../lib')
lib_path = File.expand_path("#{File.dirname(__FILE__)}/../lib")
$LOAD_PATH << lib_path if File.exist?(lib_path) && !$LOAD_PATH.include?(lib_path)

require 'sym'
Expand All @@ -13,9 +13,9 @@ require 'sym/app'
begin
exit ::Sym::App::CLI.new(ARGV.dup).execute
rescue Interrupt => e
STDERR.flush
$stderr.flush
warn "Interrupt, #{e.message}, exiting."
STDERR.flush
$stderr.flush
exit 1
end

Expand Down
13 changes: 6 additions & 7 deletions lib/sym/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ module Sym
#
module App
class << self
attr_accessor :exit_code
attr_accessor :stdin, :stdout, :stderr
attr_accessor :exit_code, :stdin, :stdout, :stderr
end

self.exit_code = 0

self.stdin = STDIN
self.stdout = STDOUT
self.stderr = STDERR
self.stdin = $stdin
self.stdout = $stdout
self.stderr = $stderr

def self.out
self.stderr
Expand All @@ -44,7 +43,7 @@ def self.error(config: {},

lines = []

error_type = "#{(type || exception.class.name)}"
error_type = "#{type || exception.class.name}"
error_details = (details || exception.message)

operation = command ? "to #{command.class.short_name.to_s.humanize.downcase}" : ''
Expand All @@ -55,7 +54,7 @@ def self.error(config: {},
lines << exception.backtrace.join("\n").red.bold if config[:trace]
lines << "\n"
else
lines << " ✖ Sym Error #{operation}:".bold.red + (reason ? " #{reason} ".red.italic: " #{error_details}")[0..70] + ' '.normal + "\n"
lines << "#{" ✖ Sym Error #{operation}:".bold.red}#{(reason ? " #{reason} ".red.italic: " #{error_details}")[0..70]}#{' '.normal}\n"
lines << "#{comments}" if comments
end

Expand Down
8 changes: 3 additions & 5 deletions lib/sym/app/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class CLI

attr_accessor :opts, :application, :outputs, :stdin, :stdout, :stderr, :kernel, :args

def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = nil)
def initialize(argv, stdin = $stdin, stdout = $stdout, stderr = $stderr, kernel = nil)
self.args = argv
self.stdin = stdin
self.stdout = stdout
Expand All @@ -79,15 +79,13 @@ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = n
end

# Deal with SYM_ARGS and -A
if opts[:sym_args]
if non_empty_array?(sym_args)
if opts[:sym_args] && non_empty_array?(sym_args)
args << sym_args
args.flatten!
args.compact!
args.delete('-A')
args.delete('--sym-args')
self.opts = parse(args)
end
end

# Disable coloring if requested, or if piping STDOUT
Expand All @@ -99,7 +97,7 @@ def initialize(argv, stdin = STDIN, stdout = STDOUT, stderr = STDERR, kernel = n
rescue StandardError => e
log :error, "#{e.message}" if opts
error exception: e
quit!(127) if stdin == STDIN
quit!(127) if stdin == $stdin
end

self.application = ::Sym::Application.new(self.opts, stdin, stdout, stderr, kernel)
Expand Down
19 changes: 9 additions & 10 deletions lib/sym/app/cli_slop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def parse(arguments)
o.separator ' 5) use -i to paste/type the key interactively'.dark
o.separator ' 6) default key file (if present) at '.dark + Sym.default_key_file.magenta.bold
o.separator ' '
o.separator ' ' + key_spec + ' = -k/--key [ key | file | keychain | env variable name ]'.green.bold
o.separator " #{key_spec}#{' = -k/--key [ key | file | keychain | env variable name ]'.green.bold}"
o.separator ' -i/--interactive'.green.bold
o.separator ''
o.separator ' Encrypt/Decrypt from STDIN/file/args, to STDOUT/file:'.dark
Expand Down Expand Up @@ -48,7 +48,7 @@ def parse(arguments)
o.separator 'Modes:'.yellow
o.bool '-e', '--encrypt', ' encrypt mode'
o.bool '-d', '--decrypt', ' decrypt mode'
o.string '-t', '--edit', '[file] '.blue + ' edit encrypted file in an $EDITOR', default: nil
o.string '-t', '--edit', "#{'[file] '.blue} edit encrypted file in an $EDITOR", default: nil
o.string '-n', '--negate', '[file] '.blue + " encrypts any regular #{'file'.green} into #{'file.enc'.green}" + "\n" +
" conversely decrypts #{'file.enc'.green} into #{'file'.green}."
o.separator ' '
Expand All @@ -57,25 +57,25 @@ def parse(arguments)
o.bool '-p', '--password', ' encrypt the key with a password'

if Sym::App.osx?
o.string '-x', '--keychain', '[key-name] '.blue + 'write the key to OS-X Keychain'
o.string '-x', '--keychain', "#{'[key-name] '.blue}write the key to OS-X Keychain"
end

o.separator ' '
o.separator 'Read existing private key from:'.yellow
o.string '-k', '--key', '[key-spec]'.blue + ' private key, key file, or keychain'
o.string '-k', '--key', "#{'[key-spec]'.blue} private key, key file, or keychain"
o.bool '-i', '--interactive', ' Paste or type the key interactively'

o.separator ' '
o.separator 'Password Cache:'.yellow
o.bool '-c', '--cache-passwords', ' enable password cache'
o.integer '-z', '--cache-timeout', '[seconds]'.blue + ' expire passwords after'
o.integer '-z', '--cache-timeout', "#{'[seconds]'.blue} expire passwords after"
o.string '-r', '--cache-provider', '[provider]'.blue + ' cache provider, one of ' + "#{Sym::App::Password::Providers.provider_list}"

o.separator ' '
o.separator 'Data to Encrypt/Decrypt:'.yellow
o.string '-s', '--string', '[string]'.blue + ' specify a string to encrypt/decrypt'
o.string '-f', '--file', '[file] '.blue + ' filename to read from'
o.string '-o', '--output', '[file] '.blue + ' filename to write to'
o.string '-s', '--string', "#{'[string]'.blue} specify a string to encrypt/decrypt"
o.string '-f', '--file', "#{'[file] '.blue} filename to read from"
o.string '-o', '--output', "#{'[file] '.blue} filename to write to"

o.separator ' '
o.separator 'Flags:'.yellow
Expand All @@ -95,8 +95,7 @@ def parse(arguments)
" user home available, you may need to force set user's home to any existing\n" +
" directory using the #{'--user-home'.bold.blue} flag.\n"

o.string '-B', '--bash-support', '[file]'.blue + ' append bash completion & utils to a file'+ "\n" +
' such as ~/.bash_profile or ~/.bashrc'
o.string '-B', '--bash-support', "#{'[file]'.blue} append bash completion & utils to a file\n such as ~/.bash_profile or ~/.bashrc"
o.string '-u', '--user-home', '[DIR]'.blue + " Overrides #{'${HOME}'.green} ==> supports AWS Lambda\n"

o.separator ' '
Expand Down
1 change: 1 addition & 0 deletions lib/sym/app/commands/base_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def options_satisfied_by?(opts_hash)
extend Forwardable

attr_accessor :application

def_delegators :@application, :opts, :opts_slop, :key, :stdin, :stdout, :stderr, :kernel

def initialize(application)
Expand Down
2 changes: 1 addition & 1 deletion lib/sym/app/commands/bash_completion.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def execute

def append_completion_script(file, script)
File.open(file, 'a') do |fd|
fd.write(script + "\n")
fd.write("#{script}\n")
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/sym/app/commands/keychain_add_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class KeychainAddKey < BaseCommand

def execute
if Sym.default_key? && Sym.default_key == self.key
raise 'Refusing to import key specified in the default key file ' + Sym.default_key_file.italic
raise "Refusing to import key specified in the default key file #{Sym.default_key_file.italic}"
end
raise Sym::Errors::NoPrivateKeyFound.new("Unable to resolve private key from argument '#{opts[:key]}'") if self.key.nil?
add_to_keychain_if_needed(self.key)
Expand Down
Loading

0 comments on commit bf59ebe

Please sign in to comment.