Class Rudy::Config::Commands

  1. lib/rudy/config/objects.rb
Parent: Caesars

Modify the SSH command available in routines. The default set of commands is defined by Rye::Cmd (Rudy executes all SSH commands via Rye).

NOTE: We allow people to define their own keywords. It is important that new keywords do not conflict with existing Rudy keywords. Strange things may happen!

Methods

public instance

  1. init
  2. postprocess

Included modules

  1. Gibbler::Complex

Public instance methods

init ()
[show source]
    # File lib/rudy/config/objects.rb, line 77
77:     def init
78:       # We can't process the Rye::Cmd commands here because the
79:       # DSL hasn't been parsed yet so Rudy::Config.postprocess
80:       # called the following postprocess method after parsing.
81:     end
postprocess ()

Process the directives specified in the commands config. NOTE: This affects the processing of the routines config which only works if commands is parsed first. This works naturally if each config has its own file b/c Rudy loads files via a glob (globs are alphabetized and “commands” comes before “routines”).

That’s obviously not good enough but for now commands configuration MUST be put before routines.

[show source]
     # File lib/rudy/config/objects.rb, line 92
 92:     def postprocess
 93:       return false if @@processed
 94:       @@processed = true  # Make sure this runs only once
 95: 
 96:       # Parses:
 97:       # commands do
 98:       #   allow :kill 
 99:       #   allow :custom_script, '/full/path/2/custom_script'
100:       #   allow :git_clone, '/usr/bin/git', 'clone'
101:       # end
102:       # 
103:       # * Tells Routines to force_array on the command name.
104:       # This is important b/c of the way we parse commands 
105:       self.allow.each do |cmd|
106:         cmd, *args = *cmd
107:         
108:         ## Currently disabled
109:         ##raise AlreadyDefined.new(:commands, cmd) if @@allowed.member?(cmd)
110:         ##@@allowed << cmd
111:         
112:         # We can allow existing commands to be overridden but we
113:         # print a message to STDERR so the user knows what's up.
114:         if Rye::Cmd.can?(cmd)
115:           Rudy::Huxtable.ld "Redefining #{cmd}" if Rudy::Huxtable.global.verbose > 2
116:         end
117:         
118:         if args.last.is_a?(Proc)
119:           block = args.pop
120:           Rye::Cmd.add_command(cmd, nil, *args, &block)
121:         else
122:           # If no path was specified, we can assume cmd is in the remote path so
123:           # when we add the method to Rye::Cmd, we'll it the path is "cmd".
124:           path = args.shift || cmd.to_s
125:           
126:           raise PathNotString.new(:commands, cmd) if path && !path.is_a?(String)
127:           
128:           Rye::Cmd.add_command cmd, path, *args
129:           
130:         end
131:         
132:         
133:         ## We cannot allow new commands to be defined that conflict use known
134:         ## routines keywords. This is based on keywords in the current config.
135:         ## NOTE: We can't check for this right now b/c the routines config
136:         ## won't necessarily have been parsed yet. TODO: Figure it out!
137:         ##if Caesars.known_symbol_by_glass?(:routines, cmd)
138:         ##  raise ReservedKeyword.new(:commands, cmd)
139:         ##end
140:         
141:       end
142:   
143:       ## NOTE: We now process command blocks as Procs rather than individual commands.
144:       ## There's currently no need to ForceRefresh here
145:       ##raise Caesars::Config::ForceRefresh.new(:routines)
146:     end