eventhub-command 0.8.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,17 +1,16 @@
1
- desc 'Generate template for a new processor'
1
+ desc "Generate template for a new processor"
2
2
  command :generate do |c|
3
-
4
- c.arg_name 'MODULE_NAME PROCESSOR_NAME'
3
+ c.arg_name "MODULE_NAME PROCESSOR_NAME"
5
4
  c.desc "Generate ruby based processor"
6
5
  c.command :ruby do |c|
7
6
  c.action do |global_options, options, args|
8
- require 'active_support/core_ext/string/inflections'
9
- require 'fileutils'
10
- require 'erb'
7
+ require "active_support/core_ext/string/inflections"
8
+ require "fileutils"
9
+ require "erb"
11
10
 
12
11
  if args.size != 2
13
12
  puts "Needs exactly 2 arguments: eh generate processor MODULE NAME"
14
- exit -1
13
+ exit(-1)
15
14
  end
16
15
 
17
16
  processor_module_name = args[0].camelcase
@@ -22,9 +21,9 @@ command :generate do |c|
22
21
  destination_dir = Eh::Settings.current.ruby_processors_src_dir
23
22
  destination_dir = File.join(destination_dir, "#{underscored_processor_module_name}.#{underscored_processor_class_name}")
24
23
 
25
- if Dir.exists? destination_dir
24
+ if Dir.exist? destination_dir
26
25
  puts "#{destination_dir} already exists!"
27
- exit -1
26
+ exit(-1)
28
27
  end
29
28
 
30
29
  template_tmp_dir = Eh::Settings.current.template_tmp_dir
@@ -32,7 +31,7 @@ command :generate do |c|
32
31
 
33
32
  FileUtils.cp_r template_tmp_dir, destination_dir
34
33
  FileUtils.rm_rf File.join(destination_dir, ".git")
35
- FileUtils.rm File.join(destination_dir, 'README.md')
34
+ FileUtils.rm File.join(destination_dir, "README.md")
36
35
 
37
36
  puts "Generating processor #{processor_module_name}::#{processor_class_name} in #{destination_dir}"
38
37
  Dir.glob(destination_dir + "/**/*.erb") do |file|
@@ -1,58 +1,55 @@
1
- desc 'Package commands'
1
+ desc "Package commands"
2
2
  command :package do |package|
3
- package.flag([:s, :source], :desc => "Source directory to read processors from.")
4
- package.flag([:d, :destination], :desc => "Destination directory to place created zip files.")
5
- package.flag([:x, :exclude], arg_name: 'NAME1,NAME2,PATTERN*', desc: "Exclude components with NAME1,NAME2,PATTERN*", type: String)
3
+ package.flag([:s, :source], desc: "Source directory to read processors from.")
4
+ package.flag([:d, :destination], desc: "Destination directory to place created zip files.")
5
+ package.flag([:x, :exclude], arg_name: "NAME1,NAME2,PATTERN*", desc: "Exclude components with NAME1,NAME2,PATTERN*", type: String)
6
6
 
7
- package.desc 'Packages ruby processors to zip files'
8
- package.arg_name '[NAME1,[NAME2,PATTERN*]]'
7
+ package.desc "Packages ruby processors to zip files"
8
+ package.arg_name "[NAME1,[NAME2,PATTERN*]]"
9
9
  package.command :ruby do |ruby|
10
-
11
10
  ruby.action do |global_options, options, args|
12
- options['s'] ||= Eh::Settings.current.ruby_processors_src_dir
13
- options['d'] ||= Eh::Settings.current.ruby_release_dir
14
- source_dir = options.fetch('s')
15
- destination_dir = options.fetch('d')
11
+ options["s"] ||= Eh::Settings.current.ruby_processors_src_dir
12
+ options["d"] ||= Eh::Settings.current.ruby_release_dir
13
+ source_dir = options.fetch("s")
14
+ destination_dir = options.fetch("d")
16
15
  include_pattern = args[0]
