Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions sphinxcontrib/runcmd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,25 @@ def run(self):
# Grab a cache singleton instance
cache = CMDCache()

# Handle "$ foo" to run "foo", but display it as prompt (enabled
# "prompt" flag).
if self.arguments[0] in ("$", "%"):
command = " ".join(self.arguments[1:])
prompt = " ".join(self.arguments)
else:
command = " ".join(self.arguments)
if "prompt" in self.options:
prompt = command
else:
prompt = False

# Get the command output
command = " ".join(self.arguments)
output = cache.get(command)

# Grab our custom commands
syntax = self.options.get("syntax", "text")
replace = self.options.get("replace", "")
reader = csv.reader([replace], delimiter=",", escapechar="\\")
prompt = "prompt" in self.options
dedent_output = self.options.get("dedent-output", 0)

# Dedent the output if required
Expand All @@ -93,7 +103,7 @@ def run(self):

# Add the prompt to our output if required
if prompt:
output = "{}\n{}".format(command, output)
output = "{}\n{}".format(prompt, output)

# Do our "replace" syntax on the command output
for items in reader:
Expand Down