Class: Hadupils::Commands::WithTmpDir
- Inherits:
-
SimpleCommand
- Object
- SimpleCommand
- Hadupils::Commands::WithTmpDir
- Defined in:
- lib/hadupils/commands.rb
Instance Attribute Summary
Attributes inherited from SimpleCommand
Instance Method Summary collapse
Methods inherited from SimpleCommand
#initialize, run, #successful?
Constructor Details
This class inherits a constructor from Hadupils::Commands::SimpleCommand
Instance Method Details
#run ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 |
# File 'lib/hadupils/commands.rb', line 161 def run # Runs provided subcommand with tmpdir and cleans up tmpdir on an exitstatus of zero if params.empty? $stderr.puts 'Yeeaaahhh... sooo... you failed to provide a subcommand...' [nil, 255] else # Let's create the tmpdir stdout, exitstatus = Hadupils::Commands::MkTmpFile.run ['-d'] if successful? exitstatus tmpdir_path = Hadupils::Extensions::Dfs::TmpFile.tmpfile_path params.unshift({'HADUPILS_TMPDIR_PATH' => tmpdir_path}) # Let's run the shell subcommand! stdout, exitstatus = Hadupils::Runners::Subcommand.run params if successful? exitstatus # Let's attempt to cleanup tmpdir_path stdout, exitstatus = Hadupils::Commands::RmFile.run ['-r', tmpdir_path] else $stderr.puts "Failed to run shell subcommand: #{params}" end end Hadupils::Extensions::Dfs::TmpFile.reset_tmpfile! [nil, exitstatus] end end |