Skip to content

Commit

Permalink
bump rubocop
Browse files Browse the repository at this point in the history
Signed-off-by: mwrock <matt@mattwrock.com>
  • Loading branch information
mwrock committed Oct 15, 2018
1 parent ed7f44d commit f910598
Show file tree
Hide file tree
Showing 106 changed files with 5,413 additions and 5,519 deletions.
64 changes: 38 additions & 26 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
AllCops:
Exclude:
- 'appveyor.yml'
- 'Vagrantfile'
- 'scripts/**/*'

Style/Encoding:
Enabled: true

Style/NumericLiterals:
Enabled: false

Metrics/LineLength:
Max: 100

Metrics/MethodLength:
Max: 20

ModuleLength:
Max: 250

ClassLength:
Max: 250

Metrics/AbcSize:
Max: 25
AllCops:
Exclude:
- 'appveyor.yml'
- 'Vagrantfile'
- 'scripts/**/*'

Style/Encoding:
Enabled: true

Style/NumericLiterals:
Enabled: false

Layout/EndOfLine:
Enabled: false

Layout/IndentHeredoc:
Enabled: false

Metrics/BlockLength:
Max: 200

Metrics/LineLength:
Max: 120

Metrics/MethodLength:
Max: 20

ModuleLength:
Max: 250

Naming/HeredocDelimiterNaming:
Enabled: false

ClassLength:
Max: 250

Metrics/AbcSize:
Max: 25
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: ruby
rvm:
- 2.0.0
- 2.1.0
- 2.2.0
before_install:
- gem update bundler

Expand Down
5 changes: 2 additions & 3 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
# encoding: UTF-8
source 'https://rubygems.org'
gemspec
source 'https://rubygems.org'
gemspec
67 changes: 33 additions & 34 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
# encoding: UTF-8
require 'rubygems'
require 'bundler/setup'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'bundler/gem_tasks'

# Change to the directory of this file.
Dir.chdir(File.expand_path('../', __FILE__))

desc 'Open a Pry console for this library'
task :console do
require 'pry'
require 'winrm'
ARGV.clear
Pry.start
end

RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = 'tests/spec/**/*_spec.rb'
task.rspec_opts = ['--color', '-f documentation', '-r ./tests/spec/spec_helper']
end

# Run the integration test suite
RSpec::Core::RakeTask.new(:integration) do |task|
task.pattern = 'tests/integration/*_spec.rb'
task.rspec_opts = ['--color', '-f documentation', '-r ./tests/integration/spec_helper']
end

RuboCop::RakeTask.new

task default: [:spec, :rubocop]

task all: [:default, :integration]
require 'rubygems'
require 'bundler/setup'
require 'rspec/core/rake_task'
require 'rubocop/rake_task'
require 'bundler/gem_tasks'

# Change to the directory of this file.
Dir.chdir(File.expand_path(__dir__))

desc 'Open a Pry console for this library'
task :console do
require 'pry'
require 'winrm'
ARGV.clear
Pry.start
end

RSpec::Core::RakeTask.new(:spec) do |task|
task.pattern = 'tests/spec/**/*_spec.rb'
task.rspec_opts = ['--color', '-f documentation', '-r ./tests/spec/spec_helper']
end

# Run the integration test suite
RSpec::Core::RakeTask.new(:integration) do |task|
task.pattern = 'tests/integration/*_spec.rb'
task.rspec_opts = ['--color', '-f documentation', '-r ./tests/integration/spec_helper']
end

RuboCop::RakeTask.new

task default: %i[spec rubocop]

task all: %i[default integration]
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ environment:
user_key: c:\projects\winrm\key.pem

matrix:
- ruby_version: "21"
- ruby_version: "22"
winrm_endpoint: http://localhost:5985/wsman

clone_folder: c:\projects\winrm
Expand Down
193 changes: 96 additions & 97 deletions bin/rwinrm
Original file line number Diff line number Diff line change
@@ -1,97 +1,96 @@
#!/usr/bin/env ruby
# encoding: UTF-8

