sshmenu 0.0.2 → 0.0.3

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
2
  SHA1:
3
- metadata.gz: 253c7a7f7a0a20ee5e3fa8a6da40e498caca810e
4
- data.tar.gz: 5ed08912d8f8b1c44ab9513ff52714d17fd8a91c
3
+ metadata.gz: 8965529a56d459ff2f1e1697088fa5a5f6e31d50
4
+ data.tar.gz: b1f9a37eb1b8370506d0fcdc1bf9f92911752f65
5
5
  SHA512:
6
- metadata.gz: 3e3f9297eed4d6d9cc4dca957d728eccb0008a782d95803f2564cb3e6fd57917422931e89967bd7298754b9f359aaf84c4c3d9519ed86f97f6a00e8f722591d6
7
- data.tar.gz: ebc336f8a2453eb468bff10a6bcb956f2d166129059e9dde84a5de44afcf6536641c4c18ed595ee9a9006546eecfd3d6269fdd83b9993a2b1d26f0f259371431
6
+ metadata.gz: bb309e44d8c81ac1bfd58c40ef3d49d3e5eb6098610f4efb947a7115f3db95021c44f1af6517effdb973417834c65435eb3166618fd3c949f4967caebffd6ef9
7
+ data.tar.gz: 3ecc3a63b1e664b441db749d6997e3ea233a67ee2354e7483920fdf6a84591000bb40dfa984f162ce2f42c684f71130e54780ae8a67d51d390e53243341c9ca4
@@ -10,22 +10,19 @@ module SshMenu
10
10
  end
11
11
 
12
12
  def edit
13
- puts "Edit config file #{@config_file}"
14
- exec("#{@general['editor']} #{@config_file}")
13
+ puts "Edit config file #@config_file"
14
+ exec("#{@general['editor']} #@config_file")
15
15
  end
16
16
 
17
17
  def connect(index)
18
- unless index.between?(0, @connections.length-1)
19
- raise ArgumentError, 'invalid index'
20
- end
21
-
22
18
  conn = @connections[index]
23
19
 
24
- opts = " #{@general['ssh_opts']} #{conn['ssh_opts']}"
25
- cmd = "#{@general['ssh_exec']}"
26
- cmd << opts
27
- cmd << " #{conn['user_host']}"
28
-
20
+ cmd = [@general['ssh_exec'],
21
+ @general['ssh_opts'],
22
+ conn['ssh_opts'],
23
+ conn['user_host']
24
+ ].join(' ')
25
+ puts "Command is #{cmd}" if $DEBUG
29
26
  puts "Connecting to #{conn['user_host']}"
30
27
  exec(cmd)
31
28
  end
@@ -34,9 +31,8 @@ module SshMenu
34
31
  editor = Config.default_editor
35
32
  config = Config.default_config_file
36
33
  print "Edit #{config} using default editor '#{editor}' [y/N]? "
37
- if STDIN.getc =~ /\A[Yy]\z/
38
- exec("#{editor} #{config}")
39
- end
34
+
35
+ exec("#{editor} #{config}") if STDIN.getc[/[Yy]/]
40
36
  end
41
37
 
42
38
  end
@@ -22,7 +22,7 @@ module SshMenu
22
22
  @general = config['general']
23
23
  @connections = config['connections']
24
24
 
25
- puts "Config is #{config.inspect}" if ENV['SSHMENU_DEBUG'].eql?('true')
25
+ puts "Config is #{config.inspect}" if $DEBUG
26
26
  rescue Psych::SyntaxError => e
27
27
  raise ConfigException, "YAML syntax error: #{e.message}"
28
28
  end
@@ -38,11 +38,11 @@ module SshMenu
38
38
  end
39
39
 
40
40
  def create_config_file(cfg_file)
41
- puts "Create sample config file #{cfg_file}"
42
- project_dir = File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))
43
- sample_cfg = File.join(project_dir, 'data', 'sshmenu', 'sampleconfig.yml');
44
- FileUtils.mkdir_p(File.dirname(cfg_file))
45
- FileUtils.cp(sample_cfg, cfg_file)
41
+ puts "Create sample config file #{cfg_file}"
42
+ project_dir = File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))
43
+ sample_cfg = File.join(project_dir, 'data', 'sshmenu', 'sampleconfig.yml');
44
+ FileUtils.mkdir_p(File.dirname(cfg_file))
45
+ FileUtils.cp(sample_cfg, cfg_file)
46
46
  end
47
47
 
48
48
  def validate_config(config)
@@ -58,7 +58,7 @@ module SshMenu
58
58
  end
59
59
 
60
60
  def self.default_ssh_client
61
- 'ssh'
61
+ 'ssh'
62
62
  end
63
63
 
64
64
  def self.default_editor
@@ -13,7 +13,7 @@ module SshMenu
13
13
  opts.banner << "add no arguments to show a list of configured connections"
14
14
 
15
15
  opts.on('-e', '--edit', 'edit configuration file') do |e|
16
- @opts = @opts.merge({:action => :edit})
16
+ @opts[:action] = :edit
17
17
  end
