Coverage for apio/commands/options.py: 100%
21 statements
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +0000
« prev ^ index » next coverage.py v7.11.0, created at 2025-11-06 10:20 +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 "--docs",
123 is_flag=True,
124 help="Format for Apio Docs.",
125 cls=cmd_util.ApioOption,
126)
128project_dir_option = click.option(
129 "project_dir", # Var name.
130 "-p",
131 "--project-dir",
132 type=Path,
133 metavar="path",
134 help="Set the root directory for the project.",
135 cls=cmd_util.ApioOption,
136)
139verbose_option = click.option(
140 "verbose", # Var name.
141 "-v",
142 "--verbose",
143 is_flag=True,
144 help="Show detailed output.",
145 cls=cmd_util.ApioOption,
146)
149verbose_pnr_option = click.option(
150 "verbose_pnr", # Var name.
151 "--verbose-pnr",
152 is_flag=True,
153 help="Show detailed pnr stage output.",
154 cls=cmd_util.ApioOption,
155)
158verbose_synth_option = click.option(
159 "verbose_synth", # Var name.
160 "--verbose-synth",
161 is_flag=True,
162 help="Show detailed synth stage output.",
163 cls=cmd_util.ApioOption,
164)