17
- exclude_pattern = options['x']
16
+ exclude_pattern = options["x"]
18
17
  packager = Packager::Ruby.new(source_dir, destination_dir, include_pattern, exclude_pattern)
19
18
  packager.package
20
19
  end
21
20
  end
22
21
 
23
- package.desc 'Packages go processors to zip files'
24
- package.arg_name '[NAME1,[NAME2,PATTERN*]]'
22
+ package.desc "Packages go processors to zip files"
23
+ package.arg_name "[NAME1,[NAME2,PATTERN*]]"
25
24
  package.command :go do |go|
26
- go.flag([:p, :platform], arg_name: 'PLATFORM', desc: 'Target platform', must_match: ['linux', 'darwin', 'windows'], default_value: 'linux')
25
+ go.flag([:p, :platform], arg_name: "PLATFORM", desc: "Target platform", must_match: ["linux", "darwin", "windows"], default_value: "linux")
27
26
 
28
27
  go.action do |global_options, options, args|
29
- options['s'] ||= Eh::Settings.current.go_processors_src_dir
30
- options['d'] ||= Eh::Settings.current.go_release_dir
31
- source_dir = options.fetch('s')
32
- destination_dir = options.fetch('d')
28
+ options["s"] ||= Eh::Settings.current.go_processors_src_dir
29
+ options["d"] ||= Eh::Settings.current.go_release_dir
30
+ source_dir = options.fetch("s")
31
+ destination_dir = options.fetch("d")
33
32
  include_pattern = args[0]
34
- exclude_pattern = options['x']
35
- platform = options['p'] || 'linux'
33
+ exclude_pattern = options["x"]
34
+ platform = options["p"] || "linux"
36
35
  packager = Packager::Go.new(source_dir, destination_dir, include_pattern, exclude_pattern, platform)
37
36
  packager.package
38
37
  end
39
-
40
38
  end
41
39
 
42
- package.desc 'Packages rails console app to zip file'
40
+ package.desc "Packages rails console app to zip file"
43
41
  package.command :rails do |rails|
44
42
  rails.action do |global_options, options, args|
45
- options['s'] ||= Eh::Settings.current.rails_src_dir
46
- options['d'] ||= Eh::Settings.current.rails_release_dir
43
+ options["s"] ||= Eh::Settings.current.rails_src_dir
44
+ options["d"] ||= Eh::Settings.current.rails_release_dir
47
45
 
48
- raise 'Flag [-x, --exclude] is currently not supported with rails subcommand' if options[:exclude]
46
+ raise "Flag [-x, --exclude] is currently not supported with rails subcommand" if options[:exclude]
49
47
 
50
- source_dir = options.fetch('s')
51
- destination_dir = options.fetch('d')
48
+ source_dir = options.fetch("s")
49
+ destination_dir = options.fetch("d")
52
50
 
53
51
  packager = Packager::Rails.new(source_dir, destination_dir)
54
52
  packager.package
55
53
  end
56
54
  end
57
-
58
55
  end
@@ -1,41 +1,40 @@
1
- desc 'Manage proxies'
1
+ desc "Manage proxies"
2
2
  command :proxy do |proxy|
3
+ proxy.switch([:v, :verbose], desc: "Show additional output.")
4
+ proxy.flag([:stage], desc: "stage", type: String, long_desc: "Stage where proxy is", default_value: Eh::Settings.current.default_stage)
3
5
 
4
- proxy.switch([:v, :verbose], :desc => 'Show additional output.')
5
- proxy.flag([:stage], desc: 'stage', type: String, long_desc: 'Stage where proxy is', default_value: Eh::Settings.current.default_stage)
6
-
7
- proxy.desc 'List defined proxies'
6
+ proxy.desc "List defined proxies"
8
7
  proxy.command :list do |list|
9
8
  list.action do |global_options, options, arguments|
10
9
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).list
11
10
  end
12
11
  end
13
12
 
