Class: Webcli::CommandsController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/webcli/commands_controller.rb

Instance Method Summary collapse

Instance Method Details

#runObject

unloadable



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
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/webcli/commands_controller.rb', line 6

def run

  puts File.join(RAILS_ROOT,'app','webcli-commands')
  glob = File.join(RAILS_ROOT,'app','webcli-commands','*') # Rcli.script_root + DS + 'lib' + DS + 'commands' + DS + '*'

  allowed_commands = []
  Dir[glob].each{ |c| allowed_commands << File.basename(c,'.rb')}

  puts allowed_commands.inspect

  # user_input = params[:input]
  # prev_command = params[:prev_cmd]
  # input = nil
  
  # if prev_command == ''
    # command = user_input
  # else
    # command = prev_command
    # input = user_input
  # end
  
  # unless allowed_commands.include?(command)
      # json_reply = generate_reply('ERROR',"The command '#{command}' is invalid")
  # else

    # json_reply = nil

    # puts "Received user command : '" + command + "'"
    
    # if command == 'admin'
      # json_reply = admin(input)
    # else
      # json_reply = {
        # :status => "ERROR",
        # :data => {
          # :text => "'" + command + "' is an unrecognized Command",
          # :url => nil
        # }
      # }
    # end
  # end
  
#      respond_to do |format|
#        format.html # index.html.erb
#        format.json { render :json => json_reply.to_json }
#      end

  if allowed_commands.include?(params[:command])
    require File.join(RAILS_ROOT,'app','webcli-commands',params[:command])
    reply = Object.const_get( "#{params[:command].titleize}Command" ).send "reply"
  else
    reply = generate_reply("ERROR","TEXT",:text => "The command #{params[:command]} is invalid")
  end      

  render :json => validate_reply(reply).to_json
end