module Exercitus_romanorum
Constants
- GETTINGSTARTED
- HELPTEXT
- THANKYOUALL
Public Instance Methods
access?()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 82 def access? if get_admin_status == 1 if is_admin? == 0 return false end end end
admin_check()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 201 def admin_check if is_admin == 0 return "You must be an admin to use this command" else end end
arg_has_special?(arg)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 173 def arg_has_special?(arg) arg.match(/\W+/) { return true } end
cmd_argument?(recievecmd, matchcmd, flag1, flag2)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 138 def cmd_argument?(recievecmd, matchcmd, flag1, flag2) if recievecmd =~ /^#{matchcmd}\s*(#{flag1}|#{flag2})\s.*\s*$/ return true else nil end end
cmd_flag1?(recievecmd, matchcmd, flag1)
click to toggle source
below method isn’t being used
# File lib/Exercitus_romanorum.rb, line 128 def cmd_flag1?(recievecmd, matchcmd, flag1) if recievecmd =~ /^#{matchcmd}\s*#{flag1}\s*/ return true else nil end end
cmd_get_arg1(recievecmd)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 156 def cmd_get_arg1(recievecmd) arg1 = /^\S*\s*(\S*)\s*\S*\s*$/.match(recievecmd).captures return arg1 end
cmd_get_arg2(recievecmd)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 161 def cmd_get_arg2(recievecmd) arg2 = /^\S*\s*\S*\s*(\S*)\s*$/.match(recievecmd).captures #put in a check here if argument is equal to one of the commands or already existing slatenames return arg2 end
cmd_get_argument(recievecmd, matchcmd)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 167 def cmd_get_argument(recievecmd, matchcmd) argument = /^#{matchcmd}\s.+\s(.+)\s*$/.match(recievecmd).captures #put in a check here if argument is equal to one of the commands or already existing slatenames and if so return error can't be cmd or slatename return argument end
cmd_no_ops?(recievecmd, matchcmd)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 111 def cmd_no_ops?(recievecmd, matchcmd) if recievecmd =~ /^#{matchcmd}\s*$/ return true else return false end end
cmd_onlytwo_arguments?(recievecmd, matchcmd)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 148 def cmd_onlytwo_arguments?(recievecmd, matchcmd) if recievecmd =~ /^#{matchcmd}\s*\S+\s*\S+\s*$/ return true else nil end end
cmd_option2?(recievecmd, matchcmd, flag1, flag2)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 119 def cmd_option2?(recievecmd, matchcmd, flag1, flag2) if recievecmd =~ /^#{matchcmd}\s*(#{flag1}|#{flag2})\s*$/ return true else return false end end
get_command(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 208 def get_command(command) #send the command to a file which will be used by the history command and up and down arrows scrolling through old commands that were run !!here use_cmd if command =~ /^about/ parse_about(command) elsif command =~ /^new/ parse_new(command) elsif command =~ /^delete/ parse_delete(command) elsif command =~ /^d\s*$/ parse_delete(command) elsif command =~ /^ls/ parse_ls(command) elsif command =~ /^list/ parse_list(command) elsif command =~ /^ThankYou$/ parse_thankyou(command) elsif command =~ /^rename/ parse_rename(command) elsif command =~ /^exit/ parse_exit(command) elsif command =~ /^e\s*$/ parse_exit(command) elsif command =~ /^help/ parse_help(command) elsif command =~ /^h\s*$/ parse_help(command) elsif command =~ /^demote/ parse_demote(command) elsif command =~ /^history/ parse_history(command) elsif command =~ /^version/ parse_version(command) elsif command =~ /^lastlog/ parse_lastlog(command) elsif command =~ /^next\s*\S+\s*$/ || command =~ /^n\s*\S+\s*$/ next_help elsif command =~ /^previous\s*\S+\s*$/ || command =~ /^p\s*\S+\s*$/ previous_help elsif command =~ /^viewslate\s*\S+\s*$/ || command =~ /^v\s*\S+\s*$/ viewslate_help elsif command =~ /^super\s*\S+\s*$/ super_help else nocommand(command) #return "\n#{command}\n\n\n This is not one of the commands or slates. Type help if you would like a list of commands. To learn more about this program type about." end end
is_arg_cmd?(arg)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 71 def is_arg_cmd?(arg) off_limit_args = [ "--slates", "--hosts", "new", "version", "delete", "rename", "lastlog", "history", "next", "previous", "exit", "demote", "super", "help", "about", "viewslate", "list", "ThankYou" ] off_limit_args.each do |cmd| if arg =~ /^#{cmd}\s*$/ return true else #return nil end end end
is_arg_slate?(arg)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 177 def is_arg_slate?(arg) slates = [] slates = list_slates slates.each do |slate| if arg =~ /^#{slate}$/ return true else #return nothing next end end end
is_slate?(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 91 def is_slate?(command) slates = [] slates = list_slates slates.each do |slate| if command =~ /^#{slate}\s*$/ return true else #return nil next end end end
slatecount()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 104 def slatecount slates = [] slates = list_slates number = slates.length return number end
use_cmd()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 193 def use_cmd if using_cmd? == 0 set_cmd_view("1") else nil end end
Private Instance Methods
next_help()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 276 def next_help return "\nnext\n\n\nThis command brings you to the next slate in your list of slates. It does not take any arguments. \n\nUsage: next\n\n\n\nAlias: n" end
nocommand(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 268 def nocommand(command) return "\n#{command}\n\n\n This is not a valid command or slate. Type help if you would like a list of commands. To learn more about this program type about." end
parse_about(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 299 def parse_about(command) match = "about" if cmd_no_ops?(command, match) == true return "\n#{GETTINGSTARTED}" else return "\nabout\n\n\nThis command gives you information about Slates. It gives you an overview of the functions and features this program offers. If you are new to Slates, I suggest you start here. \n\nUsage: about" end end
parse_delete(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 339 def parse_delete(command) flag1 = "-s" flag2 = "--slate" match = "delete" match2 = "d" if access? == false return "\nYou must be an administrator to run this command." else if cmd_no_ops?(command, match) == true || cmd_no_ops?(command, match2) == true @numofslates = slatecount if @numofslates <= 3 return "\nYou cannot delete this slate, because there must be at least 3 slates at all times." else viewingslate = get_slatename previous = previousslate set_viewing("#{previous}") remove_slate("#{viewingslate}") return "\nThe slate #{viewingslate} was deleted." end elsif cmd_argument?(command, match, flag1, flag2) == true @argument = cmd_get_argument(command, match).join("") if arg_has_special?("#{@argument}") == true return "\nThere is no slate with the name #{@argument}" elsif is_arg_slate?("#{@argument}") == true @numofslates = slatecount if @numofslates <= 3 return "\nYou cannot delete this slate, because there must be at least 3 slates at all times." end if viewing?("#{@argument}") == 1 previous = previousslate set_viewing("#{previous}") end remove_slate("#{@argument}") return "\nThe slate #{@argument} was deleted." else return "\nThere is no slate with the name #{@argument}" end else return "\ndelete\n\n\nThis command allows you to delete a slate. \n\nUsage: delete -s <slatename> or delete --slate <slatename> \n -s stands for slate. You can only use one flag each time this command is run. Delete can only take one argument which is the name of the slate you would like to delete. If you want to delete the slate you are viewing, just type delete or d without any arguments." end end end
parse_demote(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 481 def parse_demote(command) match = "demote" if cmd_no_ops?(command, match) == true set_admin("0") return "\nYou are no longer an administrator" else return "\ndemote\n\n\nThis command takes away administrator abilities. \n\nUsage: demote" end end
parse_exit(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 457 def parse_exit(command) match = "exit" if cmd_no_ops?(command, match) == true return exit elsif cmd_no_ops?(command, "e") == true return exit else usage = "\nexit\n\n\nThis command exits the program. A shortcut for this is e.\n\nUsage: exit" return usage end end
parse_help(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 469 def parse_help(command) match = "help" if cmd_no_ops?(command, match) == true return "\n#{HELPTEXT}" elsif cmd_no_ops?(command, "h") == true return "\n#{HELPTEXT}" else usage = "\nType in help if you need assistance." return usage end end
parse_history(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 491 def parse_history(command) match = "history" if cmd_no_ops?(command, match) == true numolines = File.read("../log/history.log").scan(/\n/).count if numolines == 0 return "" elsif numolines >= 50 read = IO.readlines("../log/history.log")[-50..-1] return read.join("") else numolines *= -1 read = IO.readlines("../log/history.log")[numolines..-1] return read.join("") end =begin file.readlines.each do |line| count = 0 if count <= 39 lines << line #linetxt = "#{@period}" + "#{line}\n" #@period = "#{linetxt}" count += 1 else linetxt = lines.join("\n\n\n\n") return "#{linetxt}" end =end else return "\nhistory\n\n\nThis command gives you a listing of the last 50 commands that were run. It does not take any arguments. \n\nUsage: history" end end
parse_lastlog(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 525 def parse_lastlog(command) match = "lastlog" if cmd_no_ops?(command, match) == true numolines = File.read("../log/slate.log").scan(/\n/).count if numolines == 0 return "" elsif numolines >= 100 read = IO.readlines("../log/slate.log")[-100..-1] return read.join("") else numolines *= -1 read = IO.readlines("../log/slate.log")[numolines..-1] return read.join("") end =begin lines = [] File.open("../log/slate.log", "r") { |file| @period = ".START\n\n\n\n" file.readlines.each do |line| count = 0 if count <= 39 lines << line #linetxt = "#{@period}" + "#{line}\n" #@period = "#{linetxt}" count += 1 else linetxt = lines.join("\n\n\n\n") return "#{linetxt}" end end } =end else return "\nlastlog\n\n\nThis command shows you the last few lines of this programs logfile. It does not take any arguments. \n\nUsage: lastlog" end end
parse_list(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 397 def parse_list(command) match = "list" flag1 = "-s" flag2 = "--slates" @numofslates = slatecount if cmd_no_ops?(command, match) == true sap = list_slates.join("\n") hap = list_hosts.join("\n") slates = "\n You have #{@numofslates} slates.\n\n\nYour slates include: \n\n #{sap}" return slates elsif cmd_option2?(command, match, flag1, flag2) == true sap = list_slates.join("\n") slates = "\n You have #{@numofslates} slates.\n\n\nYour slates include: \n\n #{sap}" return slates else return "\nlist\n\n\nThis command lists the slates you have. \n\nUsage: list [options]\n\t -s, --slates list only slates\n\t \n\n\n The alias for list is: ls" end end
parse_ls(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 384 def parse_ls(command) match = "ls" if cmd_no_ops?(command, match) == true sap = list_slates.join("\n") @numofslates = slatecount far = "\n You have #{@numofslates} slates.\n\n\nYour slates include:\n\n #{sap}" return far else usage = "\nls\n\n\nThis command lists the slates. It is a shortcut for list. It doesn't not take any arguments or flags.\n\nUsage: ls" return usage end end
parse_new(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 308 def parse_new(command) flag1 = "-s" flag2 = "--slate" match = "new" if access? == false return "\nYou must be an administrator to run this command." else if cmd_no_ops?(command, match) == true return "\nThe new command requires an option and an argument." elsif cmd_argument?(command, match, flag1, flag2) == true @argument = cmd_get_argument(command, match).join("") if arg_has_special?("#{@argument}") == true return "\nThe slatename can't contain special characters" elsif is_arg_slate?("#{@argument}") == true return "\nThe slate #{@argument} already exists." elsif @argument =~ /^(..|.)$/ return "\nSlatename must be more than 2 characters long." elsif is_arg_cmd?(@argument) == true return "\nYour slate cannot be the name of a command." else new_slate("#{@argument}") return "\nThe slate #{@argument} has been created." end else return "\nnew\n\n\nThis command allows you to create a new slate. \n\nUsage: new -s <slatename> or new --slate <slatename> \n -s stands for slate. You can only use one flag each time this command is run.\nThis command takes only one argument after the flag which is the name of the slate you want to create." end end end
parse_rename(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 422 def parse_rename(command) match = "rename" if access? == false return "\nYou must be an administrator to run this command." else if cmd_no_ops?(command, match) == true return "\nThe rename command requires two arguments. The first argument must be an existing slatename and the other argument must be the name you want to change it to." elsif cmd_onlytwo_arguments?(command, match) == true oldname = cmd_get_arg1(command).join("") newname = cmd_get_arg2(command).join("") if newname =~ /^(..|.)$/ return "\nThe slatename must be more than 2 characters long." elsif newname =~ /\W/ return "\nYou can only use letters, numbers and underscores in the name of a slate." elsif oldname =~ /^help$/ return "\nrename\n\n\nThis command renames an already existing slate to some other name. \n\nUsage: rename <oldslatename> <newslatename>\n This command must take in the name of an already existing slate and the name you want to change it to." elsif oldname =~ /\W/ return "\nYou do not have a slate named: #{oldname}." elsif is_arg_cmd?(newname) == true return "\nYour slate cannot be the name of a command." elsif is_arg_slate?(newname) == true return "\nYou already have a slate called #{newname}." elsif is_arg_slate?(oldname) == true slateid = get_slateid("#{oldname}") set_slatename("#{slateid}", "#{newname}") return "\nThe slate #{oldname} has changed its name to #{newname}." else return "\nThe first argument #{oldname} is not the name of a slate." end else return "\nrename\n\n\nThis command renames an already existing slate to some other name. \n\nUsage: rename <oldslatename> <newslatename>\n This command must take in the name of an already existing slate and the name you want to change it to." end end end
parse_thankyou(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 418 def parse_thankyou(command) return "\n\n\n\n\n#{THANKYOUALL}" end
parse_version(command)
click to toggle source
# File lib/Exercitus_romanorum.rb, line 288 def parse_version(command) match = "version" if cmd_no_ops?(command, match) == true ver = "\nYou are running Version 0.1.0 - Gumshoe" return ver else usage = "\nversion\n\n\nThis command displays the version of this program that is running. It does not take any arguments. \n\nUsage: version" return usage end end
previous_help()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 280 def previous_help return "\nprevious\n\n\nThis command brings you to the previous slate in your list of slates. It does not take any arguments. \n\nUsage: previous \n\n\n\nAlias: p" end
super_help()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 272 def super_help return "\nsuper\n\n\nThis command asks for the administrator password so that you could become an admin. If you are an admin, you will be able to access all the commands and sectons. This command does not take any arguments.\n\nUsage: super" end
viewslate_help()
click to toggle source
# File lib/Exercitus_romanorum.rb, line 284 def viewslate_help return "\nviewslate\n\n\nThis command removes the command output and lets you view the slatetext. It does not take any arguments. \n\nUsage: viewslate\n\n\n\nAlias: v" end