14
- proxy.desc 'Select proxy by NAME'
15
- proxy.arg_name 'NAME'
13
+ proxy.desc "Select proxy by NAME"
14
+ proxy.arg_name "NAME"
16
15
  proxy.command :select do |select|
17
16
  select.action do |global_options, options, arguments|
18
17
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).select(arguments[0])
19
18
  end
20
19
  end
21
20
 
22
- proxy.desc 'Enable proxy default or by NAME'
23
- proxy.arg_name 'NAME'
21
+ proxy.desc "Enable proxy default or by NAME"
22
+ proxy.arg_name "NAME"
24
23
  proxy.command :on do |on|
25
24
  on.action do |global_options, options, arguments|
26
25
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).set(arguments[0])
27
26
  end
28
27
  end
29
28
 
30
- proxy.desc 'Disable default proxy'
29
+ proxy.desc "Disable default proxy"
31
30
  proxy.command :off do |off|
32
31
  off.action do |global_options, options, arguments|
33
32
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).unset
34
33
  end
35
34
  end
36
35
 
37
- proxy.desc 'Add new proxy by NAME and PROXY_URL'
38
- proxy.arg_name 'NAME PROXY_URL'
36
+ proxy.desc "Add new proxy by NAME and PROXY_URL"
37
+ proxy.arg_name "NAME PROXY_URL"
39
38
  proxy.command :add do |add|
40
39
  add.action do |global, options, arguments|
41
40
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).add(arguments[0], arguments[1])
@@ -43,7 +42,7 @@ command :proxy do |proxy|
43
42
  end
44
43
 
45
44
  proxy.desc "Remove by NAME"
46
- proxy.arg_name 'NAME'
45
+ proxy.arg_name "NAME"
47
46
  proxy.command :remove do |remove|
48
47
  remove.action do |global_options, options, arguments|
49
48
  Eh::Proxy::Proxy.new(options[:stage], options[:verbose]).remove(arguments[0])
@@ -3,23 +3,22 @@ desc "Manage repositories"
3
3
  command :repository do |command|
4
4
  command.desc "Lists all avaiable repositories"
5
5
  command.command :list do |command|
6
- command.action do |global_options,options,args|
7
-
8
- puts "Defined Repositories [#{Eh::Settings.current.data['repositories'].size}]"
6
+ command.action do |global_options, options, args|
7
+ puts "Defined Repositories [#{Eh::Settings.current.data["repositories"].size}]"
9
8
  Eh::Settings.current.repositories.each_with_index do |repository, index|
10
9
  if repository.current?
11
- puts " #{index+1}. #{repository.url} (current)".green
10
+ puts " #{index + 1}. #{repository.url} (current)".green
12
11
  else
13
- puts " #{index+1}. #{repository.url}"
12
+ puts " #{index + 1}. #{repository.url}"
14
13
  end
15
14
  end
16
15
  end
17
16
  end
18
17
 
19
18
  command.desc "Selects a repository by INDEX"
20
- command.arg_name 'INDEX'
19
+ command.arg_name "INDEX"
21
20
  command.command :select do |command|
22
- command.action do |global_options,options,args|
21
+ command.action do |global_options, options, args|
23
22
  if Eh::Settings.current.repositories.length == 0
24
23
  raise "No repository configured so far"
25
24
  end
@@ -27,53 +26,51 @@ command :repository do |command|
27
26
  raise "Needs mandatory INDEX argument"
28
27
  end
29
28
  selected = args[0].to_i
30
- if selected > Eh::Settings.current.data['repositories'].size
29
+ if selected > Eh::Settings.current.data["repositories"].size
31
30
  raise "Argument INDEX is out of range"
32
31
  end
33
- Eh::Settings.current.data['repositories'].each_with_index do |repository, index|
34
- repository['current'] = (index + 1) == selected
32
+ Eh::Settings.current.data["repositories"].each_with_index do |repository, index|
33
+ repository["current"] = (index + 1) == selected
35
34
  end
36
35
  Eh::Settings.current.write
