Class: Dister::Cli

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/dister/cli.rb

Overview

This is the public facing command line interface which is available through the dister command line tool. Use dister –help for usage instructions.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.source_rootString

NOTE: Some of Thor’s actions require this method to be defined.

Returns:

  • (String)

    Dister’s root directory.



11
12
13
# File 'lib/dister/cli.rb', line 11

def self.source_root
  File.expand_path('../../',__FILE__)
end

Instance Method Details

#basesystems



122
123
124
125
# File 'lib/dister/cli.rb', line 122

def basesystems
  access_core
  puts @core.basesystems.sort
end

#build



66
67
68
69
70
71
72
73
74
# File 'lib/dister/cli.rb', line 66

def build
  access_core
  ensure_appliance_exists
  if @core.build options
    puts "Appliance successfully built."
  else
    puts "Build failed."
  end
end

#bundle



128
129
130
131
132
133
134
# File 'lib/dister/cli.rb', line 128

def bundle
  access_core
  @core.package_gems
  @core.package_config_files
  # Package app last, since it will tarball the application including all gems.
  @core.package_app
end

#config(option, value)



24
25
26
27
# File 'lib/dister/cli.rb', line 24

def config option, value
  dister_options = Dister::Options.new(!options[:local].nil?)
  dister_options.send("#{option}=", value)
end

#create(appliance_name)



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/dister/cli.rb', line 33

def create(appliance_name)
  # Check parameters.
  access_core
  ensure_valid_option options[:arch], VALID_ARCHS, "arch"
  ensure_valid_option options[:template], VALID_TEMPLATES, "template"
  basesystems = @core.basesystems
  if basesystems.empty?
    STDERR.puts "No basesystem found, contact server administrator"
    exit 1
  end

  if options[:basesystem].nil?
    # attempt to find latest version of openSUSE
    basesystem = basesystems.find_all{|a| a =~ /\d+\.\d+/}.sort.last
    if basesystem.nil?
      # apparently this server doesn't offer openSUSE basesystem, so we
      # present the user with a menu with available choices
      basesystem = choose do |menu|
        menu.header = "Available base systems"
        menu.choices *basesystems
        menu.prompt = "Which base system do you want to use?"
      end
    end
  else
    basesystem = options[:basesystem]
  end
  ensure_valid_option basesystem, basesystems, "base system"
  # Create appliance and add patterns required to build native gems.
  @core.create_appliance(appliance_name, options[:template], basesystem, options[:arch])
end

#download



77
78
79
80
81
82
# File 'lib/dister/cli.rb', line 77

def download
  access_core
  ensure_appliance_exists
  ensure_build_exists
  @core.download(@builds)
end

#format(operation, format = nil)



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/dister/cli.rb', line 94

def format(operation,format = nil)
  access_core
  ensure_valid_option operation, %w(add rm list), "operation"
  if operation == 'list'
    puts "Available formats:"
    puts VALID_FORMATS
  else
    existing_types = @core.options.build_types || []
    chosen_types = case operation
      when "add"
        ensure_valid_option format, VALID_FORMATS, "format"
        @core.options.build_types = (existing_types + [format]).uniq
      when "rm"
        @core.options.build_types = (existing_types - [format])
      else
        existing_types
      end
    puts "Chosen formats:"
    puts chosen_types
  end
end

#info



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
# File 'lib/dister/cli.rb', line 165

def info
  access_core
  app = Utils::execute_printing_progress "Contacting SUSE Studio" do
    @core.appliance
  end
  puts "Name: #{app.name}"
  puts "Based on: #{app.parent.name}"
  if app.builds.empty?
    puts "No builds yet."
  else
    puts "Builds:"
    app.builds.each do |b|
      puts "  - #{b.image_type}, version #{b.version}"
    end
  end
  puts "Edit url: #{app.edit_url}"
end

#package(operation, *package)



146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/dister/cli.rb', line 146

def package operation, *package
  access_core
  valid_operations = %w(add rm)
  ensure_valid_option operation, valid_operations, "operation"
  case operation
  when "add"
    package.each do |p|
      @core.add_package p
    end
  when "rm"
    package.each do |p|
      @core.rm_package p
    end
  end
  @core.verify_status
  puts "Done."
end

#push



137
138
139
140
141
142
143
# File 'lib/dister/cli.rb', line 137

def push
  access_core
  # Always call 'bundle' to ensure we got the latest version bundled.
  invoke :bundle
  ensure_appliance_exists
  @core.upload_bundled_files
end

#templates



117
118
119
# File 'lib/dister/cli.rb', line 117

def templates
  puts VALID_TEMPLATES.sort
end

#testdrive



85
86
87
88
89
90
# File 'lib/dister/cli.rb', line 85

def testdrive
  access_core
  ensure_appliance_exists
  ensure_build_exists
  @core.testdrive(@builds)
end

#version



16
17
18
19
# File 'lib/dister/cli.rb', line 16

def version
  require "dister/version"
  puts "dister version #{Dister::VERSION}"
end