Class: Caliph::CommandLine
- Inherits:
-
Object
- Object
- Caliph::CommandLine
- Includes:
- DefineOp
- Defined in:
- lib/caliph/command-line.rb,
lib/caliph/testing/record-commands.rb
Direct Known Subclasses
Constant Summary collapse
- @@commands =
[]
Class Attribute Summary collapse
-
.command_recording_path ⇒ Object
Returns the value of attribute command_recording_path.
-
.output_stream ⇒ Object
Returns the value of attribute output_stream.
Instance Attribute Summary collapse
-
#definition_watcher ⇒ Object
Returns the value of attribute definition_watcher.
-
#env ⇒ Object
(also: #command_environment)
Returns the value of attribute env.
-
#executable ⇒ Object
Returns the value of attribute executable.
-
#name ⇒ Object
Returns the value of attribute name.
-
#options ⇒ Object
Returns the value of attribute options.
-
#output_stream ⇒ Object
Returns the value of attribute output_stream.
-
#redirections ⇒ Object
readonly
Returns the value of attribute redirections.
-
#verbose ⇒ Object
Returns the value of attribute verbose.
Class Method Summary collapse
Instance Method Summary collapse
-
#command ⇒ Object
The command as a string, including arguments and options.
- #copy_stream_to(from, to) ⇒ Object
-
#execute ⇒ Object
deprecated
Deprecated.
(see: Shell)
- #from(executable = nil, *options) ⇒ Object
-
#initialize(*args) {|_self| ... } ⇒ CommandLine
constructor
A new instance of CommandLine.
- #must_succeed! ⇒ Object deprecated Deprecated.
- #options_composition ⇒ Object
-
#original_execute ⇒ Object
deprecated
Deprecated.
(see: Shell)
- #redirect_both(path) ⇒ Object
- #redirect_from(path, stream) ⇒ Object
- #redirect_stderr(path) ⇒ Object
- #redirect_stdin(path) ⇒ Object
- #redirect_stdout(path) ⇒ Object
- #redirect_to(stream, path) ⇒ Object
-
#run ⇒ Object
deprecated
Deprecated.
(see: Shell)
-
#run_as_replacement ⇒ Object
(also: #replace_us)
deprecated
Deprecated.
(see: Shell)
-
#run_detached ⇒ Object
(also: #spin_off)
deprecated
Deprecated.
(see: Shell)
-
#run_in_background ⇒ Object
(also: #background)
deprecated
Deprecated.
(see: Shell)
- #set_env(name, value) ⇒ Object
-
#string_format ⇒ Object
The command as a string, including arguments and options, plus prefixed environment variables.
- #succeeds? ⇒ Boolean deprecated Deprecated.
- #valid? ⇒ Boolean
Methods included from DefineOp
Constructor Details
#initialize(*args) {|_self| ... } ⇒ CommandLine
Returns a new instance of CommandLine.
12 13 14 15 16 17 18 19 |
# File 'lib/caliph/command-line.rb', line 12 def initialize(*args) @output_stream = self.class.output_stream || $stderr from(*args) @redirections = [] @env = {} @verbose = false yield self if block_given? end |
Class Attribute Details
.command_recording_path ⇒ Object
Returns the value of attribute command_recording_path.
15 16 17 |
# File 'lib/caliph/testing/record-commands.rb', line 15 def command_recording_path @command_recording_path end |
.output_stream ⇒ Object
Returns the value of attribute output_stream.
9 10 11 |
# File 'lib/caliph/command-line.rb', line 9 def output_stream @output_stream end |
Instance Attribute Details
#definition_watcher ⇒ Object
Returns the value of attribute definition_watcher.
22 23 24 |
# File 'lib/caliph/command-line.rb', line 22 def definition_watcher @definition_watcher end |
#env ⇒ Object Also known as: command_environment
Returns the value of attribute env.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def env @env end |
#executable ⇒ Object
Returns the value of attribute executable.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def executable @executable end |
#name ⇒ Object
Returns the value of attribute name.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def name @name end |
#options ⇒ Object
Returns the value of attribute options.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def @options end |
#output_stream ⇒ Object
Returns the value of attribute output_stream.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def output_stream @output_stream end |
#redirections ⇒ Object (readonly)
Returns the value of attribute redirections.
23 24 25 |
# File 'lib/caliph/command-line.rb', line 23 def redirections @redirections end |
#verbose ⇒ Object
Returns the value of attribute verbose.
21 22 23 |
# File 'lib/caliph/command-line.rb', line 21 def verbose @verbose end |
Class Method Details
.emit_recording ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/caliph/testing/record-commands.rb', line 21 def emit_recording io = $stderr if command_recording_path io = File.open(command_recording_path, "w") else io.puts "Set CALIPH_CMDREC to write to a path" end @@commands.each do |pair| io.puts "[/#{pair[0]}/, #{[pair[1].exit_code, pair[1].streams].inspect}]" end end |
Instance Method Details
#command ⇒ Object
The command as a string, including arguments and options
46 47 48 |
# File 'lib/caliph/command-line.rb', line 46 def command ([executable] + + @redirections).join(" ") end |
#copy_stream_to(from, to) ⇒ Object
71 72 73 |
# File 'lib/caliph/command-line.rb', line 71 def copy_stream_to(from, to) @redirections << "#{from}>&#{to}" end |
#execute ⇒ Object
(see: Shell)
110 111 112 |
# File 'lib/caliph/command-line.rb', line 110 def execute Caliph.new.execute(self) end |
#from(executable = nil, *options) ⇒ Object
27 28 29 30 |
# File 'lib/caliph/command-line.rb', line 27 def from(executable = nil, *) @executable = executable.to_s unless executable.nil? @options = end |
#must_succeed! ⇒ Object
126 127 128 |
# File 'lib/caliph/command-line.rb', line 126 def must_succeed! run.must_succeed! end |
#options_composition ⇒ Object
58 59 60 |
# File 'lib/caliph/command-line.rb', line 58 def end |
#original_execute ⇒ Object
(see: Shell)
6 7 8 |
# File 'lib/caliph/testing/record-commands.rb', line 6 def execute Caliph.new.execute(self) end |
#redirect_both(path) ⇒ Object
87 88 89 |
# File 'lib/caliph/command-line.rb', line 87 def redirect_both(path) redirect_stdout(path).redirect_stderr(path) end |
#redirect_from(path, stream) ⇒ Object
67 68 69 |
# File 'lib/caliph/command-line.rb', line 67 def redirect_from(path, stream) @redirections << "#{stream}<#{path}" end |
#redirect_stderr(path) ⇒ Object
79 80 81 |
# File 'lib/caliph/command-line.rb', line 79 def redirect_stderr(path) redirect_to(2, path) end |
#redirect_stdin(path) ⇒ Object
83 84 85 |
# File 'lib/caliph/command-line.rb', line 83 def redirect_stdin(path) redirect_from(path, 0) end |
#redirect_stdout(path) ⇒ Object
75 76 77 |
# File 'lib/caliph/command-line.rb', line 75 def redirect_stdout(path) redirect_to(1, path) end |
#redirect_to(stream, path) ⇒ Object
62 63 64 65 |
# File 'lib/caliph/command-line.rb', line 62 def redirect_to(stream, path) @redirections << "#{stream}>#{path}" self end |
#run ⇒ Object
(see: Shell)
:nocov:
93 94 95 |
# File 'lib/caliph/command-line.rb', line 93 def run Caliph.new.run(self) end |
#run_as_replacement ⇒ Object Also known as: replace_us
(see: Shell)
98 99 100 |
# File 'lib/caliph/command-line.rb', line 98 def run_as_replacement Caliph.new.run_as_replacement(self) end |
#run_detached ⇒ Object Also known as: spin_off
(see: Shell)
104 105 106 |
# File 'lib/caliph/command-line.rb', line 104 def run_detached Caliph.new.run_detached(self) end |
#run_in_background ⇒ Object Also known as: background
(see: Shell)
115 116 117 |
# File 'lib/caliph/command-line.rb', line 115 def run_in_background Caliph.new.run_in_background(self) end |
#set_env(name, value) ⇒ Object
36 37 38 39 |
# File 'lib/caliph/command-line.rb', line 36 def set_env(name, value) command_environment[name] = value return self end |
#string_format ⇒ Object
The command as a string, including arguments and options, plus prefixed environment variables.
52 53 54 55 56 |
# File 'lib/caliph/command-line.rb', line 52 def string_format (command_environment.map do |key, value| [key, value].join("=") end + [command]).join(" ") end |
#succeeds? ⇒ Boolean
121 122 123 |
# File 'lib/caliph/command-line.rb', line 121 def succeeds? run.succeeded? end |
#valid? ⇒ Boolean
32 33 34 |
# File 'lib/caliph/command-line.rb', line 32 def valid? !@executable.nil? end |