class Droid
Constants
- COMMANDS
- DESC
- FILE
- RUN
- SYNTAX
Public Instance Methods
handle_command(command)
click to toggle source
# File lib/droid.rb, line 33 def handle_command(command) commands = load[COMMANDS] command = commands[command] if !command list_commands abort() end system("#{command[RUN]} #{ARGV[1..ARGV.count].join(' ')}") end
list_commands()
click to toggle source
# File lib/droid.rb, line 21 def list_commands loaded_file = load abort("No commands found in droid.yml") unless loaded_file commands = loaded_file[COMMANDS] puts "Usage: #{"droid".green} #{"<command>".yellow} #{"[args...] [options...]".blue}" commands.each do |command| puts "\n#{"droid".green} #{command[0].green} #{command[1][SYNTAX] ? command[1][SYNTAX] : ""}" puts " #{command[1][DESC]}" end end
load()
click to toggle source
# File lib/droid.rb, line 13 def load YAML.load_file(FILE) end
run()
click to toggle source
# File lib/droid.rb, line 44 def run File.file?('./droid.yml') if !File.file?('./droid.yml') abort('Could not find droid.yml') end # Main runner code command = ARGV[0] if !command list_commands else handle_command(command) end end
save(data)
click to toggle source
# File lib/droid.rb, line 17 def save(data) File.open(FILE, 'w') { |f| YAML.dump(data, f) } end