103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
# File 'lib/morpheus/cli/cli_registry.rb', line 103
def exec_expression(input)
flow = input
if input.is_a?(String)
begin
flow = Morpheus::Cli::ExpressionParser.parse(input)
rescue Morpheus::Cli::ExpressionParser::InvalidExpression => e
raise e
end
end
final_command_result = nil
if flow.size == 0
else
last_command_result = nil
if ['&&','||', '|'].include?(flow.first)
raise Morpheus::Cli::ExpressionParser::InvalidExpression.new "#{Morpheus::Terminal.angry_prompt}invalid command format, begins with an operator: #{input}"
elsif ['&&','||', '|'].include?(flow.last)
raise Morpheus::Cli::ExpressionParser::InvalidExpression.new "#{Morpheus::Terminal.angry_prompt}invalid command format, ends with an operator: #{input}"
else
previous_command = nil
previous_command_result = nil
current_operator = nil
still_executing = true
flow.each do |flow_cmd|
if still_executing
if flow_cmd == '&&'
current_operator = flow_cmd
exit_code, cmd_err = parse_command_result(previous_command_result)
if exit_code != 0
still_executing = false
end
elsif flow_cmd == '||' current_operator = flow_cmd
exit_code, err = parse_command_result(previous_command_result)
if exit_code == 0
still_executing = false
end
elsif flow_cmd == '|' raise Morpheus::Cli::ExpressionParser::InvalidExpression.new "The PIPE (|) operator is not yet supported =["
previous_command_result = nil
still_executing = false
elsif flow_cmd.is_a?(Array)
current_operator = nil
previous_command_result = exec_expression(flow_cmd)
else current_operator = nil
flow_argv = Shellwords.shellsplit(flow_cmd)
previous_command_result = exec_command(flow_argv[0], flow_argv[1..-1])
end
previous_command = flow_cmd
else
end
end
final_command_result = previous_command_result
end
end
return final_command_result
end
|