xpd rules outline
Use xpd rules outline to map what files import and define before you read them in full. It lists
definitions, imports and members with line numbers and signatures, without running any code, in
any language that ast-grep parses.
xpd rules outline [OPTIONS] [PATHS]...Arguments
Section titled “Arguments”| Argument | What it does |
|---|---|
<PATHS>... |
Files or directories (directories respect .gitignore) |
Options
Section titled “Options”| Option | Default | What it does |
|---|---|---|
-l, --lang <LANG> |
The language to read. With paths, only files of this language are read. Values: bash, c, cc, c++, cpp, cxx, cs, csharp, css, dart, ex, elixir, go, golang, hs, haskell, hcl, html, java, javascript, js, jsx, json, kotlin, kt, lua, markdown, md, nix, php, py, python, rb, ruby, rs, rust, scala, sol, solidity, swift, tsx, ts, typescript, yaml, yml, zig. |
|
--stdin |
Read the code from stdin, in the language of --lang. | |
--format <FORMAT> |
Output format. Default: text on a terminal, json otherwise. JSON is one line. Values: text, json. |
|
--json[=<STYLE>] |
Print JSON (pretty unless a style is given) Optional value via --json=<VALUE>. Conflicts with --format. Values: pretty, compact, stream. |
|
--items <ITEMS> |
auto |
Which top-level items to list. Values: auto (structure for files and stdin, exports when a directory is given), structure (What each file defines, without its imports), exports (What each file exports: public names in Python), imports (What each file imports), all. |
--type <TYPE> |
Keep the items of these symbol types, separated by commas. Repeatable. Values: file, module, namespace, package, class, method, property, field, constructor, enum, interface, function, variable, constant, string, number, boolean, array, object, key, null, enumMember, struct, event, operator, typeParameter. |
|
--match <REGEX> |
Keep the items whose name or signature matches this regular expression. | |
--pub-members |
List only public members. | |
--view <VIEW> |
auto |
How to print the items as text. Values: auto (digest for files and stdin, names when a directory is given), names (The names of each file, one line per kind of symbol), signatures (One line per item, with its line number and signature), digest (The signatures, each with the names of its members), expanded (The signatures, each with one line per member). |
--outline-rules <FILE> |
More outline rule files, in the schema of ast-grep outline --outline-rules. Repeatable. |
|
--no-default-outline-rules |
Do not use the rules that ship with xpd. | |
--follow |
Follow symbolic links. | |
--no-ignore <FILE_TYPE> |
Ignore files to disregard. Repeat the flag for more than one. Repeatable. Values: hidden (Read hidden files and directories), dot (Disregard .ignore files), exclude (Disregard .git/info/exclude), global (Disregard the global git ignore file), parent (Disregard ignore files in parent directories), vcs (Disregard .gitignore files). |
|
--globs <GLOBS> |
Include or exclude paths that match a glob, as in .gitignore. ! excludes. Repeatable. |
Examples
Section titled “Examples”A file gets its definitions, each with the names of its members.
$ xpd rules outline samples/graph/steps.py --format textsamples/graph/steps.py14: LARGE_ORDER = 1000.015: PRICE = "unit_price"18: def totals(orders: pd.DataFrame) -> pd.DataFrame variable: orders28: def shares(orders: pd.DataFrame) -> pd.DataFrame variable: orders33: def discounts(orders: pd.DataFrame) -> pd.DataFrame variable: orders39: def flags(orders: pd.DataFrame) -> pd.DataFrame variable: orders47: def features(orders: pd.DataFrame) -> pd.DataFrame variable: ordersA folder gets a shorter view, with the public names of each file grouped by kind. --type,
--match and --view narrow it down.
$ xpd rules outline samples/graph --type function --match '^(totals|flags)' --view signatures --format textsamples/graph/impact.py6: def totals(orders: pd.DataFrame) -> pd.DataFrame
samples/graph/steps.py18: def totals(orders: pd.DataFrame) -> pd.DataFrame39: def flags(orders: pd.DataFrame) -> pd.DataFrame--globs keeps or drops paths by a glob, and --follow follows symbolic links when it walks
a folder.
Exit status
Section titled “Exit status”| Exit code | Meaning |
|---|---|
| 0 | The outline was printed |
| 2 | xpd could not run, or it could not read a path |