insert_text¶
Operation inserting text on a given line
Example¶
The following example inserts text into a file named settings.py:
examples/operations/insert_text.yml¶steps:
"Find middleware tag in settings":
name: find_tagged_line
file_path: "examples/data/settings.py"
tag: "# qwikstart: middleware"
"Insert new middleware under tag":
name: insert_text
file_path: "examples/data/settings.py"
text: '"django.contrib.auth.middleware.AuthenticationMiddleware",'
To set up this example, we first use the find_tagged_line operation to find the
line number and column number where the tag "# qwikstart: middleware". These
values are added to the global context and match variables expected by insert_text.
The insert_text operation will then insert text below the tagged line:
MIDDLEWARE = [
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
# qwikstart: middleware
"django.contrib.auth.middleware.AuthenticationMiddleware",
]
Required context¶
file_pathPath to file relative to the current working directory.
textText that will be inserted.
lineLine number where text will be inserted.
columnColumn where the text will be inserted.
Optional context¶
line_endingdefault:
'\n'Text appended to the end of inserted text.
match_indentdefault:
True