chef-fork 0.1.2 → 0.1.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: 389fc33ea14f3940f41e337f0a43bb2acb33f524
4
- data.tar.gz: 94fe767539b6be91ae9dacc76b2f92ec93a04771
3
+ metadata.gz: 1d17a69329759230186ad22f20d0351e83064065
4
+ data.tar.gz: 735fc1a41ec02e208324b378f582b5d00daae28a
5
5
  SHA512:
6
- metadata.gz: 3d0a2d1eba11e63465a0b7e9b7dc926c7d6c148dbe392ca82a4acb1c4a6c9d752ff3204c479b40ccb1bfaa20db0812ec81ffabe74daaed3c436d57b381bd1745
7
- data.tar.gz: 8153a3af4141e0b145548a628afc61ab60a9321682a6b05a173fb64f19025c55bd3a8cef8381b3a79534c5ae3db4e6c52e81447ec70a591a804eec92017021fd
6
+ metadata.gz: 336ca8301cb1f474636ac53aabd33fd66f6d9b21e9720137b4961a199176a836ebb8675e16bb915f9fa2760f9fa569684d3ba553922cacca1f45bf8fa6417d7f
7
+ data.tar.gz: 6586ba56251e95643770a1fd50be7efb974067b947aff31f3641394a6388cb8cd94a38190ea916a24b079a2e9f4811df7315e9372d38f005c1566524c1d8d088
data/chef-fork.gemspec CHANGED
@@ -8,15 +8,14 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Chef::Fork::VERSION
9
9
  spec.authors = ["Yamashita Yuu"]
10
10
  spec.email = ["peek824545201@gmail.com"]
11
-
12
11
  spec.summary = %q{A tool for your left hand, to have a meal cooked by chef.}
13
12
  spec.description = %q{A tool for your left hand, to have a meal cooked by chef.}
14
13
  spec.homepage = "https://github.com/yyuu/chef-fork"
15
14
  spec.license = "Apache-2.0"
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
- spec.bindir = "exe"
19
- spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
19
  spec.require_paths = ["lib"]
21
20
 
22
21
  spec.add_development_dependency "bundler", "~> 1.9"
@@ -21,7 +21,6 @@ class Chef
21
21
  attr_reader :optparse
22
22
 
23
23
  def main(args=[])
24
- configure_chef(locate_config_file("fork") || locate_config_file("knife"))
25
24
  rest = @optparse.order(args)
26
25
  begin
27
26
  command = get_command(rest.shift || "help").new(self)
@@ -31,6 +30,10 @@ class Chef
31
30
  end
32
31
  end
33
32
 
33
+ def configure(options={})
34
+ configure_chef(locate_config_file("fork") || locate_config_file("knife"), options)
35
+ end
36
+
34
37
  private
35
38
  def define_options()
