|
def | __init__ (self, mode="r", encoding=None, errors="strict", lazy=None, atomic=False) |
|
def | resolve_lazy_flag (self, value) |
|
def | convert (self, value, param, ctx) |
|
def | __call__ (self, value, param=None, ctx=None) |
|
def | get_metavar (self, param) |
|
def | get_missing_message (self, param) |
|
def | split_envvar_value (self, rv) |
|
def | fail (self, message, param=None, ctx=None) |
|
Declares a parameter to be a file for reading or writing. The file
is automatically closed once the context tears down (after the command
finished working).
Files can be opened for reading or writing. The special value ``-``
indicates stdin or stdout depending on the mode.
By default, the file is opened for reading text data, but it can also be
opened in binary mode or for writing. The encoding parameter can be used
to force a specific encoding.
The `lazy` flag controls if the file should be opened immediately or upon
first IO. The default is to be non-lazy for standard input and output
streams as well as files opened for reading, `lazy` otherwise. When opening a
file lazily for reading, it is still opened temporarily for validation, but
will not be held open until first IO. lazy is mainly useful when opening
for writing to avoid creating the file until it is needed.
Starting with Click 2.0, files can also be opened atomically in which
case all writes go into a separate file in the same folder and upon
completion the file will be moved over to the original location. This
is useful if a file regularly read by other users is modified.
See :ref:`file-args` for more information.