Coverage for apio/commands/options.py: 100%
19 statements
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
« prev ^ index » next coverage.py v7.16.1, created at 2026-09-23 03:53 +0000
1# -*- coding: utf-8 -*-
2# -- This file is part of the Apio project
3# -- (C) 2016-2024 FPGAwars
4# -- Authors
5# -- * Jesús Arroyo (2016-2019)
6# -- * Juan Gonzalez (obijuan) (2019-2024)
7# -- License GPLv2
8"""Common apio command options"""
10from pathlib import Path
11import click
12from apio.utils import cmd_util
15# The design is based on the idea here https://stackoverflow.com/a/77732441.
16# It contains shared command line options in two forms, dynamic option
17# which can be customized for specific use cases and fixed static options
18# with fixed attributes. Options that are too specific to a single command
19# not not listed here and defined instead in the command itself.
20# Both type of options are listed in an alphabetical order.
23# ----------------------------------
24# -- Customizable option generators
25# ----------------------------------
28def env_option_gen(*, short_help: str = "Set the apio.ini env."):
29 """Generate an --env option with given help text."""
31 return click.option(
32 "env", # Var name.
33 "-e",
34 "--env",
35 type=str,
36 default=None,
37 metavar="name",
38 help=short_help,
39 cls=cmd_util.ApioOption,
40 )
43def force_option_gen(*, short_help: str):
44 """Generate a --force option with given help text."""
46 return click.option(
47 "force", # Var name
48 "-f",
49 "--force",
50 is_flag=True,
51 help=short_help,
52 cls=cmd_util.ApioOption,
53 )
56def list_option_gen(*, short_help: str):
57 """Generate a --list option with given help text."""
59 return click.option(
60 "list_", # Var name. Deconflicting from python builtin 'list'.
61 "-l",
62 "--list",
63 is_flag=True,
64 help=short_help,
65 cls=cmd_util.ApioOption,
66 )
69def top_module_option_gen(
70 *,
71 short_help: str = "Set the top level module name.",
72):
73 """Generate a --top-module option with given help text."""
75 return click.option(
76 "top_module", # Var name.
77 "-t",
78 "--top-module",
79 type=str,
80 metavar="name",
81 # deprecated=deprecated,
82 help=short_help,
83 cls=cmd_util.ApioOption,
84 )
87def dst_option_gen(*, short_help: str):
88 """Generate a --dst option with given help text."""
90 dst_option = click.option(
91 "dst", # Var name.
92 "-d",
93 "--dst",
94 type=Path,
95 metavar="path",
96 help=short_help,
97 cls=cmd_util.ApioOption,
98 )
100 return dst_option
103# ---------------------------
104# -- Static options
105# ---------------------------
107docs_format_option = click.option(
108 "docs", # Var name.
109 "-d",
110 "--docs",
111 is_flag=True,
112 help="Format for Apio Docs.",
113 cls=cmd_util.ApioOption,
114)
116project_dir_option = click.option(
117 "project_dir", # Var name.
118 "-p",
119 "--project-dir",
120 type=Path,
121 metavar="path",
122 help="Set the root directory for the project.",
123 cls=cmd_util.ApioOption,
124)
127verbose_option = click.option(
128 "verbose", # Var name.
129 "-v",
130 "--verbose",
131 is_flag=True,
132 help="Show detailed output.",
133 cls=cmd_util.ApioOption,
134)
137verbose_pnr_option = click.option(
138 "verbose_pnr", # Var name.
139 "--verbose-pnr",
140 is_flag=True,
141 help="Show detailed pnr stage output.",
142 cls=cmd_util.ApioOption,
143)
146verbose_synth_option = click.option(
147 "verbose_synth", # Var name.
148 "--verbose-synth",
149 is_flag=True,
150 help="Show detailed synth stage output.",
151 cls=cmd_util.ApioOption,
152)