<commit_before>.. _cli:

======================
Command Line Arguments
======================

The ``crash`` binary supports several command line arguments.

+---------------------------------------+--------------------------------------------------+
| Argument                              | Description                                      |
+=======================================+==================================================+
| ``-h``, ``--help``                    | Show the help message end exit.                  |
+---------------------------------------+--------------------------------------------------+
| ``-v``, ``--verbose``                 | Print debug information to stdout.               |
+---------------------------------------+--------------------------------------------------+
| ``-c COMMAND``, ``--command COMMAND`` | Execute the SQL statement and exit.              |
+---------------------------------------+--------------------------------------------------+
| ``--hosts HOSTS``                     | The Crate hosts to connect to.                   |
+---------------------------------------+--------------------------------------------------+
| ``--history HISTORY``                 | The history file the Crate shell uses.           |
+---------------------------------------+--------------------------------------------------+
| ``--format FORMAT``                   | Specifies the output format of the SQL response. |
+---------------------------------------+--------------------------------------------------+
| ``--version``                         | Print the crash version and exit.                |
+---------------------------------------+--------------------------------------------------+
| ``--sysinfo``                         | Print system and cluster information.            |
+---------------------------------------+--------------------------------------------------+
| ``-A`` , ``--no-autocomplete``        | Disable autocomplete of SQL keywords on startup. |
|                                       | Autocomplete requires a minimum terminal         |
|                                       | height of 8 lines due to size of the dropdown    |
|                                       | overlay for suggestions.                         |
|                                       | Disabling autocomplete removes this limitation.  |
+---------------------------------------+--------------------------------------------------+

Example Usage
=============

::

    $ crash --hosts st1.crate.io:4200 st2.crate.io st3.crate.io \
            --format json \
            -c 'select * from sys.nodes' > output.json


.. _commands:

==============
Crash Commands
==============

.. note::

    Crash client commands are available since version ``0.11.x``!

Crash has several client commands, which start with a backslash (``\``).

You can get a list of commands by typing ``\?``:

+----------------------+------------------------------------------------------------------------------------+
| Command              | Description                                                                        |
+======================+====================================================================================+
| ``\?``               | List all available commands.                                                       |
+----------------------+------------------------------------------------------------------------------------+
| ``\c``, ``\connect`` | Connect to the given server.                                                       |
|                      | Same as ``--host`` command line option.                                            |
+----------------------+------------------------------------------------------------------------------------+
| ``\dt``              | Print existing tables.                                                             |
|                      | The list does not include tables in the ``sys`` and ``information_schema`` schema. |
+----------------------+------------------------------------------------------------------------------------+
| ``\format``          | Switch the output format of the SQL response.                                      |
|                      | Same as ``--format`` command line option.                                          |
|                      | Available formats are: ``tabular``, ``raw``, ``json``, ``json_row``, ``csv``       |
|                      | and ``mixed``                                                                      |
|                      |                                                                                    |
|                      | see :ref:`formats` for details                                                     |
+----------------------+------------------------------------------------------------------------------------+
| ``\q``               | Quit Crate shell                                                                   |
+----------------------+------------------------------------------------------------------------------------+
| ``\check``           | Query the sys.checks table for failing cluster checks                              |
+----------------------+------------------------------------------------------------------------------------+
| ``\r <filename>``    | Reads statements from the given file and executes them                             |
+----------------------+------------------------------------------------------------------------------------+
| ``\sysinfo``         | Query the ``sys`` tables for system and cluster information                        |
+----------------------+------------------------------------------------------------------------------------+
| ``\autocomplete``    | Turn autocomplete feature on or off. Works as a toggle.                            |
+----------------------+------------------------------------------------------------------------------------+

===============
Status Messages
===============

The ``SUCCESS`` status messages are only printed when ``crash`` is used as
an interactive tty.

If the output is routed, e.g. dumped into a file or piped into another command
(such as `jq`_) for further processing of the response, these messages are omitted.


The synopsis of the ``SUCCESS`` message is as follows::

    SUCCESS <STMT>, <NUM> row(s) affected (<DURATION> sec)

If the SQL statement (``SELECT``) returns selected columns::

    SUCCESS <STMT> <NUM> row(s) in set (<DURATION> sec)

The ``STMT`` is the definition/manipulation/query keyword, such as
``CREATE``, ``INSERT``, ``UPDATE``, ``DELETE``, ``SELECT``, etc.

``NUM`` is the number of rows that were affected by the SQL statement.
It is ``-1`` for statements that do not affect any rows or
if the row count of a statement is unknown.

``DURATION`` is the time it took to process the SQL statement on the server
from request to response.


.. _jq: http://stedolan.github.io/jq/<commit_msg>document usage of --config command line argument<commit_after>.. _cli:

======================
Command Line Arguments
======================

The ``crash`` binary supports several command line arguments.

