Coverage for apio / commands / options.py: 100%
21 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-24 01:53 +0000
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-24 01: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 all_option_gen(*, short_help: str):
44 """Generate an --all option with given help text."""
46 return click.option(
47 "all_", # Var name. Deconflicting from Python'g builtin 'all'.
48 "-a",
49 "--all",
50 is_flag=True,
51 help=short_help,
52 cls=cmd_util.ApioOption,
53 )
56def force_option_gen(*, short_help: str):
57 """Generate a --force option with given help text."""
59 return click.option(
60 "force", # Var name
61 "-f",
62 "--force",
63 is_flag=True,
64 help=short_help,
65 cls=cmd_util.ApioOption,
66 )
69def list_option_gen(*, short_help: str):
70 """Generate a --list option with given help text."""
72 return click.option(
73 "list_", # Var name. Deconflicting from python builtin 'list'.
74 "-l",
75 "--list",
76 is_flag=True,
77 help=short_help,
78 cls=cmd_util.ApioOption,
79 )
82def top_module_option_gen(
83 *,
84 short_help: str = "Set the top level module name.",
85):
86 """Generate a --top-module option with given help text."""
88 return click.option(
89 "top_module", # Var name.
90 "-t",
91 "--top-module",
92 type=str,
93 metavar="name",
94 # deprecated=deprecated,
95 help=short_help,
96 cls=cmd_util.ApioOption,
97 )
100def dst_option_gen(*, short_help: str):
101 """Generate a --dst option with given help text."""
103 dst_option = click.option(
104 "dst", # Var name.
105 "-d",
106 "--dst",
107 type=Path,
108 metavar="path",
109 help=short_help,
110 cls=cmd_util.ApioOption,
111 )
113 return dst_option
116# ---------------------------
117# -- Static options
118# ---------------------------
120docs_format_option = click.option(
121 "docs", # Var name.
122 "-d",
123 "--docs",
124 is_flag=True,
125 help="Format for Apio Docs.",
126 cls=cmd_util.ApioOption,
127)
129project_dir_option = click.option(
130 "project_dir", # Var name.
131 "-p",
132 "--project-dir",
133 type=Path,
134 metavar="path",
135 help="Set the root directory for the project.",
136 cls=cmd_util.ApioOption,
137)
140verbose_option = click.option(
141 "verbose", # Var name.
142 "-v",
143 "--verbose",
144 is_flag=True,
145 help="Show detailed output.",
146 cls=cmd_util.ApioOption,
147)
150verbose_pnr_option = click.option(
151 "verbose_pnr", # Var name.
152 "--verbose-pnr",
153 is_flag=True,
154 help="Show detailed pnr stage output.",
155 cls=cmd_util.ApioOption,
156)
159verbose_synth_option = click.option(
160 "verbose_synth", # Var name.
161 "--verbose-synth",
162 is_flag=True,
163 help="Show detailed synth stage output.",
164 cls=cmd_util.ApioOption,
165)