# Copyright 2014 Shawn Neal <sneal@sneal.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# rubocop:disable all

$LOAD_PATH.push File.expand_path('../../lib', __FILE__)

require 'readline'
require 'io/console'
require 'winrm'

def help_msg
puts 'Usage: rwinrm user@host'
puts ''
end

def parse_options
options = {}
fail 'Missing required options' unless ARGV.length == 1

m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
fail "#{ARGV[0]} is an invalid host" unless m
options[:user] = m[:user]
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"

# Get the password
print 'Password: '
options[:pass] = STDIN.noecho(&:gets).chomp
puts

# Set some defaults required by WinRM WS
options[:auth_type] = :plaintext
options[:basic_auth_only] = true

options
rescue StandardError => e
puts e.message
help_msg
exit 1
end

def repl(options)
client = WinRM::WinRMWebService.new(
options[:endpoint],
options[:auth_type].to_sym,
options)

client.set_timeout(3600)
shell_id = client.open_shell
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")

read_thread = Thread.new do
client.get_command_output(shell_id, command_id) do |stdout, stderr|
STDOUT.write stdout
STDERR.write stderr
end
end
read_thread.abort_on_exception = true

while (buf = Readline.readline('', true))
if buf =~ /^exit/
read_thread.exit
client.cleanup_command(shell_id, command_id)
client.close_shell(shell_id)
exit 0
else
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
end
end
rescue Interrupt
puts 'exiting'
# ctrl-c
rescue WinRM::WinRMAuthorizationError
puts 'Authentication failed, bad user name or password'
exit 1
rescue StandardError => e
puts e.message
exit 1
end

repl(parse_options)

# rubocop:enable all
#!/usr/bin/env ruby

# Copyright 2014 Shawn Neal <sneal@sneal.net>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# rubocop:disable all

$LOAD_PATH.push File.expand_path('../../lib', __FILE__)

require 'readline'
require 'io/console'
require 'winrm'

def help_msg
puts 'Usage: rwinrm user@host'
puts ''
end

def parse_options
options = {}
fail 'Missing required options' unless ARGV.length == 1

m = /^(?<user>[a-z0-9\.\!\$ _-]+)@{1}(?<host>[a-z0-9\.\-]+)(?<port>:[0-9]+)?/i.match(ARGV[0])
fail "#{ARGV[0]} is an invalid host" unless m
options[:user] = m[:user]
options[:endpoint] = "http://#{m[:host]}#{m[:port] || ':5985'}/wsman"

# Get the password
print 'Password: '
options[:pass] = STDIN.noecho(&:gets).chomp
puts

# Set some defaults required by WinRM WS
options[:auth_type] = :plaintext
options[:basic_auth_only] = true

options
rescue StandardError => e
puts e.message
help_msg
exit 1
end

def repl(options)
client = WinRM::WinRMWebService.new(
options[:endpoint],
options[:auth_type].to_sym,
options)

client.set_timeout(3600)
shell_id = client.open_shell
command_id = client.run_command(shell_id, 'cmd', "/K prompt [#{ARGV[0]}]$P$G")

read_thread = Thread.new do
client.get_command_output(shell_id, command_id) do |stdout, stderr|
STDOUT.write stdout
STDERR.write stderr
end
end
read_thread.abort_on_exception = true

while (buf = Readline.readline('', true))
if buf =~ /^exit/
read_thread.exit
client.cleanup_command(shell_id, command_id)
client.close_shell(shell_id)
exit 0
else
client.write_stdin(shell_id, command_id, "#{buf}\r\n")
end
end
rescue Interrupt
puts 'exiting'
# ctrl-c
rescue WinRM::WinRMAuthorizationError
puts 'Authentication failed, bad user name or password'
exit 1
rescue StandardError => e
puts e.message
exit 1
end

repl(parse_options)

# rubocop:enable all
Loading

0 comments on commit f910598

Please sign in to comment.