Coverage for apio / commands / apio_docs.py: 50%
20 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"""Implementation of 'apio format' command"""
10import sys
11import webbrowser
12import click
13from apio.common.apio_console import cout
14from apio.apio_context import (
15 ApioContext,
16 PackagesPolicy,
17 ProjectPolicy,
18 RemoteConfigPolicy,
19)
20from apio.utils import cmd_util
23# -------------- apio format
25# -- Text in the rich-text format of the python rich library.
26APIO_DOCS_HELP = """
27The command 'apio docs' opens the Apio documentation using the user's \
28default browser.
30Examples:[code]
31 apio docs # Open the apio docs.
32 apio docs --commands # Land on the commands list page.
33"""
35commands_option = click.option(
36 "commands", # Var name.
37 "-c",
38 "--commands",
39 is_flag=True,
40 help="Show the commands page.",
41 cls=cmd_util.ApioOption,
42)
45@click.command(
46 name="docs",
47 cls=cmd_util.ApioCommand,
48 short_help="Show Apio documentation.",
49 help=APIO_DOCS_HELP,
50)
51@commands_option
52def cli(
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)
78 sys.exit(0)