ec2ssh 3.0.2 → 3.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a9fc26414d2229c5799e37e4c57d462a93fae33
4
- data.tar.gz: da75a3f732e6422304d4146b983b5ce59aa1d8f1
3
+ metadata.gz: 427d803411f39f80c250748ed172af0f72308082
4
+ data.tar.gz: 0378e1f19cfd75db31a2441967b46e72f3abbd15
5
5
  SHA512:
6
- metadata.gz: 7f9ce9fa0b70be913f10f57dd9c7eefef819459681a1ab5fca2f474abb99c4eaa5b9f09159836bf7c36e384ad7d403083458b2ba2c1167d068429330e9481e2d
7
- data.tar.gz: 9d594fbdb67366d832bed0c6b6633485d8481f765d4ab2bfd37c66c949477fe9a90675c85564da36698df2074f68a6a3e8237bafcc776f67ceb6d69cabf6ce79
6
+ metadata.gz: f8e5de4f469dbbfc56f6061484932748b0e6387f72035b51d9a53ce453fa2b8ee4007ce06e253ef087073c61d05999991ac44c16959a86b84a35d384261e8556
7
+ data.tar.gz: a77fffdc9fec166647df4372238a277600bed4a8dbc8c4fa3935311de0a2b8f3712441ac6ec3f0bd4386a04d0b491ad976ef63797ddcf18bc1caf95f893678d9
data/ChangeLog.md CHANGED
@@ -1,4 +1,9 @@
1
1
  # Change Log
2
+ ## 3.0.3
3
+ * Use "%-" for ERB's trim\_mode at `host\_line` in dotfile (#29)
4
+ * Add 'shellcomp' command: loading completion functions easily in bash/zsh (#27)
5
+ Thanks to @hayamiz
6
+
2
7
  ## 3.0.2
3
8
  * Add zsh completion file (#26)
4
9
  Thanks to @hayamiz
data/bash/ec2ssh.bash ADDED
@@ -0,0 +1,53 @@
1
+ # bash completion support for ec2ssh
2
+
3
+ _ec2ssh() {
4
+ local cmd cur prev subcmd
5
+ cmd=$1
6
+ cur=$2
7
+ prev=$3
8
+
9
+ subcmds="help init migrate remove update version"
10
+ common_opts="--dotfile --verbose"
11
+
12
+ # contextual completion
13
+ case $prev in
14
+ ec2ssh)
15
+ case "$cur" in
16
+ -*)
17
+ COMPREPLY=( $(compgen -W "$common_opts" $cur) )
18
+ ;;
19
+ *)
20
+ COMPREPLY=( $(compgen -W "$subcmds" $cur) )
21
+ esac
22
+ return 0
23
+ ;;
24
+ --aws-key)
25
+ COMPREPLY=()
26
+ return 0;
27
+ ;;
28
+ --dotfile)
29
+ COMPREPLY=( $(compgen -o default -- "$cur"))
30
+ return 0;
31
+ ;;
32
+ esac
33
+
34
+ # complete options
35
+ subcmd=${COMP_WORDS[1]}
36
+
37
+ case $subcmd in
38
+ update)
39
+ COMPREPLY=( $(compgen -W "--aws-key $common_opts" -- "$cur") )
40
+ ;;
41
+ help)
42
+ COMPREPLY=( $(compgen -W "$subcmds" $cur) )
43
+ ;;
44
+ *)
45
+ COMPREPLY=( $(compgen -W "$common_opts" -- "$cur") )
46
+ ;;
47
+ esac
48
+
49
+ return 0
50
+
51
+ }
52
+
53
+ complete -F _ec2ssh ec2ssh
@@ -6,7 +6,9 @@ module Ec2ssh
6
6
  class Builder
7
7
  def initialize(container)
8
8
  @container = container
9
- @host_lines_erb = ERB.new @container.host_line
9
+ safe_level = nil
10
+ erb_trim_mode = '%-'
11
+ @host_lines_erb = ERB.new @container.host_line, safe_level, erb_trim_mode
10
12
  end
11
13
 
12
14
  def build_host_lines
@@ -16,10 +18,11 @@ module Ec2ssh
16
18
  ec2s.instances(name).each do |instance|
17
19
  bind = instance.instance_eval { binding }
18
20
  next if @container.reject && @container.reject.call(instance)
19
- out.puts @host_lines_erb.result(bind)
21
+ line = @host_lines_erb.result(bind).rstrip
22
+ out.puts line unless line.empty?
20
23
  end
