~ubuntu-branches/ubuntu/quantal/ruby-vmc/quantal-201206142105

« back to all changes in this revision

Viewing changes to lib/cli/commands/manifest.rb

  • Committer: Michael Terry
  • Date: 2012-06-14 17:21:18 UTC
  • mfrom: (5.1.1 ruby-vmc)
  • Revision ID: michael.terry@canonical.com-20120614172118-8m3f2k7ugyki6sir
New upstream release (LP: #998111).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module VMC::Cli::Command
 
2
  class Manifest < Base
 
3
    include VMC::Cli::ManifestHelper
 
4
 
 
5
    def initialize(options)
 
6
      super
 
7
 
 
8
      # don't resolve any of the manifest template stuff
 
9
      if manifest_file
 
10
        @manifest = load_manifest_structure manifest_file
 
11
      else
 
12
        @manifest = {}
 
13
      end
 
14
    end
 
15
 
 
16
    def edit
 
17
      build_manifest
 
18
      save_manifest
 
19
    end
 
20
 
 
21
    def extend(which)
 
22
      parent = load_manifest_structure which
 
23
      @manifest = load_manifest_structure which
 
24
 
 
25
      build_manifest
 
26
 
 
27
      simplify(@manifest, parent)
 
28
 
 
29
      @manifest["inherit"] ||= []
 
30
      @manifest["inherit"] << which
 
31
 
 
32
      save_manifest(ask("Save where?"))
 
33
    end
 
34
 
 
35
    private
 
36
 
 
37
    def simplify(child, parent)
 
38
      return unless child.is_a?(Hash) and parent.is_a?(Hash)
 
39
 
 
40
      child.reject! do |k, v|
 
41
        if v == parent[k]
 
42
          puts "rejecting #{k}"
 
43
          true
 
44
        else
 
45
          simplify(v, parent[k])
 
46
          false
 
47
        end
 
48
      end
 
49
    end
 
50
 
 
51
    def build_manifest
 
52
      @application = ask("Configure for which application?", :default => ".")
 
53
      interact true
 
54
    end
 
55
  end
 
56
end