knife-essentials 0.6.1 → 0.7

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.
@@ -0,0 +1,33 @@
1
+ require 'chef_fs/knife'
2
+ require 'chef_fs/file_system'
3
+
4
+ class Chef
5
+ class Knife
6
+ class Delete < ChefFS::Knife
7
+ banner "delete [PATTERN1 ... PATTERNn]"
8
+
9
+ common_options
10
+
11
+ option :recurse,
12
+ :long => '--[no-]recurse',
13
+ :boolean => true,
14
+ :default => false,
15
+ :description => "Delete directories recursively."
16
+
17
+ def run
18
+ # Get the matches (recursively)
19
+ pattern_args.each do |pattern|
20
+ ChefFS::FileSystem.list(chef_fs, pattern) do |result|
21
+ begin
22
+ result.delete(config[:recurse])
23
+ puts "Deleted #{result.path_for_printing}"
24
+ rescue ChefFS::FileSystem::NotFoundError
25
+ STDERR.puts "result.path_for_printing}: No such file or directory"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+
@@ -13,14 +13,14 @@ class Chef
13
13
  pattern_args.each do |pattern|
14
14
  ChefFS::FileSystem.list(chef_fs, pattern) do |result|
15
15
  if result.dir?
16
- STDERR.puts "#{format_path(result.path)}: is a directory" if pattern.exact_path
16
+ STDERR.puts "#{result.path_for_printing}: is a directory" if pattern.exact_path
17
17
  else
18
18
  begin
19
19
  value = result.read
20
- puts "#{format_path(result.path)}:"
20
+ puts "#{result.path_for_printing}:"
21
21
  output(format_for_display(value))
22
22
  rescue ChefFS::FileSystem::NotFoundError
23
- STDERR.puts "#{format_path(result.path)}: No such file or directory" if pattern.exact_path
23
+ STDERR.puts "#{result.path_for_printing}: No such file or directory"
24
24
  end
25
25
  end
26
26
  end
@@ -96,9 +96,9 @@ module ChefFS
96
96
  #
97
97
  def self.copy_to(pattern, src_root, dest_root, recurse_depth, options)
98
98
  found_result = false
99
- list_pairs(pattern, src_root, dest_root) do |a, b|
99
+ list_pairs(pattern, src_root, dest_root) do |src, dest|
100
100
  found_result = true
101
- copy_entries(a, b, recurse_depth, options)
101
+ copy_entries(src, dest, recurse_depth, options)
102
102
  end
103
103
  if !found_result && pattern.exact_path
104
104
  puts "#{pattern}: No such file or directory on remote or local"
@@ -215,8 +215,8 @@ module ChefFS
215
215
  if options[:dry_run]
216
216
  puts "Would delete #{dest_entry.path_for_printing}"
217
217
  else
218
- dest_entry.delete
219
- puts "Delete extra entry #{dest_entry.path_for_printing} (purge is on)"
218
+ dest_entry.delete(true)
219
+ puts "Deleted extra entry #{dest_entry.path_for_printing} (purge is on)"
220
220
  end
221
221
  else
222
222
  Chef::Log.info("Not deleting extra entry #{dest_entry.path_for_printing} (purge is off)")
@@ -314,9 +314,7 @@ module ChefFS
314
314
  parent = entry.parent
315
315
  if !parent.exists?
316
316
  parent_parent = get_or_create_parent(entry.parent, options)
317
- if options[:dry_run]
318
- puts "Would create #{parent.path_for_printing}"
319
- else
317
+ if !options[:dry_run]
320
318
  parent = parent_parent.create_child(parent.name, true)
321
319
  puts "Created #{parent.path_for_printing}"
322
320
  end
@@ -50,12 +50,15 @@ module ChefFS
50
50
  if repo_mode == 'everything'
51
51
  result += [
52
52
  RestListDir.new("clients", self),
53
- NodesDir.new(self)
53
+ NodesDir.new(self),
54
+ RestListDir.new("users", self)
54
55
  ]
55
56
  end
56
57
  result.sort_by { |child| child.name }
57
58
  end
58
59
  end
60
+
61
+ # Yeah, sorry, I'm not putting delete on this thing.
59
62
  end
60
63
  end
61
64
  end
@@ -103,6 +103,9 @@ module ChefFS
103
103
  end
104
104
 
105
105
  def compare_to(other)
106
+ if !other.dir?
107
+ return [ !exists?, nil, nil ]
108
+ end
106
109
  are_same = true
107
110
  ChefFS::CommandLine::diff_entries(self, other, nil, :name_only) do
108
111
  are_same = false
@@ -1,6 +1,7 @@
1
1
  require 'chef_fs/file_system/rest_list_dir'
2
2
  require 'chef_fs/file_system/data_bag_item'
3
3
  require 'chef_fs/file_system/not_found_error'
4
+ require 'chef_fs/file_system/must_delete_recursively_error'
4
5
 
5
6
  module ChefFS
6
7
  module FileSystem
@@ -30,6 +31,18 @@ module ChefFS
30
31
  DataBagItem.new(name, self, exists)
31
32
  end
32
33
 
34
+ def delete(recurse)
35
+ if !recurse
36
+ raise ChefFS::FileSystem::MustDeleteRecursivelyError.new, "#{path_for_printing} must be deleted recursively"
37
+ end
38
+ begin
39
+ rest.delete_rest(api_path)
40
+ rescue Net::HTTPServerException
41
+ if $!.response.code == "404"
42
+ raise ChefFS::FileSystem::NotFoundError.new($!), "#{path_for_printing} not found"
43
+ end
44
+ end
45
+ end
33
46
  end
