Skip to content

Commit

Permalink
Add py-args and -- as command line parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
DelazJ committed Jan 14, 2025
1 parent c367964 commit ded384d
Showing 1 changed file with 38 additions and 2 deletions.
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 @@ -2378,6 +2378,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' included 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 @@ -2551,6 +2552,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 @@ -2569,9 +2572,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 @@ -2656,6 +2678,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

0 comments on commit ded384d

Please sign in to comment.