37
36
  puts "Repository selected: #{Eh::Settings.current.repository.url}".green
38
37
  end
39
38
  end
40
39
 
41
- command.desc 'Add a repository with URL DIR USERNAME PASSWORD'
42
- command.arg_name 'URL DIR USERNAME PASSWORD'
40
+ command.desc "Add a repository with URL DIR USERNAME PASSWORD"
41
+ command.arg_name "URL DIR USERNAME PASSWORD"
43
42
  command.command :add do |command|
44
43
  command.action do |global_options, options, args|
45
44
  if args.length != 4
46
45
  raise "Need exactly 4 arguments: URL, DIR, USERNAME, PASSWORD"
47
46
  end
48
- Eh::Settings.current.data['repositories'] ||= []
47
+ Eh::Settings.current.data["repositories"] ||= []
49
48
 
50
49
  # check if same repo already exists
51
- exists = Eh::Settings.current.data['repositories'].any? do |repository|
52
- repository['url'] == args[0]
50
+ exists = Eh::Settings.current.data["repositories"].any? do |repository|
51
+ repository["url"] == args[0]
53
52
  end
54
53
  if exists
55
54
  raise "Already configured repository [#{args[0]}]"
56
55
  end
57
56
 
58
- Eh::Settings.current.data['repositories'] << {
59
- 'url' => args[0],
60
- 'dir' => File::ALT_SEPARATOR ? args[1].gsub(File::ALT_SEPARATOR, File::SEPARATOR) : args[1],
61
- 'deploy_username' => args[2],
62
- 'deploy_password' => args[3],
63
- 'current' => (Eh::Settings.current.data['repositories'].length == 0)
57
+ Eh::Settings.current.data["repositories"] << {
58
+ "url" => args[0],
59
+ "dir" => File::ALT_SEPARATOR ? args[1].gsub(File::ALT_SEPARATOR, File::SEPARATOR) : args[1],
60
+ "deploy_username" => args[2],
61
+ "deploy_password" => args[3],
62
+ "current" => (Eh::Settings.current.data["repositories"].length == 0)
64
63
  }
65
64
  Eh::Settings.current.write
66
65
 
67
- puts "New Repository [#{args[0]}] has beed added. Total Repositories: #{Eh::Settings.current.data['repositories'].size}".green
66
+ puts "New Repository [#{args[0]}] has beed added. Total Repositories: #{Eh::Settings.current.data["repositories"].size}".green
68
67
  end
69
68
  end
70
69
 
71
-
72
- command.desc 'Remove a repository by INDEX'
73
- command.arg_name 'INDEX'
70
+ command.desc "Remove a repository by INDEX"
71
+ command.arg_name "INDEX"
74
72
  command.command :remove do |command|
75
73
  command.action do |global_options, options, args|
76
-
77
74
  if args.length != 1
78
75
  raise "Needs mandatory INDEX argument"
79
76
  end
@@ -83,10 +80,10 @@ command :repository do |command|
83
80
  raise "No repository with index [selected]"
84
81
  end
85
82
 
86
- Eh::Settings.current.data['repositories'].delete_at(selected - 1)
83
+ Eh::Settings.current.data["repositories"].delete_at(selected - 1)
87
84
  Eh::Settings.current.write
88
85
 
89
- puts "Repository has been removed. Total Repositories: #{Eh::Settings.current.data['repositories'].size}".green
86
+ puts "Repository has been removed. Total Repositories: #{Eh::Settings.current.data["repositories"].size}".green
90
87
  end
91
88
  end
92
89
 
@@ -1,21 +1,21 @@
1
- desc 'Manage stages'
1
+ desc "Manage stages"
2
2
  command :stage do |command|
3
- command.desc 'List defined stages'
3
+ command.desc "List defined stages"
4
4
  command.command :list do |list|
5
5
  list.action do |global_options, options, args|
6
6
  dir = Eh::Settings.current.stages_dir
7
7
  puts "Checking in #{dir}".yellow if global_options[:verbose]
8
8
  puts "Available Stages"
9
- Dir.glob(File.join(dir, '*.yml')) do |name|
10
- stage_name = File.basename(name, '.*')
9
+ Dir.glob(File.join(dir, "*.yml")) do |name|
10
+ stage_name = File.basename(name, ".*")
11
11
  is_default = Eh::Settings.current.default_stage == stage_name
12
- puts " - #{stage_name} #{is_default ? '(default)' : nil}".send(is_default ? :green : :white)
12
+ puts " - #{stage_name} #{is_default ? "(default)" : nil}".send(is_default ? :green : :white)
13
13
  end
14
14
  end
15
15
  end
16
16
 
17
- command.desc 'Select default stage'
18
- command.arg_name 'NAME'
17
+ command.desc "Select default stage"
18
+ command.arg_name "NAME"
19
19
  command.command :select do |default|
20
20
  default.action do |global_options, options, args|
21
21
  new_stage = args[0]
@@ -29,7 +29,7 @@ command :stage do |command|
29
29
  raise "Stage [#{new_stage}] is not defined yet"
30
30
  end
31
31
 
32
- Eh::Settings.current.data['default_stage'] = new_stage
32
+ Eh::Settings.current.data["default_stage"] = new_stage
33
33
  Eh::Settings.current.write
34
34
  puts "Default stage selected: #{new_stage}".green
35
35
  end
@@ -1,9 +1,9 @@
1
1
  module Eh
2
2
  module Proxy
3
- require 'uri'
4
- require_relative 'settings/git'
5
- require_relative 'settings/svn'
6
- require_relative 'settings/shell'
3
+ require "uri"
4
+ require_relative "settings/git"
5
+ require_relative "settings/svn"
6
+ require_relative "settings/shell"
7
7
 
8
8
  class Proxy
9
9
  def initialize(stage_name, verbose)
@@ -34,7 +34,7 @@ module Eh
34
34
  raise "No proxy with given name [#{name}]"
35
35
  end
36
36
 
37
- Eh::Settings.current.data['proxies'].reject! { |json| json['name'] == name}
37
+ Eh::Settings.current.data["proxies"].reject! { |json| json["name"] == name }
38
38
  Eh::Settings.current.write
39
39
  puts "Proxy [#{name}] has been removed".green
40
40
  end
@@ -47,10 +47,10 @@ module Eh
47
47
  raise "Already configured proxy for [#{name} -> #{url}]"
48
48
  end
49
49
 
50
- Eh::Settings.current.data['proxies'] << {
51
- 'url' => url,
52
- 'name' => name,
53
- 'default' => (Eh::Settings.current.proxies.length == 0)
50
+ Eh::Settings.current.data["proxies"] << {
51
+ "url" => url,
52
+ "name" => name,
53
+ "default" => (Eh::Settings.current.proxies.length == 0)
54
54
  }
55
55
  Eh::Settings.current.write
56
56
  puts "Proxy [#{name}] has been added".green
@@ -63,8 +63,8 @@ module Eh
63
63
  raise "No proxy found with given name [#{name}]"
64
64
  end
65
65
 
66
- Eh::Settings.current.data['proxies'].each do |json|
67
- json['default'] = (json['name'] == name)
66
+ Eh::Settings.current.data["proxies"].each do |json|
67
+ json["default"] = (json["name"] == name)
68
68
  end
69
69
  Eh::Settings.current.write
70
70
  puts "Proxy [#{name}] has been selected".green
@@ -73,11 +73,12 @@ module Eh
73
73
  def list
74
74
  puts "Defined Proxies"
75
75
  Eh::Settings.current.proxies.each do |proxy|
76
- puts proxy.label.send( proxy.label =~ /\(default\)/ ? :green : :white )
76
+ puts proxy.label.send(/\(default\)/.match?(proxy.label) ? :green : :white)
77
77
  end
78
78
  end
79
79
 
80
80
  private
81
+
81
82
  attr_reader :stage_name, :verbose
82
83
 
83
84
  def stage
@@ -99,7 +100,6 @@ module Eh
99
100
  def find_default_proxy
100
101
  Eh::Settings.current.proxies.find { |proxy| proxy.default }
101
102
  end
102
-
103
103
  end
104
104
  end
105
105
  end
@@ -17,7 +17,6 @@ module Eh::Proxy::Settings
17
17
  end
18
18
  end
19
19
 
20
-
21
20
  private
22
21
 
23
22
  def verbose?
@@ -8,7 +8,6 @@ module Eh::Proxy::Settings
8
8
  def set(value)
9
9
  Deployer::Executor.new(stage, verbose: verbose?) do |executor|
10
10
  executor.execute(set_command(value), abort_on_error: false)
11
-
12
11
  end
13
12
  end
14
13
 
@@ -18,11 +17,10 @@ module Eh::Proxy::Settings
18
17
  end
19
18
  end
20
19
 
21
-
22
20
  private
23
21
 
24
22
  def proxy_file
25
- '~/.proxy'
23
+ "~/.proxy"
26
24
  end
27
25
 
28
26
  def verbose?
@@ -1,7 +1,6 @@
1
- require 'tempfile'
2
- require 'parseconfig'
1
+ require "tempfile"
2
+ require "parseconfig"
3
3
  module Eh::Proxy::Settings
4
-
5
4
  class Svn
6
5
  def initialize(stage, verbose = true)
7
6
  @stage = stage
@@ -13,16 +12,15 @@ module Eh::Proxy::Settings
13
12
  executor.download("~/.subversion/servers", temporary_config_file)
14
13
  config = ParseConfig.new(temporary_config_file)
15
14
 
16
- config['global'].delete('http-proxy-host')
17
- config['global'].delete('http-proxy-port')
18
- config['global'].delete('http-proxy-username')
19
- config['global'].delete('http-proxy-password')
20
- File.open(temporary_config_file, 'w') do |file|
15
+ config["global"].delete("http-proxy-host")
16
+ config["global"].delete("http-proxy-port")
17
+ config["global"].delete("http-proxy-username")
18
+ config["global"].delete("http-proxy-password")
19
+ File.open(temporary_config_file, "w") do |file|
21
20
  config.write(file, false)
22
21
  end
23
22
  executor.upload(temporary_config_file, "~/.subversion/servers")
24
23
  end
25
-
26
24
  end
27
25
 
28
26
  def set(value)
@@ -31,14 +29,13 @@ module Eh::Proxy::Settings
31
29
  Deployer::Executor.new(stage, verbose: verbose?) do |executor|
32
30
  executor.download("~/.subversion/servers", temporary_config_file)
33
31
  config = ParseConfig.new(temporary_config_file)
34
- config['global']['http-proxy-host'] = uri.host
35
- config['global']['http-proxy-port'] = uri.port
36
- File.open(temporary_config_file, 'w') do |file|
32
+ config["global"]["http-proxy-host"] = uri.host
33
+ config["global"]["http-proxy-port"] = uri.port
34
+ File.open(temporary_config_file, "w") do |file|
37
35
  config.write(file, false)
38
36
  end
39
37
  executor.upload(temporary_config_file, "~/.subversion/servers")
40
38
  end
41
-
42
39
  end
43
40
 
44
41
  private
@@ -50,12 +47,10 @@ module Eh::Proxy::Settings
50
47
  attr_reader :stage
51
48
 
52
49
  def unset_command
53
-
54
50
  end
55
51
 
56
52
  def temporary_config_file
57
- @temporary_config_file ||= Dir::Tmpname.make_tmpname([Dir.tmpdir, 'subversion_servers'], nil)
53
+ @temporary_config_file ||= Dir::Tmpname.make_tmpname([Dir.tmpdir, "subversion_servers"], nil)
58
54
  end
59
-
60
55
  end
61
56
  end