Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport release_3.40] Add py-args and -- as command line parameters #9575

Merged
merged 2 commits into from
Jan 19, 2025
Merged
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
40 changes: 38 additions & 2 deletions docs/user_manual/introduction/qgis_configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2392,6 +2392,7 @@ returns::
[-g, --globalsettingsfile path] use the given ini file as Global Settings (defaults)
[-a, --authdbdirectory path] use the given directory for authentication database
[-f, --code path] run the given python file on load
[-F, --py-args arguments] arguments for python. These arguments will be available for each python execution via 'sys.argv' including the file specified by '--code'. All arguments till '--' are passed to python and ignored by QGIS.
[-d, --defaultui] start by resetting user ui settings to default
[--hide-browser] hide the browser widget
[--dxf-export filename.dxf] emit dxf output of loaded datasets to given file
Expand Down Expand Up @@ -2565,6 +2566,8 @@ several machines by only editing one file.
This option is similar to ``--globalsettingsfile``, but defines the path to the
directory where the authentication database will be stored and loaded.

.. _code_commandline:

``--code``
..........

Expand All @@ -2583,9 +2586,28 @@ following content:

Assuming you are in the directory where the file :file:`load_alaska.py` is
located, you can start QGIS, load the raster file :file:`landcover.img` and give
the layer the name 'Alaska' using the following command::
the layer the name 'Alaska' using the following command:

.. code-block:: bash

qgis --code load_alaska.py

``--py-args``
.............

This option allows to pass arguments to the script provided via the :ref:`--code <code_commandline>` parameter
and more generally to each python execution.
After ``--py-args``, it is not possible to pass any other parameter than :ref:`-- <file_commandline>` to QGIS.
All arguments after ``--py-args`` till ``--`` are passed over to the python interpreter and ignored by QGIS.

.. code-block:: bash

qgis --code /home/user/test.py --py-args --specialScriptArguments "a text arg" 'and another arg' -- layer1 layer2

In the above code, :file:`test.py` will have this content in ``sys.argv``:
['/home/user/test.py', '--specialScriptArguments', 'a text arg', 'and another arg'].
``layer1`` and ``layer2`` will be normally handled by QGIS as layers to load.

qgis --code load_alaska.py

``--defaultui``
...............
Expand Down Expand Up @@ -2673,6 +2695,20 @@ without needing to replace the existing ones.

The equivalent environment variable is ``QGIS_OPENCL_PROGRAM_FOLDER``.

.. _file_commandline:

``--``
......

This option allows to pass following arguments as files to open in QGIS.
They can be supported rasters or vectors files, QGIS layer definition files or project files.

.. code-block:: bash

qgis -- /home/user/project.qgs /home/user/path_to_data/layer1.gpkg

The above code will start QGIS, open the :file:`project` file and load :file:`layer1` in it.

.. _deploying_organization:

Deploying QGIS within an organization
Expand Down
Loading