berkshelf 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,22 +1,17 @@
1
- Copyright (c) 2012 Riot Games
1
+ Author:: Jamie Winsor (<jamie@vialstudios.com>)
2
+ Author:: Josiah Kiehl (<josiah@skirmisher.net>)
3
+ Author:: Michael Ivey (<ivey@gweezlebur.com>)
2
4
 
3
- MIT License
5
+ Copyright 2012 Riot Games
4
6
 
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
7
+ Licensed under the Apache License, Version 2.0 (the "License");
8
+ you may not use this file except in compliance with the License.
9
+ You may obtain a copy of the License at
12
10
 
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
11
+ http://www.apache.org/licenses/LICENSE-2.0
15
12
 
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13
+ Unless required by applicable law or agreed to in writing, software
14
+ distributed under the License is distributed on an "AS IS" BASIS,
15
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ See the License for the specific language governing permissions and
17
+ limitations under the License.
data/README.md CHANGED
@@ -16,7 +16,7 @@ See [berkshelf.com](http://berkshelf.com) for up-to-date usage instructions.
16
16
 
17
17
  ### Install prerequisites
18
18
 
19
- Install the latest version of {Bundler}[http://gembundler.com]
19
+ Install the latest version of [Bundler](http://gembundler.com)
20
20
 
21
21
  $ gem install bundler
22
22
 
data/bin/berks ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ $:.push File.expand_path("../../lib", __FILE__)
3
+ require 'berkshelf'
4
+
5
+ Berkshelf::Cli.start
@@ -27,31 +27,31 @@ Then /^the file "(.*?)" should contain in the current directory:$/ do |filename,
27
27
  end
28
28
 
29
29
  When /^I run the init command with the cookbook "(.*?)" as the target$/ do |cookbook_name|
30
- run_simple(unescape("knife berks init #{cookbook_name}"), false)
30
+ run_simple(unescape("berks init #{cookbook_name}"), true)
31
31
  end
32
32
 
33
33
  When /^I run the init command with the directory "(.*?)" as the target$/ do |directory_name|
34
- run_simple(unescape("knife berks init #{directory_name}"), false)
34
+ run_simple(unescape("berks init #{directory_name}"), true)
35
35
  end
36
36
 
37
37
  When /^I run the init command with no value for the target$/ do
38
- run_simple(unescape("knife berks init"), false)
38
+ run_simple(unescape("berks init"), true)
39
39
  end
40
40
 
41
41
  When /^I run the install command$/ do
42
- run_simple(unescape("knife berks install"), true)
42
+ run_simple(unescape("berks install"), true)
43
43
  end
44
44
 
45
45
  When /^I run the install command with flags:$/ do |flags|
46
- run_simple(unescape("knife berks install #{flags.raw.join(" ")}"), true)
46
+ run_simple(unescape("berks install #{flags.raw.join(" ")}"), true)
47
47
  end
48
48
 
49
49
  When /^I run the update command$/ do
50
- run_simple(unescape("knife berks update"), false)
50
+ run_simple(unescape("berks update"), true)
51
51
  end
52
52
 
53
53
  When /^I run the upload command$/ do
54
- run_simple(unescape("knife berks upload"), false)
54
+ run_simple(unescape("berks upload"), true)
55
55
  end
56
56
 
57
57
  Then /^the CLI should exit with the status code for error "(.*?)"$/ do |error_constant|
data/lib/berkshelf.rb CHANGED
@@ -17,6 +17,7 @@ module Berkshelf
17
17
  DEFAULT_STORE_PATH = File.expand_path("~/.berkshelf").freeze
18
18
  DEFAULT_FILENAME = 'Berksfile'.freeze
19
19
 
20
+ autoload :Cli, 'berkshelf/cli'
20
21
  autoload :DSL, 'berkshelf/dsl'
21
22
  autoload :Git, 'berkshelf/git'
22
23
  autoload :Berksfile, 'berkshelf/berksfile'
@@ -37,7 +38,7 @@ module Berkshelf
37
38
  attr_accessor :downloader
38
39
 
39
40
  def root
40
- File.join(File.dirname(__FILE__), '..')
41
+ @root ||= Pathname.new(File.expand_path('../', File.dirname(__FILE__)))
41
42
  end
42
43
 
43
44
  def ui
@@ -0,0 +1,152 @@
1
+ require 'thor'
2
+ require 'berkshelf'
3
+
4
+ module Berkshelf
5
+ # @author Jamie Winsor <jamie@vialstudios.com>
6
+ class Cli < Thor
7
+ def initialize(*)
8
+ super
9
+ # JW TODO: Replace Chef::Knife::UI with our own UI class
10
+ ::Berkshelf.ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
11
+ load_config
12
+ @options = options.dup # unfreeze frozen options Hash from Thor
13
+ rescue BerkshelfError => e
14
+ Berkshelf.ui.fatal e
15
+ exit e.status_code
16
+ end
17
+
18
+ namespace "berkshelf"
19
+
20
+ map 'in' => :install
21
+ map 'up' => :upload
22
+ map 'ud' => :update
23
+ map 'ver' => :version
24
+
25
+ class_option :config,
26
+ type: :string,
27
+ default: File.expand_path("~/.chef/knife.rb"),
28
+ desc: "Path to Knife or Chef configuration to use.",
29
+ aliases: "-c",
30
+ banner: "PATH"
31
+
32
+ method_option :shims,
33
+ type: :string,
34
+ default: nil,
35
+ desc: "Create a directory of shims pointing to Cookbook Versions.",
36
+ banner: "PATH"
37
+ method_option :without,
38
+ type: :array,
39
+ default: Array.new,
40
+ desc: "Exclude cookbooks that are in these groups.",
41
+ aliases: "-w"
42
+ method_option :berksfile,
43
+ type: :string,
44
+ default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
45
+ desc: "Path to a Berksfile to operate off of.",
46
+ aliases: "-b",
47
+ banner: "PATH"
48
+ desc "install", "Install the Cookbooks specified by a Berksfile or a Berskfile.lock."
49
+ def install
50
+ if options[:shims] == "shims" # This means 'no value given'.
51
+ options[:shims] = default_shims_path
52
+ end
53
+
54
+ berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
55
+ berksfile.install(options)
56
+ rescue BerkshelfError => e
57
+ Berkshelf.ui.fatal e
58
+ exit e.status_code
59
+ end
60
+
61
+ method_option :berksfile,
62
+ type: :string,
63
+ default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
64
+ desc: "Path to a Berksfile to operate off of.",
65
+ aliases: "-b",
66
+ banner: "PATH"
67
+ method_option :without,
68
+ type: :array,
69
+ default: Array.new,
70
+ desc: "Exclude cookbooks that are in these groups.",
71
+ aliases: "-w"
72
+ desc "update", "Update all Cookbooks and their dependencies specified by a Berksfile to their latest versions."
73
+ def update
74
+ Lockfile.remove!
75
+ invoke :install
76
+ rescue BerkshelfError => e
77
+ Berkshelf.ui.fatal e
78
+ exit e.status_code
79
+ end
80
+
81
+ method_option :berksfile,
82
+ type: :string,
83
+ default: File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME),
84
+ desc: "Path to a Berksfile to operate off of.",
85
+ aliases: "-b",
86
+ banner: "PATH"
87
+ method_option :without,
88
+ type: :array,
89
+ default: Array.new,
90
+ desc: "Exclude cookbooks that are in these groups.",
91
+ aliases: "-w"
92
+ method_option :freeze,
93
+ type: :boolean,
94
+ default: false,
95
+ desc: "Freeze the uploaded cookbooks so that they cannot be overwritten"
96
+ option :force,
97
+ type: :boolean,
98
+ default: false,
99
+ desc: "Upload all cookbooks even if a frozen one exists on the target Chef Server"
100
+ desc "upload", "Upload the Cookbooks specified by a Berksfile or a Berksfile.lock to a Chef Server."
101
+ def upload
102
+ berksfile = ::Berkshelf::Berksfile.from_file(options[:berksfile])
103
+ berksfile.upload(Chef::Config[:chef_server_url], options)
104
+ rescue BerkshelfError => e
105
+ Berkshelf.ui.fatal e
106
+ exit e.status_code
107
+ end
108
+
109
+ desc "init [PATH]", "Prepare a local path to have it's Cookbook dependencies managed by Berkshelf."
110
+ def init(path = Dir.pwd)
111
+ if File.chef_cookbook?(path)
112
+ options[:chefignore] = true
113
+ options[:metadata_entry] = true
114
+ end
115
+
116
+ generator = ::Berkshelf::InitGenerator.new([path], options)
117
+ generator.invoke_all
118
+
119
+ ::Berkshelf.ui.info "Successfully initialized"
120
+ rescue BerkshelfError => e
121
+ Berkshelf.ui.fatal e
122
+ exit e.status_code
123
+ end
124
+
125
+ desc "version", "Display version and copyright information"
126
+ def version
127
+ Berkshelf.ui.info version_header
128
+ Berkshelf.ui.info "\n"
129
+ Berkshelf.ui.info license
130
+ end
131
+
132
+ private
133
+
134
+ def version_header
135
+ "Berkshelf (#{Berkshelf::VERSION})"
136
+ end
137
+
138
+ def license
139
+ File.read(Berkshelf.root.join('LICENSE'))
140
+ end
141
+
142
+ def load_config
143
+ Chef::Config.from_file(File.expand_path(options[:config]))
144
+ rescue Errno::ENOENT
145
+ raise KnifeConfigNotFound, "Unable to find a Knife config at #{options[:config]}. Specify a different path with --config."
146
+ end
147
+
148
+ def default_shims_path
149
+ File.join(Dir.pwd, "cookbooks")
150
+ end
151
+ end
152
+ end
@@ -17,4 +17,5 @@ module Berkshelf
17
17
  class NoSolution < BerkshelfError; status_code(106); end
18
18
  class CookbookSyntaxError < BerkshelfError; status_code(107); end
19
19
  class UploadFailure < BerkshelfError; status_code(108); end
20
+ class KnifeConfigNotFound < BerkshelfError; status_code(109); end
20
21
  end
@@ -3,9 +3,15 @@ require 'thor/group'
3
3
  module Berkshelf
4
4
  # @author Jamie Winsor <jamie@vialstudios.com>
5
5
  class InitGenerator < Thor::Group
6
+ class << self
7
+ def source_root
8
+ File.expand_path(File.join(File.dirname(__FILE__), "generator_files"))
9
+ end
10
+ end
11
+
6
12
  include Thor::Actions
7
13
 
8
- class_option :path,
14
+ argument :path,
9
15
  :type => :string,
10
16
  :required => true
11
17
 
@@ -17,22 +23,14 @@ module Berkshelf
17
23
  :type => :boolean,
18
24
  :default => false
19
25
 
20
- def self.source_root
21
- File.expand_path(File.join(File.dirname(__FILE__), "generator_files"))
22
- end
23
-
24
26
  def generate
27
+ target_path = File.expand_path(path)
28
+
25
29
  template "Berksfile.erb", File.join(target_path, "Berksfile")
26
30
 
27
31
  if options[:chefignore]
28
32
  copy_file "chefignore", File.join(target_path, ".chefignore")
29
33
  end
30
34
  end
31
-
32
- private
33
-
34
- def target_path
35
- @target_path ||= File.expand_path(options[:path])
36
- end
37
35
  end
38
36
  end
@@ -1,43 +1 @@
1
- require 'berkshelf'
2
-
3
- module Berkshelf
4
- class ThorTasks < Thor
5
- namespace "berkshelf"
6
-
7
- method_option :config,
8
- type: :string,
9
- aliases: "-c",
10
- desc: "Knife configuration file to use.",
11
- default: File.expand_path("~/.chef/knife.rb")
12
- method_option :without,
13
- type: :array,
14
- aliases: "-w",
15
- desc: "Exclude cookbooks that are in these groups",
16
- default: Array.new
17
- method_option :force,
18
- type: :boolean,
19
- desc: "Fail the build if any of the specified tags are matched.",
20
- default: false
21
- method_option :freeze,
22
- type: :boolean,
23
- desc: "Freeze the uploaded cookbooks so that they cannot be overwritten.",
24
- default: false
25
- desc "upload", "Upload the sources defined in your Berksfile and their dependencies to a Chef Server."
26
- def upload
27
- begin
28
- Chef::Config.from_file(File.expand_path(options[:config]))
29
- rescue Errno::ENOENT
30
- say "Unable to find a Knife config at #{options[:config]}. Specify a different path with --config.", :red
31
- exit(10)
32
- end
33
-
34
- ::Berkshelf.ui = Chef::Knife::UI.new(STDOUT, STDERR, STDIN, {})
35
- cookbook_file = ::Berkshelf::Berksfile.from_file(File.join(Dir.pwd, "Berksfile"))
36
- cookbook_file.upload(Chef::Config[:chef_server_url],
37
- without: options[:without],
38
- freeze: options[:freeze],
39
- force: options[:force]
40
- )
41
- end
42
- end
43
- end
1
+ require 'berkshelf/cli'
@@ -1,3 +1,3 @@
1
1
  module Berkshelf
2
- VERSION = "0.2.0"
2
+ VERSION = "0.3.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: berkshelf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2012-06-24 00:00:00.000000000 Z
15
+ date: 2012-06-25 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: dep_selector
@@ -340,7 +340,8 @@ email:
340
340
  - jamie@vialstudios.com
341
341
  - ivey@gweezlebur.com
342
342
  - erik@hollensbe.org
343
- executables: []
343
+ executables:
344
+ - berks
344
345
  extensions: []
345
346
  extra_rdoc_files: []
346
347
  files:
@@ -352,6 +353,7 @@ files:
352
353
  - README.md
353
354
  - Thorfile
354
355
  - berkshelf.gemspec
356
+ - bin/berks
355
357
  - features/config.sample.yml
356
358
  - features/init_command.feature
357
359
  - features/install.feature
@@ -367,6 +369,7 @@ files:
367
369
  - lib/berkshelf.rb
368
370
  - lib/berkshelf/berksfile.rb
369
371
  - lib/berkshelf/cached_cookbook.rb
372
+ - lib/berkshelf/cli.rb
370
373
  - lib/berkshelf/cookbook_source.rb
371
374
  - lib/berkshelf/cookbook_source/git_location.rb
372
375
  - lib/berkshelf/cookbook_source/path_location.rb
@@ -391,10 +394,6 @@ files:
391
394
  - lib/berkshelf/tx_result_set.rb
392
395
  - lib/berkshelf/uploader.rb
393
396
  - lib/berkshelf/version.rb
394
- - lib/chef/knife/berks_init.rb
395
- - lib/chef/knife/berks_install.rb
396
- - lib/chef/knife/berks_update.rb
397
- - lib/chef/knife/berks_upload.rb
398
397
  - spec/fixtures/Berksfile
399
398
  - spec/fixtures/cookbooks/example_cookbook-0.5.0/README.md
400
399
  - spec/fixtures/cookbooks/example_cookbook-0.5.0/metadata.rb
@@ -459,7 +458,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
459
458
  version: '0'
460
459
  segments:
461
460
  - 0
462
- hash: -3927630543327707547
461
+ hash: 2507702980010171500
463
462
  requirements: []
464
463
  rubyforge_project:
465
464
  rubygems_version: 1.8.23
@@ -1,29 +0,0 @@
1
- require 'chef/knife'
2
-
3
- module Berkshelf
4
- class BerksInit < Chef::Knife
5
- deps do
6
- require 'berkshelf'
7
- end
8
-
9
- banner "knife berks init [PATH]"
10
-
11
- def run
12
- ::Berkshelf.ui = ui
13
- config[:path] = File.expand_path(@name_args.first || Dir.pwd)
14
-
15
- if File.chef_cookbook?(config[:path])
16
- config[:chefignore] = true
17
- config[:metadata_entry] = true
18
- end
19
-
20
- generator = ::Berkshelf::InitGenerator.new([], config)
21
- generator.invoke_all
22
-
23
- ::Berkshelf.ui.info "Successfully initialized"
24
- rescue BerkshelfError => e
25
- Berkshelf.ui.fatal e
26
- exit e.status_code
27
- end
28
- end
29
- end
@@ -1,42 +0,0 @@
1
- require 'chef/knife'
2
-
3
- module Berkshelf
4
- class BerksInstall < Chef::Knife
5
- deps do
6
- require 'berkshelf'
7
- end
8
-
9
- banner "knife berks install (options)"
10
-
11
- option :shims,
12
- short: "-s",
13
- long: "--shims",
14
- description: "Create a directory of shims pointing to Cookbook Versions.",
15
- boolean: true
16
- option :without,
17
- short: "-W WITHOUT",
18
- long: "--without WITHOUT",
19
- description: "Exclude cookbooks that are in these groups",
20
- proc: lambda { |w| w.split(",") },
21
- default: Array.new
22
- def run
23
- ::Berkshelf.ui = ui
24
- # JW TODO: replace knife with Thor bin. Opt parsing here isn't my favorite.
25
- if config[:shims]
26
- config[:shims] = shims_path
27
- end
28
-
29
- cookbook_file = ::Berkshelf::Berksfile.from_file(File.join(Dir.pwd, Berkshelf::DEFAULT_FILENAME))
30
- cookbook_file.install(config)
31
- rescue BerkshelfError => e
32
- Berkshelf.ui.fatal e
33
- exit e.status_code
34
- end
35
-
36
- private
37
-
38
- def shims_path
39
- File.join(Dir.pwd, "cookbooks")
40
- end
41
- end
42
- end
@@ -1,24 +0,0 @@
1
- require 'chef/knife'
2
- require 'chef/knife/berks_install'
3
-
4
- module Berkshelf
5
- class BerksUpdate < BerksInstall
6
- deps do
7
- require 'berkshelf'
8
- end
9
-
10
- banner "knife berks update"
11
-
12
- alias :install_run :run
13
-
14
- def run
15
- ::Berkshelf.ui = ui
16
-
17
- Lockfile.remove!
18
- install_run
19
- rescue BerkshelfError => e
20
- Berkshelf.ui.fatal e
21
- exit e.status_code
22
- end
23
- end
24
- end
@@ -1,39 +0,0 @@
1
- require 'chef/knife'
2
-
3
- module Berkshelf
4
- class BerksUpload < Chef::Knife
5
- deps do
6
- require 'berkshelf'
7
- end
8
-
9
- banner "knife berks upload (options)"
10
-
11
- option :without,
12
- :short => "-W WITHOUT",
13
- :long => "--without WITHOUT",
14
- :description => "Exclude cookbooks that are in these groups",
15
- :proc => lambda { |w| w.split(",") },
16
- :default => Array.new
17
-
18
- option :freeze,
19
- :long => "--freeze",
20
- :description => "Freeze the uploaded cookbooks so that they cannot be overwritten",
21
- :boolean => true,
22
- :default => false
23
-
24
- option :force,
25
- :long => "--force",
26
- :description => "Upload all cookbooks even if a frozen one exists on the target Chef Server",
27
- :boolean => true,
28
- :default => false
29
-
30
- def run
31
- ::Berkshelf.ui = ui
32
- cookbook_file = ::Berkshelf::Berksfile.from_file(File.join(Dir.pwd, "Berksfile"))
33
- cookbook_file.upload(Chef::Config[:chef_server_url], config)
34
- rescue BerkshelfError => e
35
- Berkshelf.ui.fatal e
36
- exit e.status_code
37
- end
38
- end
39
- end