34
47
  end
35
48
  end
@@ -40,9 +40,13 @@ module ChefFS
40
40
  File.directory?(file_path)
41
41
  end
42
42
 
43
- def delete
43
+ def delete(recurse)
44
44
  if dir?
45
- FileUtils.rm_rf(file_path)
45
+ if recurse
46
+ FileUtils.rm_rf(file_path)
47
+ else
48
+ File.rmdir(file_path)
49
+ end
46
50
  else
47
51
  File.delete(file_path)
48
52
  end
@@ -0,0 +1,11 @@
1
+ module ChefFS
2
+ module FileSystem
3
+ class FileSystemError < StandardError
4
+ def initialize(cause = nil)
5
+ @cause = cause
6
+ end
7
+
8
+ attr_reader :cause
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ require 'chef_fs/file_system/file_system_error'
2
+
3
+ module ChefFS
4
+ module FileSystem
5
+ class MustDeleteRecursivelyError < FileSystemError
6
+ def initialize(cause = nil)
7
+ super(cause)
8
+ end
9
+ end
10
+ end
11
+ end
@@ -1,11 +1,11 @@
1
+ require 'chef_fs/file_system/file_system_error'
2
+
1
3
  module ChefFS
2
4
  module FileSystem
3
- class NotFoundError < StandardError
5
+ class NotFoundError < FileSystemError
4
6
  def initialize(cause = nil)
5
- @cause = cause
7
+ super(cause)
6
8
  end
7
-
8
- attr_reader :cause
9
9
  end
10
10
  end
11
11
  end
@@ -59,7 +59,6 @@ module ChefFS
59
59
  def _make_child_entry(name, exists = nil)
60
60
  RestListEntry.new(name, self, exists)
61
61
  end
62
-
63
62
  end
64
63
  end
65
64
  end
@@ -34,7 +34,7 @@ module ChefFS
34
34
  @exists
35
35
  end
36
36
 
37
- def delete
37
+ def delete(recurse)
38
38
  begin
39
39
  rest.delete_rest(api_path)
40
40
  rescue Net::HTTPServerException
@@ -1,4 +1,4 @@
1
1
  module ChefFS
2
- VERSION = "0.6.1"
2
+ VERSION = "0.7"
3
3
  end
4
4
 
@@ -140,20 +140,20 @@ describe ChefFS::FileSystem::ChefServerRootDir do
140
140
  root_dir.path_for_printing.should == 'remote/'
141
141
  end
142
142
  it 'has correct children' do
143
- root_dir.children.map { |child| child.name }.should =~ %w(clients cookbooks data_bags environments nodes roles)
143
+ root_dir.children.map { |child| child.name }.should =~ %w(clients cookbooks data_bags environments nodes roles users)
144
144
  end
145
145
  it 'can have children with the known names' do
146
- %w(clients cookbooks data_bags environments nodes roles).each { |child| root_dir.can_have_child?(child, true).should be_true }
146
+ %w(clients cookbooks data_bags environments nodes roles users).each { |child| root_dir.can_have_child?(child, true).should be_true }
147
147
  end
148
148
  it 'cannot have files as children' do
149
- %w(clients cookbooks data_bags environments nodes roles).each { |child| root_dir.can_have_child?(child, false).should be_false }
149
+ %w(clients cookbooks data_bags environments nodes roles users).each { |child| root_dir.can_have_child?(child, false).should be_false }
150
150
  root_dir.can_have_child?('blah', false).should be_false
151
151
  end
152
152
  it 'cannot have other child directories than the known names' do
153
153
  root_dir.can_have_child?('blah', true).should be_false
154
154
  end
155
155
  it 'child() responds to children' do
156
- %w(clients cookbooks data_bags environments nodes roles).each { |child| root_dir.child(child).exists?.should be_true }
156
+ %w(clients cookbooks data_bags environments nodes roles users).each { |child| root_dir.child(child).exists?.should be_true }
157
157
  end
158
158
  context 'nonexistent child()' do
159
159
  let(:nonexistent_child) { root_dir.child('blah') }
@@ -209,4 +209,11 @@ describe ChefFS::FileSystem::ChefServerRootDir do
209
209
 
210
210
  it_behaves_like 'a json rest endpoint dir'
211
211
  end
212
+
213
+ context 'root.child(users)' do
214
+ let(:endpoint_name) { 'users' }
215
+ let(:endpoint) { root_dir.child('users') }
216
+
217
+ it_behaves_like 'a json rest endpoint dir'
218
+ end
212
219
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-essentials
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: '0.7'
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -22,6 +22,7 @@ files:
22
22
  - LICENSE
23
23
  - README.rdoc
24
24
  - Rakefile
25
+ - lib/chef/knife/delete.rb
25
26
  - lib/chef/knife/diff.rb
26
27
  - lib/chef/knife/download.rb
27
28
  - lib/chef/knife/list.rb
@@ -44,7 +45,9 @@ files:
44
45
  - lib/chef_fs/file_system/data_bag_item.rb
45
46
  - lib/chef_fs/file_system/data_bags_dir.rb
46
47
  - lib/chef_fs/file_system/file_system_entry.rb
48
+ - lib/chef_fs/file_system/file_system_error.rb
47
49
  - lib/chef_fs/file_system/file_system_root_dir.rb
50
+ - lib/chef_fs/file_system/must_delete_recursively_error.rb
48
51
  - lib/chef_fs/file_system/nodes_dir.rb
49
52
  - lib/chef_fs/file_system/nonexistent_fs_object.rb
50
53
  - lib/chef_fs/file_system/not_found_error.rb