Method: Rundoc::CLI#call

Defined in:
lib/rundoc/cli.rb

#callObject



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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/rundoc/cli.rb', line 134

def call
  io.puts "## Running your docs"
  load_dotenv
  check_directories_empty!

  source_contents = execution_context.source_path.read
  if on_failure_dir.exist? && !Dir.empty?(on_failure_dir)
    io.puts "## erring on failure directory #{on_failure_dir}"
    clean_dir(
      dir: on_failure_dir,
      description: "on failure directory"
    )
  end

  if execution_context.with_contents_dir
    io.puts "## Copying contents from #{execution_context.with_contents_dir} to tmp working dir"
    Dir.chdir(execution_context.with_contents_dir) do
      FileUtils.cp_r(
        ".",
        execution_context.output_dir
      )
    end
  end

  io.puts "## Working dir is #{execution_context.output_dir}"
  Dir.chdir(execution_context.output_dir) do
    parser = Rundoc::Document.new(
      source_contents,
      context: execution_context
    )
    output = begin
      parser.to_md
    rescue StandardError, SignalException => e
      io.puts "Received exception: #{e.inspect}, cleaning up before re-raise"
      on_fail
      raise e
    end

    on_success(output)
  end
ensure
  # Stop any hanging background tasks
  Rundoc::CodeCommand::Background::ProcessSpawn.tasks.each do |name, task|
    next unless task.alive?

    io.puts "Warning background task is still running, cleaning up: name: #{name}"
    task.stop
  end

  if execution_context.output_dir.exist?
    clean_dir(
      dir: execution_context.output_dir,
      description: "tmp working directory"
    )
  end
end