36
39
  options.merge!({
@@ -98,7 +101,7 @@ class Chef
98
101
  end
99
102
  end
100
103
 
101
- def configure_chef(config_file)
104
+ def configure_chef(config_file, options={})
102
105
  if config_file
103
106
  @logger.info("Using configuration from #{config_file}")
104
107
  Chef::Config.from_file(config_file)
@@ -13,7 +13,7 @@ class Chef
13
13
  end
14
14
 
15
15
  def run(args=[])
16
- rest = @application.optparse.order(args)
16
+ order_args(args=[])
17
17
  end
18
18
 
19
19
  private
@@ -30,6 +30,18 @@ class Chef
30
30
  @application.optparse
31
31
  end
32
32
 
33
+ def order_args(args=[])
34
+ args = @application.optparse.order(args)
35
+ @application.configure(@application.options)
36
+ args
37
+ end
38
+
39
+ def parse_args(args=[])
40
+ args = @application.optparse.parse(args)
41
+ @application.configure(@application.options)
42
+ args
43
+ end
44
+
33
45
  def rest()
34
46
  @rest ||= Chef::REST.new(Chef::Config[:chef_server_url])
35
47
  end
@@ -13,7 +13,7 @@ class Chef
13
13
  module Commands
14
14
  class Bootstrap < Ssh
15
15
  def run(args=[])
16
- rest = optparse.parse(args)
16
+ rest = parse_args(args)
17
17
  if hostname = rest.shift
18
18
  command = bootstrap_command()
19
19
  ssh(hostname, [command])
@@ -75,14 +75,24 @@ class Chef
75
75
  template_file = options[:template_file] || find_template(options[:distro])
76
76
  if template_file
77
77
  template = File.read(template_file)
78
- render_template(template)
78
+ command = render_template(template)
79
+ if options[:use_sudo]
80
+ "sudo #{command}"
81
+ else
82
+ command
83
+ end
79
84
  else
80
- raise(NameError.new("Unknown distro: #{distro.inspect}"))
85
+ raise(NameError.new("Unknown distro: #{options[:distro].inspect}"))
81
86
  end
82
87
  end
83
88
 
84
89
  def find_template(name)
85
- templates = $LOAD_PATH.map { |path| File.join(path, "chef", "knife", "bootstrap", "templates", "#{name}.erb") }
90
+ templates = $LOAD_PATH.map { |path|
91
+ [
92
+ File.join(path, "chef", "knife", "bootstrap", "templates", "#{name}.erb"), # Chef 12.x
93
+ File.join(path, "chef", "knife", "bootstrap", "#{name}.erb"), # Chef 11.x
94
+ ]
95
+ }.reduce(:+)
86
96
  templates.find { |path| File.exist?(path) }
87
97
  end
88
98
 
@@ -9,7 +9,7 @@ class Chef
9
9
  module Commands
10
10
  class Cookbook < Noop
11
11
  def run(args=[])
12
- rest = optparse.order(args)
12
+ rest = order_args(args)
13
13
  case rest.first
14
14
  when "edit"
15
15
  cookbook_edit(rest.slice(1..-1) || [])
@@ -11,7 +11,7 @@ class Chef
11
11
  module Commands
12
12
  class Data < Noop
13
13
  def run(args=[])
14
- rest = optparse.order(args)
14
+ rest = order_args(args)
15
15
  case rest.first
16
16
  when "bag"
17
17
  data_bag(rest.slice(1..-1) || [])
@@ -8,7 +8,7 @@ class Chef
8
8
  module Commands
9
9
  class Databag < Data
10
10
  def run(args=[])
11
- rest = optparse.order(args)
11
+ rest = order_args(args)
12
12
  data_bag(rest)
13
13
  end
14
14
  end
@@ -10,7 +10,7 @@ class Chef
10
10
  module Commands
11
11
  class Environment < Noop
12
12
  def run(args=[])
13
- rest = optparse.order(args)
13
+ rest = order_args(args)
14
14
  case rest.first
15
15
  when "edit"
16
16
  environment_edit(rest.slice(1..-1) || [])
@@ -10,7 +10,8 @@ class Chef
10
10
  module Commands
11
11
  class Help < Noop
12
12
  def run(args=[])
13
- if command = args.shift
13
+ rest = order_args(args)
14
+ if command = rest.shift
14
15
  case command
15
16
  when "commands"
16
17
  paths = $LOAD_PATH.map { |path|
@@ -10,7 +10,7 @@ class Chef
10
10
  module Commands
11
11
  class Node < Noop
12
12
  def run(args=[])
13
- rest = optparse.order(args)
13
+ rest = order_args(args)
14
14
  case rest.first
15
15
  when "edit"
16
16
  node_edit(rest.slice(1..-1) || [])
@@ -19,7 +19,7 @@ class Chef
19
19
  when "show"
20
20
  node_show(rest.slice(1..-1) || [])
21
21
  else
22
- raise(NameError.new(rest.inspect))
22
+ raise(NameError.new(@args.inspect))
23
23
  end
24
24
  end
25
25
 
@@ -10,7 +10,7 @@ class Chef
10
10
  module Commands
11
11
  class Role < Noop
12
12
  def run(args=[])
13
- rest = optparse.order(args)
13
+ rest = order_args(args)
14
14
  case rest.first
15
15
  when "edit"
16
16
  role_edit(rest.slice(1..-1) || [])
@@ -9,7 +9,8 @@ class Chef
9
9
  module Commands
10
10
  class Ssh < Noop
11
11
  def run(args=[])
12
- rest = optparse.order(args)
12
+ rest = order_args(args)
13
+ rest = rest.dup
13
14
  if hostname = rest.shift
14
15
  ssh(hostname, rest)
15
16
  end
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  class Fork
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-fork
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yamashita Yuu
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
11
  date: 2015-06-26 00:00:00.000000000 Z
12
12
  dependencies:
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: A tool for your left hand, to have a meal cooked by chef.
70
70
  email:
71
71
  - peek824545201@gmail.com
72
- executables: []
72
+ executables:
73
+ - fork
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files: