Skip to content

Commit b993558

Browse files
committed
Update docs to include how to run a pack with path
`scope/name@range:path` is a valid way to specify a set of queries.
1 parent a9f4388 commit b993558

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

docs/codeql/codeql-cli/analyzing-databases-with-the-codeql-cli.rst

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,60 @@ pack names and use the ``--download`` flag::
135135
The ``analyze`` command above runs the default suite from ``microsoft/coding-standards v1.0.0`` and the latest version of ``github/security-queries`` on the specified database.
136136
For further information about default suites, see ":ref:`Publishing and using CodeQL packs <publishing-and-using-codeql-packs>`".
137137

138+
Running a subset of queries in a CodeQL pack
139+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
140+
141+
Additionally, you can include a path at the end of a pack specification to run a subset of queries inside the pack. This applies to any command that locates or runs queries within a pack.
142+
143+
The complete way to specify a set of queries is in the form ``scope/name@range:path``, where:
144+
145+
- ``scope/name`` is the qualified name of a CodeQL pack.
146+
- ``range`` is a `semver range <https://docs.npmjs.com/cli/v6/using-npm/semver#ranges>`_.
147+
- ``path`` is a file system path to a single query, a directory containing queries, or a query suite file.
148+
149+
If a ``scope/name`` is specified, the ``range`` and ``path`` are
150+
optional. A missing ``range`` implies the latest version of the
151+
specified pack. A missing ``path`` implies the default query suite
152+
of the specified pack.
153+
154+
The ``path`` can be one of a ``*.ql`` query file, a directory
155+
containing one or more queries, or a ``.qls`` query suite file. If
156+
there is no pack name specified, then a ``path`` must be provided,
157+
and will be interpreted relative to the current working directory
158+
of the current process.
159+
160+
If a ``scope/name`` and ``path`` are specified, then the ``path`` cannot
161+
be absolute. It is considered relative to the root of the CodeQL
162+
pack.
163+
164+
The relevant commands are:
165+
166+
* `codeql database analyze <../manual/database-analyze>`__.
167+
* `codeql database run-queries <../manual/database-run-queries>`__.
168+
* `codeql execute queries <../manual/execute-queries>`__.
169+
* `codeql resolve queries <../manual/resolve-queries>`__.
170+
171+
For example::
172+
173+
# Analyze a database using all queries in the experimental/Security folder within the codeql/cpp-queries
174+
# CodeQL query pack.
175+
codeql database analyze --format=sarif-latest --output=results <db> \
176+
codeql/cpp-queries:experimental/Security
177+
178+
# Analyse using only the RedundantNullCheckParam.ql query in the codeql/cpp-queries CodeQL query pack.
179+
codeql database analyze --format=sarif-latest --output=results <db> \
180+
'codeql/cpp-queries:experimental/Likely Bugs/RedundantNullCheckParam.ql'
181+
182+
# Analyse using the cpp-security-and-quality.qls query suite in the codeql/cpp-queries CodeQL query pack.
183+
codeql database analyze --format=sarif-latest --output=results <db> \
184+
'codeql/cpp-queries:codeql-suites/cpp-security-and-quality.qls'
185+
186+
# Analyse using the cpp-security-and-quality.qls query suite from a version of the codeql/cpp-queries pack
187+
# that is >= 0.0.3 and < 0.1.0 (the highest compatible version will be chosen).
188+
# All valid semver ranges are allowed. See https://docs.npmjs.com/cli/v6/using-npm/semver#ranges
189+
codeql database analyze --format=sarif-latest --output=results <db> \
190+
'codeql/cpp-queries@~0.0.3:codeql-suites/cpp-security-and-quality.qls'
191+
138192
For more information about CodeQL packs, see :doc:`About CodeQL Packs <about-codeql-packs>`.
139193

140194
Running query suites

0 commit comments

Comments
 (0)