Class: Rundoc::CodeCommand::Bash::Cd

Inherits:
Rundoc::CodeCommand::Bash show all
Defined in:
lib/rundoc/code_command/bash/cd.rb

Overview

special purpose class to persist cd behavior across the entire program we change the directory of the parent program (rundoc) rather than changing the directory of a spawned child (via exec, “, system, etc.)

Constant Summary

Constants inherited from Rundoc::CodeCommand

NEWLINE

Instance Attribute Summary

Attributes inherited from Rundoc::CodeCommand

#command, #contents, #keyword, #original_args, #render_command, #render_result

Instance Method Summary collapse

Methods inherited from Rundoc::CodeCommand::Bash

#sanitize_escape_chars, #shell, #to_md

Methods inherited from Rundoc::CodeCommand

#hidden?, #not_hidden?, #push, #to_md

Constructor Details

#initialize(line) ⇒ Cd

Returns a new instance of Cd.



6
7
8
# File 'lib/rundoc/code_command/bash/cd.rb', line 6

def initialize(line)
  @line = line
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/rundoc/code_command/bash/cd.rb', line 24

def call(env)
  line = @line.sub("cd", "").strip
  puts "running $ cd #{line}"

  supress_chdir_warning do
    Dir.chdir(line)
  end

  nil
end

#supress_chdir_warningObject

Ignore duplicate chdir warnings “warning: conflicting chdir during another chdir block”



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/rundoc/code_command/bash/cd.rb', line 11

def supress_chdir_warning
  old_stderr = $stderr
  capture_stderr = StringIO.new
  $stderr = capture_stderr
  yield
ensure
  if old_stderr
    $stderr = old_stderr
    capture_string = capture_stderr.string
    warn capture_string if capture_string.each_line.count > 1 || !capture_string.include?("conflicting chdir")
  end
end