21
24
  end
22
- out.string
25
+ out.string.rstrip
23
26
  end
24
27
 
25
28
  def ec2s
data/lib/ec2ssh/cli.rb CHANGED
@@ -51,6 +51,38 @@ module Ec2ssh
51
51
  command.run
52
52
  end
53
53
 
54
+ desc 'shellcomp [-]', 'Initialize shell completion for bash/zsh'
55
+ def shellcomp(_ = false)
56
+ if args.include?("-")
57
+ print_rc = true
58
+ else
59
+ print_rc = false
60
+ end
61
+
62
+ # print instructions for automatically enabling shell completion
63
+ unless print_rc
64
+ puts <<EOS
65
+ # Enable ec2ssh completion by adding
66
+ # the following to .bash_profile/.zshrc
67
+
68
+ type ec2ssh >/dev/null 2>&1 && eval "$(ec2ssh shellcomp -)"
69
+
70
+ EOS
71
+ exit(false)
72
+ end
73
+
74
+ # print shell script for enabling shell completion
75
+ zsh_comp_file = File.expand_path("../../../zsh/_ec2ssh", __FILE__)
76
+ bash_comp_file = File.expand_path("../../../bash/ec2ssh.bash", __FILE__)
77
+ puts <<EOS
78
+ if [ -n "${BASH_VERSION:-}" ]; then
79
+ source #{bash_comp_file}
80
+ elif [ -n "${ZSH_VERSION:-}" ]; then
81
+ source #{zsh_comp_file}
82
+ fi
83
+ EOS
84
+ end
85
+
54
86
  desc 'version', 'Show version'
55
87
  def version
56
88
  require 'ec2ssh/version'
@@ -1,3 +1,3 @@
1
1
  module Ec2ssh
2
- VERSION = '3.0.2'
2
+ VERSION = '3.0.3'
3
3
  end
@@ -38,7 +38,7 @@ describe Ec2ssh::Builder do
38
38
  end
39
39
 
40
40
  it do
41
- expect(builder.build_host_lines).to eq <<-END
41
+ expect(builder.build_host_lines).to eq <<-END.rstrip
42
42
  # section: key1
43
43
  Host srv1
44
44
  Host srv2
@@ -54,7 +54,7 @@ Host srv4
54
54
  end
55
55
 
56
56
  it do
57
- expect(builder.build_host_lines).to eq <<-END
57
+ expect(builder.build_host_lines).to eq <<-END.rstrip
58
58
  # section: key1
59
59
  Host srv2
60
60
  # section: key2
@@ -63,5 +63,27 @@ Host srv4
63
63
  END
64
64
  end
65
65
  end
66
+
67
+ context 'checking erb trim_mode' do
68
+ before do
69
+ container.host_line = <<-END
70
+ % if tags['Name']
71
+ <%- if tags['Name'] == 'srv3' -%>
72
+ Host <%= tags['Name'] %>
73
+ HostName <%= tags['Name'] %>
74
+ <%- end -%>
75
+ % end
76
+ END
77
+ end
78
+
79
+ it do
80
+ expect(builder.build_host_lines).to eq <<-END.rstrip
81
+ # section: key1
82
+ # section: key2
83
+ Host srv3
84
+ HostName srv3
85
+ END
86
+ end
87
+ end
66
88
  end
67
89
  end
@@ -86,7 +86,6 @@ Host srv1
86
86
  HostName 10.0.0.1
87
87
  Host srv2
88
88
  HostName 10.0.0.2
89
-
90
89
  ### EC2SSH END ###
91
90
 
92
91
  # after lines...
@@ -2,9 +2,6 @@ require 'spec_helper'
2
2
  require 'ec2ssh/dsl'
3
3
 
4
4
  describe Ec2ssh::Dsl do
5
- shared_examples 'a filled dsl container' do
6
- end
7
-
8
5
  let(:dsl_str) do
9
6
  <<-END
10
7
  aws_keys(
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ec2ssh
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Issei Naruta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-07 00:00:00.000000000 Z
11
+ date: 2015-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -69,6 +69,7 @@ files:
69
69
  - MIT-LICENSE
70
70
  - README.md
71
71
  - Rakefile
72
+ - bash/ec2ssh.bash
72
73
  - bin/ec2ssh
73
74
  - ec2ssh.gemspec
74
75
  - example/example.ec2ssh