Skip to content

cli

Classes:

Functions:

CustomHelpFormatter

CustomHelpFormatter(
    prog: str,
    indent_increment: int = 2,
    max_help_position: int = 4,
    width: Optional[int] = None,
    **kwargs: Any,
)

Bases: RawTextHelpFormatter

Only the name of this class is considered a public API. All the methods provided by the class are considered an implementation detail.

Source code in src/arx/cli.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
def __init__(
    self,
    prog: str,
    indent_increment: int = 2,
    max_help_position: int = 4,
    width: Optional[int] = None,
    **kwargs: Any,
) -> None:
    """
    title: Initialize CustomHelpFormatter.
    parameters:
      prog:
        type: str
      indent_increment:
        type: int
      max_help_position:
        type: int
      width:
        type: Optional[int]
      kwargs:
        type: Any
        variadic: keyword
    """
    super().__init__(
        prog,
        indent_increment=indent_increment,
        max_help_position=max_help_position,
        width=width,
        **kwargs,
    )

app

app(argv: Sequence[str] | None = None) -> None
Source code in src/arx/cli.py
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
def app(argv: Sequence[str] | None = None) -> None:
    """
    title: Run the application.
    parameters:
      argv:
        type: Sequence[str] | None
    """
    raw_args = list(sys.argv[1:] if argv is None else argv)

    if raw_args and raw_args[0] == "test":
        args_parser = get_test_args()
        args = args_parser.parse_args(raw_args[1:])
        arx = ArxMain()
        exit_code = arx.run_tests(**dict(args._get_kwargs()))
        if exit_code != 0:
            raise SystemExit(exit_code)
        return None

    if raw_args and _looks_like_subcommand_attempt(raw_args[0]):
        known = ", ".join(KNOWN_SUBCOMMANDS)
        print(
            f"arx: unknown command '{raw_args[0]}' "
            f"(known subcommands: {known})",
            file=sys.stderr,
        )
        raise SystemExit(2)

    args_parser = get_args()
    args = (
        args_parser.parse_args()
        if argv is None
        else args_parser.parse_args(raw_args)
    )

    if args.input_files and args.input_files[0] == "run":
        args.run = True
        args.input_files = args.input_files[1:]

    if args.version:
        return show_version()

    if not args.shell and args.input_files:
        missing = [
            entry for entry in args.input_files if not Path(entry).is_file()
        ]
        if missing:
            print(
                f"arx: input file not found: '{missing[0]}'",
                file=sys.stderr,
            )
            raise SystemExit(2)

    arx = ArxMain()
    return arx.run(**dict(args._get_kwargs()))

get_args

get_args() -> ArgumentParser
Source code in src/arx/cli.py
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
def get_args() -> argparse.ArgumentParser:
    """
    title: Get the CLI arguments.
    returns:
      type: argparse.ArgumentParser
    """
    parser = argparse.ArgumentParser(
        prog="arx",
        description=(
            "Arx is a compiler that uses the power of llvm to bring a modern "
            "infra-structure."
        ),
        epilog=(
            "If you have any problem, open an issue at: "
            "https://github.com/arxlang/arx"
        ),
        add_help=True,
        formatter_class=CustomHelpFormatter,
    )
    parser.add_argument(
        "input_files",
        nargs="*",
        type=str,
        help="The input file",
    )
    parser.add_argument(
        "--version",
        action="store_true",
        help="Show the version of the installed MakIm tool.",
    )

    parser.add_argument(
        "--output-file",
        type=str,
        help="The output file",
    )

    parser.add_argument(
        "--lib",
        dest="is_lib",
        action="store_true",
        help="build source code as library",
    )

    parser.add_argument(
        "--show-ast",
        action="store_true",
        help="Show the AST for the input source code",
    )

    parser.add_argument(
        "--show-tokens",
        action="store_true",
        help="Show the tokens for the input source code",
    )

    parser.add_argument(
        "--show-llvm-ir",
        action="store_true",
        help="Show the LLVM IR for the input source code",
    )

    parser.add_argument(
        "--shell",
        action="store_true",
        help="Open Arx in a shell prompt",
    )

    parser.add_argument(
        "--run",
        action="store_true",
        help="Build and run the compiled binary.",
    )
    parser.add_argument(
        "--link-mode",
        type=str,
        choices=("auto", "pie", "no-pie"),
        default="auto",
        help=(
            "Set executable link mode: auto (toolchain default), "
            "pie, or no-pie."
        ),
    )

    return parser

get_test_args

get_test_args() -> ArgumentParser
Source code in src/arx/cli.py
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
def get_test_args() -> argparse.ArgumentParser:
    """
    title: Get the CLI arguments for `arx test`.
    returns:
      type: argparse.ArgumentParser
    """
    parser = argparse.ArgumentParser(
        prog="arx test",
        description="Discover, compile, and run Arx tests.",
        formatter_class=CustomHelpFormatter,
    )
    parser.add_argument(
        "paths",
        nargs="*",
        type=str,
        help=(
            "Test files or directories to discover tests in. "
            "Directories are searched recursively for files matching the "
            "configured file pattern. Defaults to `tests` (or the value "
            "from [tests].paths in .arxproject.toml, if present)."
        ),
    )
    parser.add_argument(
        "--list",
        dest="list_only",
        action="store_true",
        help="List discovered tests without running them",
    )
    parser.add_argument(
        "-k",
        dest="name_filter",
        default="",
        type=str,
        help="Run only tests whose names contain the given substring",
    )
    parser.add_argument(
        "-x",
        "--fail-fast",
        dest="fail_fast",
        action="store_true",
        help="Stop after the first failing test",
    )
    parser.add_argument(
        "--exclude",
        dest="exclude",
        action="append",
        default=None,
        type=str,
        help=(
            "Glob pattern to exclude from test discovery. Repeat the flag "
            "to supply multiple patterns."
        ),
    )
    parser.add_argument(
        "--file-pattern",
        dest="file_pattern",
        default=None,
        type=str,
        help="Glob pattern for test file discovery (default: test_*.x)",
    )
    parser.add_argument(
        "--function-pattern",
        dest="function_pattern",
        default=None,
        type=str,
        help="Glob pattern for test function names (default: test_*)",
    )
    parser.add_argument(
        "--keep-artifacts",
        action="store_true",
        help="Keep generated wrapper/debug artifacts and executables",
    )
    parser.add_argument(
        "--link-mode",
        type=str,
        choices=("auto", "pie", "no-pie"),
        default="auto",
        help=(
            "Set executable link mode for generated test binaries: "
            "auto, pie, or no-pie."
        ),
    )
    return parser

show_version

show_version() -> None
Source code in src/arx/cli.py
230
231
232
233
234
def show_version() -> None:
    """
    title: Show the application version.
    """
    print(__version__)