Module: Capsaicin::Invocation
- Defined in:
- lib/capsaicin/invocation.rb
Instance Method Summary collapse
-
#local_run(*args, &block) ⇒ Object
Capistrano’s system() override is only available from the base deployment strategy.
-
#sudo_as(*args, &block) ⇒ Object
Always uses :runner to sudo as someone.
-
#sudo_su(*args, &block) ⇒ Object
Extremely helpful if you only have permission to: sudo su SOMEUSER -c “command”.
-
#sudo_su_to(*args, &block) ⇒ Object
Extremely helpful if you only have permission to: sudo su - SOMEUSER.
-
#vcapture(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things.
-
#vrun(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things.
-
#vstream(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things.
Instance Method Details
#local_run(*args, &block) ⇒ Object
Capistrano’s system() override is only available from the base deployment strategy. Also, we could do with a few more windows checks.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/capsaicin/invocation.rb', line 31 def local_run(*args, &block) args.pop if Hash===args.last cmd = args.join(' ') if RUBY_PLATFORM =~ /win32|mingw|mswin/ cmd.gsub!('/','\\') # Replace / with \\ cmd.gsub!(/^cd /,'cd /D ') # Replace cd with cd /D cmd.gsub!(/&& cd /,'&& cd /D ') # Replace cd with cd /D logger.trace "executing locally: #{cmd}" Kernel.system cmd else logger.trace "executing locally: #{cmd}" Kernel.system cmd end end |
#sudo_as(*args, &block) ⇒ Object
Always uses :runner to sudo as someone. Equivalent to: sudo “command”, :as => fetch(:runner,nil)
48 49 50 51 52 |
# File 'lib/capsaicin/invocation.rb', line 48 def sudo_as(*args, &block) = Hash===args.last ? args.pop.dup : {} [:as] = fetch(:runner, nil) sudo *args.push(), &block end |
#sudo_su(*args, &block) ⇒ Object
Extremely helpful if you only have permission to: sudo su SOMEUSER -c “command”
55 56 57 58 59 |
# File 'lib/capsaicin/invocation.rb', line 55 def sudo_su(*args, &block) = Hash===args.last ? args.pop.dup : {} args[0] = "su #{fetch(:runner, nil)} -c '#{args[0]}'" sudo *args.push(), &block end |
#sudo_su_to(*args, &block) ⇒ Object
Extremely helpful if you only have permission to: sudo su - SOMEUSER
62 63 64 65 66 67 68 |
# File 'lib/capsaicin/invocation.rb', line 62 def sudo_su_to(*args, &block) = Hash===args.last ? args.pop.dup : {} [:shell] = false cmd = args[0].gsub(/[$\\`"]/) { |m| "\\#{m}" } args[0] = "echo \"#{cmd}\" | #{sudo} su - #{fetch(:runner, nil)}" run *args.push(), &block end |
#vcapture(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things. Equivalent to capture *args, :via=>fetch(:run_method, :run)
15 16 17 18 19 |
# File 'lib/capsaicin/invocation.rb', line 15 def vcapture(*args, &block) = Hash===args.last ? args.pop.dup : {} [:via] = fetch(:run_method, :run) capture *args.push(), &block end |
#vrun(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things. Equivalent to invoke_command *args, :via=>fetch(:run_method, :run)
7 8 9 10 11 |
# File 'lib/capsaicin/invocation.rb', line 7 def vrun(*args, &block) = Hash===args.last ? args.pop.dup : {} [:via] = fetch(:run_method, :run) invoke_command *args.push(), &block end |
#vstream(*args, &block) ⇒ Object
Automatically uses the :run_method variable to run things. Equivalent to stream *args, :via=>fetch(:run_method, :run)
23 24 25 26 27 |
# File 'lib/capsaicin/invocation.rb', line 23 def vstream(*args, &block) = Hash===args.last ? args.pop.dup : {} [:via] = fetch(:run_method, :run) stream *args.push(), &block end |