18
18
 
19
19
  opts.on_tail('-v', '--version', 'print version') do
@@ -29,12 +29,10 @@ module SshMenu
29
29
 
30
30
  opt_parser.parse!(args)
31
31
 
32
- unless args.first.nil?
33
- begin
34
- @opts = @opts.merge({:index => Integer(args.first) - 1})
35
- rescue ArgumentError
36
- raise "'#{args[0]}' expected to be a preselected index"
37
- end
32
+ begin
33
+ @opts[:index] = Integer(args.first) - 1 if args.first
34
+ rescue ArgumentError
35
+ raise "'#{args.first}' expected to be a preselected index"
38
36
  end
39
37
  end
40
38
  end
@@ -7,19 +7,25 @@ module SshMenu
7
7
 
8
8
  def select
9
9
  selection = request_selection
10
-
10
+
11
11
  case selection
12
12
  when /\A[eE]\z/
13
13
  {:action => :edit}
14
- when /\A[1-9][0-9]*\z/
15
- {:index => Integer(selection) - 1 }
14
+ when (/\A[1-9][0-9]*\z/)
15
+ index = Integer(selection) - 1
16
+ raise_invalid unless index.between?(0, @connections.length - 1)
17
+ {:index => index}
16
18
  when /\A\z/
17
19
  {}
18
20
  else
19
- raise ArgumentError, "invalid selection '#{selection}'"
21
+ raise_invalid
20
22
  end
21
23
  end
22
24
 
25
+ def raise_invalid
26
+ raise ArgumentError, 'selection must be an index from the list'
27
+ end
28
+
23
29
  def request_selection
24
30
  puts connection_list
25
31
  print 'Pick a server (or e to edit connections): '
@@ -30,14 +36,13 @@ module SshMenu
30
36
  uh_length = @connections.map {|conn| conn['user_host'].length}.max
31
37
  index_length = @connections.size.to_s.length
32
38
 
33
- s = StringIO.new
34
- @connections.each.with_index do |connection, index|
35
- conn = connection['user_host']
36
- desc = connection['description']
37
- s << "%#{index_length}d) %-#{uh_length+3}s %s\n" % [ index+1, conn, desc]
38
- end
39
- s.string
39
+ @connections.each.with_index.each_with_object(StringIO.new) do |(connection, index), concat|
40
+ concat << "%#{index_length}d) %-#{uh_length+3}s %s\n" % [
41
+ index + 1,
42
+ connection['user_host'],
43
+ connection['description']
44
+ ]
45
+ end.string
40
46
  end
41
-
42
47
  end
43
48
  end
@@ -1,3 +1,3 @@
1
1
  module SshMenu
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
data/lib/sshmenu.rb CHANGED
@@ -1,7 +1,6 @@
1
- require 'sshmenu/options'
2
- require 'sshmenu/config'
3
- require 'sshmenu/actions'
4
- require 'sshmenu/selector'
1
+ %w(options config selector actions).each do |req|
2
+ require "sshmenu/#{req}"
3
+ end
5
4
 
6
5
  module SshMenu
7
6
  class SshMenu
@@ -10,21 +9,20 @@ module SshMenu
10
9
  config = Config.new
11
10
  actions = Actions.new(config)
12
11
 
13
- selection = if options.empty?
14
- selector = Selector.new(config.connections)
15
- selector.select
16
- else
17
- options
18
- end
12
+ selection = if options.empty?
13
+ Selector.new(config.connections).select
14
+ else
15
+ options
16
+ end
19
17
 
20
- actions.edit if selection[:action] == :edit
21
- actions.connect selection[:index] if selection[:index]
18
+ actions.edit if selection[:action] == :edit
19
+ actions.connect selection[:index] if selection[:index]
22
20
 
23
- rescue ConfigException => e
24
- puts e.message
25
- Actions.ask_edit_with_default_editor
26
- rescue Exception => e
27
- ENV['SSHMENU_DEBUG'].eql?('true') ? raise(e) : puts(e.message)
21
+ rescue ConfigException => e
22
+ puts e.message
23
+ Actions.ask_edit_with_default_editor
24
+ rescue => e
25
+ puts(e.message) unless $DEBUG
26
+ end
28
27
  end
29
28
  end
30
- end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sshmenu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ti
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-06-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -26,7 +26,7 @@ dependencies:
26
26
  version: '11.2'
27
27
  description: |
28
28
  This gem provides the executable 'sshmenu', which brings up
29
- a list of configured ssh connection. From the list you can
29
+ a list of configured ssh connections. From the list you can
30
30
  directly connect to one of the ssh servers or edit the
31
31
  available ssh connections.
32
32
  email:
@@ -48,7 +48,7 @@ homepage: http://rubygems.org/gems/sshmenu
48
48
  licenses:
49
49
  - GPL-2.0
50
50
  metadata: {}
51
- post_install_message: Type sshmenu -e to start editing you ssh connections
51
+ post_install_message: Type sshmenu -e to start editing your ssh connections
52
52
  rdoc_options: []
53
53
  require_paths:
54
54
  - lib