Command-Line Client for Developers (teamscale-dev
)
This article describes teamscale-dev
, the Teamscale command-line client for developers. Among other things, this client can be used to integrate Teamscale with IDEs for which no dedicated IDE plug-in exists.
Installation
The CQSE website offers both platform-specific (for Windows, Linux, macOS) and platform-independent downloads for installation.
Commands
The command-line client for developers exposes its functionality as a set of commands. You can use the built-in help option, --help
, to list all available commands.
teamscale-dev --help
teamscale-dev --help
The various commands can be further configured by command-line options. Many options are common to most if not all commands, while others are specific to a command and explained in the following alongside their respective command. Additional configuration is taken from .teamscale.toml
IDE configuration files.
The pre-commit
Command
The pre-commit
(or precommit
) command uploads files to Teamscale for pre-commit analysis and, once the analysis is finished, displays findings for them in a common format. You can use this command in two ways:
Explicitly Uploading Files for Analysis: You can upload files or directories (including subdirectories) by passing them on the command line. For example:
shellteamscale-dev pre-commit src/Example.java
teamscale-dev pre-commit src/Example.java
shellteamscale-dev pre-commit src/
teamscale-dev pre-commit src/
Automatically Uploading Only Uncommitted Changes for Analysis: If the files and directories are under version control by a supported system (Git, Subversion), you can use the
--only-uncommitted-changes
option to restrict the upload to only those files that have uncommitted changes. For example:shellteamscale-dev pre-commit --only-uncommited-changes src/
teamscale-dev pre-commit --only-uncommited-changes src/
This will automatically determine which files below
src/
have local changes and only upload those for pre-commit analysis. (Files and directories not version-controlled by a supported system will never be uploaded when--only-uncommited-changes
is used.)
Pre-Commit Upload Limits
A Teamscale server may have an upload limit configured for the number of files included in a single pre-commit upload. Uploading entire directories is often prone to exceed this limit, even if only a few files therein have actually been changed. Using the --only-uncommitted-changes
option avoids this problem in most cases, i.e., for smaller changes.
Further options, e.g., --omit-links-to-findings
and --log-to-stder
control how and where the findings are reported.
The fetch-findings
Command
The fetch-findings
command fetches findings from Teamscale for one or more paths and displays them in a common format. Unlike the pre-commit
, fetch-findings
does not upload local files to Teamscale; it shows the findings as they exist on the remote server.
You can use this command in two ways:
Fetch findings for one or more files: For example:
shellteamscale-dev fetch-findings src/Example.java src/Utils.java
teamscale-dev fetch-findings src/Example.java src/Utils.java
Fetch findings for one or more directories: For example:
shellteamscale-dev fetch-findings src/main/java src/test/java
teamscale-dev fetch-findings src/main/java src/test/java
A mixture of files and directories in the same fetch-findings
command is not supported at the moment.
The open-in-browser
Command
The open-in-browser
(or browse
) command opens the Metrics > Files view in a Web browser, showing the given files and directories as they are known to Teamscale. For example:
teamscale-dev open-in-browser src/Example.java
teamscale-dev open-in-browser src/Example.java
teamscale-dev open-in-browser src/
teamscale-dev open-in-browser src/
The Web browser used by teamscale-dev
is your desktop's default browser. Consult your operating system's documentation for how to change this.
The generate-completion
Command
The generate-completion
command outputs a script that configures the programmable completion of the bash and zsh Unix shells to recognize teamscale-dev
and offer tab-completion for it.
source <( teamscale-dev generate-completion )
source <( teamscale-dev generate-completion )
To permanently install tab-completion support for teamscale-dev
, you can either place the above line in your shell's profile (e.g., ~/.bash_profile
) or save the output of teamscale-dev generate-completion
to a file and execute it from there (e.g., by placing it in a bash-completion.d
directory). Consult your operating system's documentation for the exact details.
Common Options
Many command-line options are common to most if not all commands offered by teamscale-dev
. These are described in the following.
In particular, you can use the help option, --help
, built into all commands to list their respective options. For example:
teamscale-dev pre-commit --help
teamscale-dev pre-commit --help
Supplying Server Credentials
Some commands like pre-commit
, fetch-findings
or open-in-browser
require you to supply your credentials for a Teamscale server, i.e., your username and IDE access key. You can pass these credentials to the command in several ways:
- The
--user
and--accesskey
command-line options:shellThese supply the username and IDE access key to use for all servers referenced in the applicable configuration files (teamscale-dev pre-commit --user username --accesskey accesskey ...
teamscale-dev pre-commit --user username --accesskey accesskey ...
.teamscale.toml
), unless they are configured explicitly using a--server
option or theTEAMSCALE_DEV_SERVERS
environment variable. (If you need to supply different credentials for different server URLs, you have to resort to one of the following alternatives.) - The
--server
command-line option:shell(You can use theteamscale-dev pre-commit --server https://username:accesskey@example.com/teamscale/ ...
teamscale-dev pre-commit --server https://username:accesskey@example.com/teamscale/ ...
--servers
option multiple times to supply credential URLs for multiple servers.) - The
TEAMSCALE_DEV_SERVERS
environment variable:shell(You can specify multiple credential URLs, separated by spaces, to supply credentials for multiple servers.)export TEAMSCALE_DEV_SERVERS="https://username:accesskey@example.com/teamscale/" teamscale-dev pre-commit ...
export TEAMSCALE_DEV_SERVERS="https://username:accesskey@example.com/teamscale/" teamscale-dev pre-commit ...
All three ways can be used at the same time. If different credentials are given for the same server URL, then the --server
option takes precedence over the TEAMSCALE_DEV_SERVERS
variable. Finally, the --user
and --accesskey
apply to any server whose credentials are not explicitly supplied via a credential URL.
These credential URLs are constructed as follows: If the Teamscale server in your configuration file (.teamscale.toml
) is, for example, https://example.com/teamscale/
, then the corresponding credential URL would look like https://username:accesskey@example.com/teamscale/
, with username
and accesskey
replaced by your username and IDE access key, respectively. Optionally, the credential URL can end with a #trust-all-certificates
suffix, which disables TLS certificate validation for the server in question.
Special Characters in Username and IDE Access Key
Certain characters cannot be used verbatim in credential URLs; they need to be percent-escaped. In particular, this applies to the colon (%3A
) and @-sign (%40
). A username of user@example.com
, for example, has to be written as user%40example.com
.
Accidentally Exposing the IDE Access Key in Multi-User Environments
Using the --accesskey
or --server
options on the command line may accidentally expose your access key if other users on the same machine can inspect the command line of running commands (e.g., using ps
or the Task Manager). To prevent this, place the respective option in an argument file (e.g., .teamscale-dev.args
) not readable by other users:
--server https://username:accesskey@example.com/teamscale/
--server https://username:accesskey@example.com/teamscale/
Then, include the options from the argument file using the @
-notation:
teamscale-dev pre-commit @.teamscale-dev.args ...
teamscale-dev pre-commit @.teamscale-dev.args ...
Disabling TLS Certificate validation
Some commands like pre-commit
and fetch-findings
connect to a Teamscale server. Such a connection may fail with a certificate-validation error when, for example, the server uses a self-signed certificate. In this case, you can disable TLS certificate validation in several ways:
- The
--insecure
command-line option:shellteamscale-dev pre-commit --insecure ...
teamscale-dev pre-commit --insecure ...
- The
--server
command-line option:shellteamscale-dev pre-commit --server https://username:accesskey@example.com/teamscale/#trust-all-certificates ...
teamscale-dev pre-commit --server https://username:accesskey@example.com/teamscale/#trust-all-certificates ...
- The
TEAMSCALE_DEV_SERVERS
environment variable:shellexport TEAMSCALE_DEV_SERVERS="https://username:accesskey@example.com/teamscale/#trust-all-certificates" teamscale-dev pre-commit ...
export TEAMSCALE_DEV_SERVERS="https://username:accesskey@example.com/teamscale/#trust-all-certificates" teamscale-dev pre-commit ...
Risk of Man-in-the-Middle Attacks
Disabling TLS certificate validation is insecure and increases the risk of successful man-in-the-middle attacks. It should only be done as a method of last resort or in testing environments.
Overriding Branch Information
Some commands like pre-commit
, fetch-findings
, and open-in-browser
need to determine which branch has been checked out from the version-control system. This happens automatically for supported version-control systems (Git, Subversion). If your version-control system is unsupported by teamscale-dev
or if you need to override the branch that has been automatically determined, you can override it explicitly.
In order of precedence, the branch is determined from these sources:
--branch
command-line optionproject.branch
property in your configuration file (.teamscale.toml
)- Branch checked out from version control
- Default branch of the respective Teamscale server
Finding Output Format
Commands that report findings (e.g., pre-commit
or fetch-findings
) do so in the GCC diagnostics format:
Path:Line:Column: (error|warning): Message
Path:Line:Column: (error|warning): Message
- Path is an absolute path to the (local) file for which findings are reported
- Line (starting with 1) and Column (always 1) numbers denote the first position within the file where the finding is found.
error
andwarning
corresponding to red and yellow findings, respectively.- Message is the finding's descriptive message
If the --show-links-to-findings
command-line option is used, an extended format is used:
Path:Line:Column: (error|warning): Message | (Link)
Path:Line:Column: (error|warning): Message | (Link)
- Link is a URL to open the Findings Detail view in a Web browser.
By default, findings are reported to stdout but can be redirected to stderr by using the --findings-to-stderr
command-line option.
Logging (--debug
, --trace
)
In case any problems arise or you need to report an issue to our support, you can log debug or trace information by using the --debug
or --trace
options, respectively. These options are supported by all subcommands of teamscale-dev
.
Optionally, you can refine which information is logged by specifying one or more categories. For example:
teamscale-dev --debug # --debug ALL
teamscale-dev --debug # --debug ALL
teamscale-dev --debug FINDINGS,SERVERS # --debug FINDINGS --debug SERVERS
teamscale-dev --debug FINDINGS,SERVERS # --debug FINDINGS --debug SERVERS
You can look up the exact list of supported categories using the --help
option.