Module: Commands

Defined in:
lib/commands/env.rb,
lib/commands/list.rb,
lib/commands/view.rb,
lib/commands/clone.rb,
lib/commands/create.rb,
lib/commands/delete.rb,
lib/commands/logout.rb

Instance Method Summary collapse

Instance Method Details

#clone(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
# File 'lib/commands/clone.rb', line 2

def clone(argv)
  app_id = argv.shift
  
  return false if app_id.nil?
  
  phpfog = PHPfog.new
  apps = phpfog.get_app(app_id)
    # this could be dangerous
  exec(apps['repo']) 
  true
end

#create(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/commands/create.rb', line 2

def create(argv)
  command = argv.shift
  
  case command
  when "app"
    
    cloud_id = argv.shift
    
    if cloud_id == '1' || cloud_id == 'shared'
      cloud_id = ''
    end 
    
    phpfog = PHPfog.new
    
    mysql_password = prompt 'MySQL Password: '
    if mysql_password.empty? 
      puts 'New app canceled'
      exit
    end
    
    domain_name = nil
    while domain_name == nil
      temp_domain_name = prompt 'Domain Name: '
      
      if temp_domain_name.empty? 
        puts bwhite 'New app canceled'
        exit
      end
      
      if phpfog.domain_available?(temp_domain_name)
        domain_name = temp_domain_name
      else
        puts bwhite 'Domain name not available. Try again.'
      end
    end

    app_id = phpfog.new_app(cloud_id, 16, domain_name, mysql_password)
    if !app_id.nil?
      puts bwhite 'New app created.' + "(ID:#{red app_id})"
    else
      puts bwhite 'New app failed to be created.'
    end
    
  else
    puts "Unknown Command: " + (command || '')
    return false
  end
  
  true
end

#delete(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/commands/delete.rb', line 2

def delete(argv)
  command = argv.shift
  
  case command
  when "app"
    app_id = argv.shift
    
    phpfog = PHPfog.new
    apps = phpfog.app_delete(app_id)
  else
    puts "Unknown Command: " + command
    return false
  end
  
  true
end

#env(argv) ⇒ Object



2
3
4
# File 'lib/commands/env.rb', line 2

def env(argv)
  
end

#list(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/commands/list.rb', line 2

def list(argv)
  command = argv.shift
  
  case command
  when "clouds"
   
    phpfog = PHPfog.new
    clouds = phpfog.get_clouds
    clouds.each do |cloud|
      puts "#{bwhite(cloud['name'])} - #{cloud['description']} (ID:#{red cloud['id']})"
    end
    
  when "apps"
    
    cloud_id = argv.shift
    
    phpfog = PHPfog.new

    apps = phpfog.get_apps(cloud_id)
    apps.each do |app|
      app_status = app['status']
      case app['status']
      when "Running"
        app_status = green(app_status)
      end
      puts "#{bwhite(app['name'])} - #{app_status} (ID:#{red app['id']})"
    end
    
  else
    puts "Unknown Command: " + (command || '')
    return false
  end
  
  true
end

#logout(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
# File 'lib/commands/logout.rb', line 2

def logout(argv)
  if File.exists? SESSION_PATH 
    File.delete SESSION_PATH
    puts bright 'Successfully logged out.'
  else
    puts bwhite 'Already logged out.'
  end
  true
end

#view(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/commands/view.rb', line 2

def view(argv)
  command = argv.shift

  phpfog = PHPfog.new
  case command
  when "app"
    app_id = argv.shift
    apps = phpfog.get_app(app_id)
    system("open", apps["site_address"])
  else
    puts "Unknown Command: " + command
    return false
  end

  true
end