+---------------------------------------+--------------------------------------------------+
| Argument                              | Description                                      |
+=======================================+==================================================+
| ``-h``, ``--help``                    | Show the help message end exit.                  |
+---------------------------------------+--------------------------------------------------+
| ``-v``, ``--verbose``                 | Print debug information to stdout.               |
+---------------------------------------+--------------------------------------------------+
| ``-c COMMAND``, ``--command COMMAND`` | Execute the SQL statement and exit.              |
+---------------------------------------+--------------------------------------------------+
| ``--hosts HOSTS``                     | The Crate hosts to connect to.                   |
+---------------------------------------+--------------------------------------------------+
| ``--history HISTORY``                 | The history file the Crate shell uses.           |
+---------------------------------------+--------------------------------------------------+
| ``--config CONFIG``                   | Path to the configuration file which contains    |
|                                       | default values for Crash.                        |
|                                       | Defaults to the `user configuration directory`_  |
|                                       | of the operating system, which is e.g on Linux   |
|                                       | ``~/.config/Crate``,                             |
|                                       | ``~/Library/Application Support/Crate`` on OSX   |
|                                       | or ``C:\\Users\user\AppData\Local\Crate\Crate``  |
|                                       | on Windows.                                      |
+---------------------------------------+--------------------------------------------------+
| ``--format FORMAT``                   | Specifies the output format of the SQL response. |
+---------------------------------------+--------------------------------------------------+
| ``--version``                         | Print the crash version and exit.                |
+---------------------------------------+--------------------------------------------------+
| ``--sysinfo``                         | Print system and cluster information.            |
+---------------------------------------+--------------------------------------------------+
| ``-A`` , ``--no-autocomplete``        | Disable autocomplete of SQL keywords on startup. |
|                                       | Autocomplete requires a minimum terminal         |
|                                       | height of 8 lines due to size of the dropdown    |
|                                       | overlay for suggestions.                         |
|                                       | Disabling autocomplete removes this limitation.  |
+---------------------------------------+--------------------------------------------------+

Example Usage
=============

::

    $ crash --hosts st1.crate.io:4200 st2.crate.io st3.crate.io \
            --format json \
            -c 'select * from sys.nodes' > output.json


.. _commands:

==============
Crash Commands
==============

.. note::

    Crash client commands are available since version ``0.11.x``!

Crash has several client commands, which start with a backslash (``\``).

You can get a list of commands by typing ``\?``:

+----------------------+------------------------------------------------------------------------------------+
| Command              | Description                                                                        |
+======================+====================================================================================+
| ``\?``               | List all available commands.                                                       |
+----------------------+------------------------------------------------------------------------------------+
| ``\c``, ``\connect`` | Connect to the given server.                                                       |
|                      | Same as ``--host`` command line option.                                            |
+----------------------+------------------------------------------------------------------------------------+
| ``\dt``              | Print existing tables.                                                             |
|                      | The list does not include tables in the ``sys`` and ``information_schema`` schema. |
+----------------------+------------------------------------------------------------------------------------+
| ``\format``          | Switch the output format of the SQL response.                                      |
|                      | Same as ``--format`` command line option.                                          |
|                      | Available formats are: ``tabular``, ``raw``, ``json``, ``json_row``, ``csv``       |
|                      | and ``mixed``                                                                      |
|                      |                                                                                    |
|                      | see :ref:`formats` for details                                                     |
+----------------------+------------------------------------------------------------------------------------+
| ``\q``               | Quit Crate shell                                                                   |
+----------------------+------------------------------------------------------------------------------------+
| ``\check``           | Query the sys.checks table for failing cluster checks                              |
+----------------------+------------------------------------------------------------------------------------+
| ``\r <filename>``    | Reads statements from the given file and executes them                             |
+----------------------+------------------------------------------------------------------------------------+
| ``\sysinfo``         | Query the ``sys`` tables for system and cluster information                        |
+----------------------+------------------------------------------------------------------------------------+
| ``\autocomplete``    | Turn autocomplete feature on or off. Works as a toggle.                            |
+----------------------+------------------------------------------------------------------------------------+

===============
Status Messages
===============

The ``SUCCESS`` status messages are only printed when ``crash`` is used as
an interactive tty.

If the output is routed, e.g. dumped into a file or piped into another command
(such as `jq`_) for further processing of the response, these messages are omitted.


The synopsis of the ``SUCCESS`` message is as follows::

    SUCCESS <STMT>, <NUM> row(s) affected (<DURATION> sec)

If the SQL statement (``SELECT``) returns selected columns::

    SUCCESS <STMT> <NUM> row(s) in set (<DURATION> sec)

The ``STMT`` is the definition/manipulation/query keyword, such as
``CREATE``, ``INSERT``, ``UPDATE``, ``DELETE``, ``SELECT``, etc.

``NUM`` is the number of rows that were affected by the SQL statement.
It is ``-1`` for statements that do not affect any rows or
if the row count of a statement is unknown.

``DURATION`` is the time it took to process the SQL statement on the server
from request to response.


.. _jq: http://stedolan.github.io/jq/
.. _user configuration directory: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

{'fraction_non_alphanumeric': 0.385101850619092, 'fraction_numerical': 0.0015976567700705631, 'mean_word_length': 0.6965556182947488, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 81, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2790519', 'n_tokens_mistral': 2562, 'n_tokens_neox': 2352, 'n_words': 868}