Coverage for apio/commands/apio_docs.py: 50%
18 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"""Implementation of 'apio format' command"""
10import webbrowser
11import click
12from apio.common.apio_console import cout
13from apio.apio_context import (
14 ApioContext,
15 PackagesPolicy,
16 ProjectPolicy,
17 RemoteConfigPolicy,
18)
19from apio.utils import cmd_util
22# -------------- apio format
24# -- Text in the rich-text format of the python rich library.
25APIO_DOCS_HELP = """
26The command 'apio docs' opens the Apio documentation using the user's \
27default browser.
29Examples:[code]
30 apio docs # Open the apio docs.
31 apio docs --commands # Land on the commands list page.
32"""
34commands_option = click.option(
35 "commands", # Var name.
36 "-c",
37 "--commands",
38 is_flag=True,
39 help="Show the commands page.",
40 cls=cmd_util.ApioOption,
41)
44@click.command(
45 name="docs",
46 cls=cmd_util.ApioCommand,
47 short_help="Show Apio documentation.",
48 help=APIO_DOCS_HELP,
49)
50@commands_option
51def cli(
52 *,
53 # Options
54 commands,
55):
56 """Implements the docs command which opens the apio documentation in
57 the default browser.
58 """
60 # -- Create an apio context with a project object.
61 _ = ApioContext(
62 project_policy=ProjectPolicy.NO_PROJECT,
63 remote_config_policy=RemoteConfigPolicy.CACHED_OK,
64 packages_policy=PackagesPolicy.IGNORE_PACKAGES,
65 )
67 url = "https://fpgawars.github.io/apio/docs"
69 if commands:
70 url += "/commands-list"
72 cout(f"URL: {url}")
73 cout("Opening default browser")
75 default_browser = webbrowser.get()
76 default_browser.open(url)