class documentation

class Path(ParamType):

View In Hierarchy

The path type is similar to the File type but it performs different checks. First of all, instead of returning an open file handle it returns just the filename. Secondly, it can perform various basic checks about what the file or directory should be.

Changed in version 8.0: Allow passing type=pathlib.Path.
Changed in version 6.0: Added the allow_dash parameter.
Parameters
existsif set to true, the file or directory needs to exist for this value to be valid. If this is not required and a file does indeed not exist, then all further checks are silently skipped.
file​_okaycontrols if a file is a possible value.
dir​_okaycontrols if a directory is a possible value.
writableif true, a writable check is performed.
readableif true, a readable check is performed.
resolve​_pathif this is true, then the path is fully resolved before the value is passed onwards. This means that it's absolute and symlinks are resolved. It will not expand a tilde-prefix, as this is supposed to be done by the shell only.
allow​_dashIf this is set to True, a single dash to indicate standard streams is permitted.
path​_typeConvert the incoming path value to this type. If None, keep Python's default, which is str. Useful to convert to pathlib.Path.
Method __init__ Undocumented
Method coerce​_path​_result Undocumented
Method convert Convert the value to the correct type. This is not called if the value is None (the missing value).
Method shell​_complete Return a special completion marker that tells the completion system to use the shell to provide path completions for only directories or any paths.
Method to​_info​_dict Gather information that could be useful for a tool generating user-facing documentation.
Instance Variable allow​_dash Undocumented
Instance Variable dir​_okay Undocumented
Instance Variable exists Undocumented
Instance Variable file​_okay Undocumented
Instance Variable name Undocumented
Instance Variable readable Undocumented
Instance Variable resolve​_path Undocumented
Instance Variable type Undocumented
Instance Variable writable Undocumented

Inherited from ParamType:

Method __call__ Undocumented
Method fail Helper method to fail with an invalid value message.
Method get​_metavar Returns the metavar default for this param if it provides one.
Method get​_missing​_message Optionally might return extra information about a missing parameter.
Method split​_envvar​_value Given a value from an environment variable this splits it up into small chunks depending on the defined envvar list splitter.
Class Variable arity Undocumented
Class Variable envvar​_list​_splitter Undocumented
Class Variable is​_composite Undocumented
def __init__(self, exists=False, file_okay=True, dir_okay=True, writable=False, readable=True, resolve_path=False, allow_dash=False, path_type=None):

Undocumented

Parameters
exists:boolUndocumented
file​_okay:boolUndocumented
dir​_okay:boolUndocumented
writable:boolUndocumented
readable:boolUndocumented
resolve​_path:boolUndocumented
allow​_dash:boolUndocumented
path​_type:t.Optional[t.Type]Undocumented
def coerce_path_result(self, rv):

Undocumented

Parameters
rv:t.AnyUndocumented
Returns
t.AnyUndocumented
def convert(self, value, param, ctx):

Convert the value to the correct type. This is not called if the value is None (the missing value).

This must accept string values from the command line, as well as values that are already the correct type. It may also convert other compatible types.

The param and ctx arguments may be None in certain situations, such as when converting prompt input.

If the value cannot be converted, call fail with a descriptive message.

Parameters
value:t.AnyThe value to convert.
param:t.Optional[Parameter]The parameter that is using this type to convert its value. May be None.
ctx:t.Optional[Context]The current context that arrived at this value. May be None.
Returns
t.AnyUndocumented
def shell_complete(self, ctx, param, incomplete):

Return a special completion marker that tells the completion system to use the shell to provide path completions for only directories or any paths.

New in version 8.0.
Parameters
ctx:ContextInvocation context for this command.
param:ParameterThe parameter that is requesting completion.
incomplete:strValue being completed. May be empty.
Returns
t.List[CompletionItem]Undocumented
def to_info_dict(self):

Gather information that could be useful for a tool generating user-facing documentation.

Use click.Context.to_info_dict to traverse the entire CLI structure.

New in version 8.0.
Returns
t.Dict[str, t.Any]Undocumented
allow_dash =

Undocumented

dir_okay =

Undocumented

exists =

Undocumented

file_okay =

Undocumented

name =

Undocumented

readable =

Undocumented

resolve_path =

Undocumented

type =

Undocumented

writable =

Undocumented