Class: Antfarm::CPScript
- Inherits:
-
SCParse::Command
- Object
- SCParse::Command
- Antfarm::CPScript
- Defined in:
- lib/cpscript.rb
Overview
Extends SCParse::Command so it can be considered as a command.
Instance Attribute Summary
Attributes inherited from SCParse::Command
#commands, #name, #options, #parent
Instance Method Summary collapse
- #execute(args) ⇒ Object
-
#initialize ⇒ CPScript
constructor
A new instance of CPScript.
- #show_help ⇒ Object
Methods inherited from SCParse::Command
#add_command, #execute_prerequisites?, #has_command?, #has_commands?, #parents, #prerequisites, #scparser, #set_execution_block, #set_prerequisites_block, #usage
Constructor Details
#initialize ⇒ CPScript
Returns a new instance of CPScript.
27 28 29 30 |
# File 'lib/cpscript.rb', line 27 def initialize # set the command name to 'cp' super('cp-script') end |
Instance Method Details
#execute(args) ⇒ Object
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 |
# File 'lib/cpscript.rb', line 32 def execute(args) super(args) if defined?(USER_DIR) script = args.pop + '.rb' parents = args.join('/') location = File.("#{ANTFARM_ROOT}/lib/scripts/#{parents}/#{script}") if File.exists?(location) FileUtils.makedirs("#{USER_DIR}/scripts/#{parents}") FileUtils.cp(location, "#{USER_DIR}/scripts/#{parents}/") if parents.empty? puts "The script #{script} has been copied to #{USER_DIR}/scripts/" else puts "The script #{script} has been copied to #{USER_DIR}/scripts/#{parents}/" end else if parents.empty? puts "The script #{script} doesn't seem to exist. Please try again." else puts "The script #{parents}/#{script} doesn't seem to exist. Please try again." end end else puts "No custom user directory exists. Please run 'antfarm db --initialize' first." end end |
#show_help ⇒ Object
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/cpscript.rb', line 59 def show_help super puts "This command is used to copy scripts available in the core ANTFARM package to" puts "your user directory. This is useful for utilizing existing core ANTFARM scripts" puts "as a basis for creating your own custom scripts." puts puts "As arguments to this command, specify the script you want to copy to your user" puts "directory. For example: antfarm cp-script cisco parse-arp" end |