Class: Dockerun::CliEngine

Inherits:
Object
  • Object
show all
Includes:
TR::ArgUtils
Defined in:
lib/dockerun/cli_engine.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.pmtObject



114
115
116
117
118
119
# File 'lib/dockerun/cli_engine.rb', line 114

def self.pmt
  if @_pmt.nil?
    @_pmt = TTY::Prompt.new
  end
  @_pmt
end

.select_spec(root) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dockerun/cli_engine.rb', line 52

def self.select_spec(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)

  #sel = Dir.entries(Dir.getwd).sort
  sel = Dir.entries(root).sort
  default = sel.select { |e| (e =~ /^dockerspec/) != nil }
  selSpec = pmt.select(" Please select the dockerspec to proceed : ", filter: true, default: default.first) do |m|
    sel.each do |s|
      next if sel == "." or sel == ".." or File.directory?(s)
      m.choice s, File.expand_path(s)
    end
  end

  selSpec
end

Instance Method Details

#clean_env(root) ⇒ Object



102
103
104
105
106
107
108
109
110
111
112
# File 'lib/dockerun/cli_engine.rb', line 102

def clean_env(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)
  root = File.expand_path(root)

  Dir.glob(File.join(root,"Dockerfile-*")).each do |f|
    FileUtils.rm(f)
  end
  pa = File.join(root,"script_for_gem.sh")
  FileUtils.rm(pa) if File.exist?(pa)
  self.class.pmt.puts " Generated Dockerfile-* and script_for_gem.sh is deleted at '#{root}'".green
end

#delete_container(root) ⇒ Object



88
89
90
91
92
93
# File 'lib/dockerun/cli_engine.rb', line 88

def delete_container(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)
  root = File.expand_path(root)
  d = Dockerun::Cli::DeleteContainer.new
  d.start(root)
end

#delete_image(root) ⇒ Object



95
96
97
98
99
100
# File 'lib/dockerun/cli_engine.rb', line 95

def delete_image(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)
  root = File.expand_path(root)
  d = Dockerun::Cli::DeleteImage.new
  d.start(root)
end

#init(root) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/dockerun/cli_engine.rb', line 69

def init(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)

  root = File.expand_path(root)
  template = File.join(File.dirname(__FILE__),"..","..","dockerspec.sample")        
  if File.exist?(template)
    #FileUtils.cp template, File.join(Dir.getwd, "dockerspec.sample")
    FileUtils.cp template, File.join(root, "dockerspec.sample")
  end
end


40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dockerun/cli_engine.rb', line 40

def print_help
  pmt = self.class.pmt
  pmt.puts ""
  pmt.puts " Dockerun version #{Dockerun::VERSION}".magenta
  pmt.puts ""
  pmt.puts " Supported options : "
  self.class.arg_options.each do |key, val|
    pmt.puts " #{key}\t\t#{val[:desc]}"
  end
  pmt.puts ""
end

#run(root) ⇒ Object



80
81
82
83
84
85
86
# File 'lib/dockerun/cli_engine.rb', line 80

def run(root)
  raise InsufficientParameter, "Given path cannot be empty or nil" if is_empty?(root)

  root = File.expand_path(root)
  r = Dockerun::Cli::Run.new
  r.start(root)
end