class CommandBase

Public Class Methods

new() click to toggle source
# File src/commands/base.rb, line 4
def initialize
    @fileLocation = File.join(Dir.home, '.shuttl')
    File.open(File.join(@fileLocation, 'info'), 'r') do |fi|
        @info = JSON.parse(fi.read)
    end
    @cwd = Dir.getwd
    auth = {}
    # if @info.key?('token')
    #     auth = {'Authorization': "Token #{@info['token']}"}
    # end
    @api = ShuttlAPI.new ShuttlSettings::APIURL, auth
end

Public Instance Methods

cleanUp(options) click to toggle source
# File src/commands/base.rb, line 26
def cleanUp (options)
    File.open(File.join(Dir.home, '.shuttl/info'), 'w') do |fi|
        fi.write @info.to_json
    end
end
handle(options, args) click to toggle source
# File src/commands/base.rb, line 17
def handle (options, args)
    @args = args
    self.run options
    self.cleanUp options
end
hasImage?() click to toggle source
# File src/commands/base.rb, line 32
def hasImage?
    hasImage = @info['images'].key?(@cwd)
    if hasImage
        @current_image_info = @info['images'][@cwd]            
        @image = Docker::Image.get(@info['images'][@cwd]["image_id"])
    end
    hasImage
end
isRunning?() click to toggle source
# File src/commands/base.rb, line 41
def isRunning?
    if (@info['containers'].key?(@cwd))
        begin
            @container = Docker::Container.get(@info['containers'][@cwd]["container_id"])
        rescue Docker::Error::NotFoundError
            @info['containers'].delete(@cwd)
            return false
        end
        return @container.json['State']['Running']
    end
    false
end
run(options) click to toggle source
# File src/commands/base.rb, line 23
def run (options)
end