hy/docs/language/cli.rst
Brandon T. Willard e468d5f081 Refactor REPL error handling and filter Hy internal trace output
These changes make the Hy REPL more closely follow `code.InteractiveConsole`'s
class interface and provide minimally intrusive traceback print-out filtering
via a context manager that temporarily alters `sys.excepthook`.  In other words,
exception messages from the REPL will no longer show Hy internal
code (e.g. importer, compiler and parsing functions).

The boolean variable `hy.errors._hy_filter_internal_errors` dynamically
enables/disables trace filtering, and the env variable
`HY_FILTER_INTERNAL_ERRORS` can be used as the initial value.
2019-02-07 13:43:58 -05:00

115 lines
1.9 KiB
ReStructuredText

======================
Command Line Interface
======================
.. _hy:
hy
--
Command Line Options
^^^^^^^^^^^^^^^^^^^^
.. cmdoption:: -c <command>
Execute the Hy code in *command*.
.. code-block:: bash
$ hy -c "(print (+ 2 2))"
4
.. cmdoption:: -i <command>
Execute the Hy code in *command*, then stay in REPL.
.. cmdoption:: -m <module>
Execute the Hy code in *module*, including ``defmain`` if defined.
The :option:`-m` flag terminates the options list so that
all arguments after the *module* name are passed to the module in
``sys.argv``.
.. versionadded:: 0.11.0
.. cmdoption:: --spy
Print equivalent Python code before executing in REPL. For example::
=> (defn salutationsnm [name] (print (+ "Hy " name "!")))
def salutationsnm(name):
return print(((u'Hy ' + name) + u'!'))
=> (salutationsnm "YourName")
salutationsnm(u'YourName')
Hy YourName!
=>
`--spy` only works on REPL mode.
.. versionadded:: 0.9.11
.. cmdoption:: --repl-output-fn
Format REPL output using specific function (e.g., hy.contrib.hy-repr.hy-repr)
.. versionadded:: 0.13.0
.. cmdoption:: -v
Print the Hy version number and exit.
.. _hyc:
hyc
---
Command Line Options
^^^^^^^^^^^^^^^^^^^^
.. cmdoption:: file[, fileN]
Compile Hy code to Python bytecode. For example, save the
following code as ``hyname.hy``:
.. code-block:: hy
(defn hy-hy [name]
(print (+ "Hy " name "!")))
(hy-hy "Afroman")
Then run:
.. code-block:: bash
$ hyc hyname.hy
$ python hyname.pyc
Hy Afroman!
.. _hy2py:
hy2py
-----
.. versionadded:: 0.10.1
Command Line Options
^^^^^^^^^^^^^^^^^^^^
.. cmdoption:: -s
--with-source
Show the parsed source structure.
.. cmdoption:: -a
--with-ast
Show the generated AST.
.. cmdoption:: -np
--without-python
Do not show the Python code generated from the AST.