class Maintainer::InstructionParser

Public Class Methods

parse(line) click to toggle source
# File lib/maintainer_core/instructions.rb, line 350
def parse(line)
    inst_elm = line.split
    cmd = inst_elm[0]
    case cmd
    when "pip"
        package = inst_elm[1]
        msg_success = inst_elm[2] if inst_elm[2]
        msg_error =  inst_elm[3] if inst_elm[3]
        should_crash = inst_elm[4] == "true" if inst_elm[4]
        return PIPInstall.new(
            package, 
            msg_success, 
            msg_error, 
            should_crash
        )
    when "git"
        subcmd = inst_elm[1]
        remote = inst_elm[2]
        branch = inst_elm[3] if inst_elm[3]
        case subcmd
        when "fork"
            puts "github username: "
            username = STDIN.gets.chomp
            password = STDIN.getpass("Password: ")
            return GITFork.new(
                remote, 
                username, 
                password, 
                msg_success, 
                msg_error, 
                should_crash
            )
        when "pull"
            return GITPull.new(
                remote, 
                branch, 
                msg_success, 
                msg_error, 
                should_crash
            )
        when "clone"
            puts "github username: "
            username = STDIN.gets.chomp
            return GITClone.new(
                remote, 
                username, 
                msg_success, 
                msg_error, 
                should_crash
            )
        else
        end
    when "bash"
        subcmd = inst_elm[1]
        path = inst_elm[2]
        case subcmd
        when "run"
            return BashRun.new(
                path, 
                msg_success, 
                msg_error, 
                should_crash
            )
        else
        end
    when "cd"
        path = inst_elm[1]
        return CDInst.new(
            path, 
            msg_success, 
            msg_error, 
            should_crash
        )
    else
        puts "The command #{cmd} is not supported"
    end
end