From c6f0c937a2226bdcca46432a5ea981fff553a0a7 Mon Sep 17 00:00:00 2001 From: Obijuan Date: Fri, 15 Mar 2024 21:33:22 +0100 Subject: [PATCH] resource.py refactoring --- .vscode/launch.json | 4 ++-- apio/commands/boards.py | 29 +++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 8e657730..e41ae3c5 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -86,11 +86,11 @@ "type": "debugpy", "request": "launch", "program": "${file}", - "args": ["boards", "-f"], + "args": ["boards", "-l"], "console": "internalConsole", "justMyCode": true, //-- Change to the folder with the example to test - "cwd": "${workspaceFolder}/test-examples/Alhambra-II/ledon" + "cwd": "${workspaceFolder}/test-examples/Alhambra-II/temp-ledon" }, { "name": "Apio config", diff --git a/apio/commands/boards.py b/apio/commands/boards.py index d07c7074..4f78231e 100644 --- a/apio/commands/boards.py +++ b/apio/commands/boards.py @@ -1,7 +1,9 @@ # -*- coding: utf-8 -*- # -- This file is part of the Apio project -# -- (C) 2016-2019 FPGAwars -# -- Author Jesús Arroyo +# -- (C) 2016-2024 FPGAwars +# -- Authors +# -- * Jesús Arroyo (2016-2019) +# -- * Juan Gonzalez (obijuan) (2019-2024) # -- Licence GPLv2 """Main implementation of APIO BOARDS command""" @@ -10,27 +12,38 @@ from apio.resources import Resources from apio import util +# ------------------ +# -- CONSTANTS +# ------------------ +CMD = "boards" # -- Comand name +LIST = "list" # -- Option +FPGA = "fpga" # -- Option -@click.command("boards", context_settings=util.context_settings()) + +@click.command(CMD, context_settings=util.context_settings()) @click.pass_context @click.option( "-l", - "--list", - "list_boards", + f"--{LIST}", is_flag=True, help="List all supported FPGA boards.", ) @click.option( - "-f", "--fpga", is_flag=True, help="List all supported FPGA chips." + "-f", f"--{FPGA}", is_flag=True, help="List all supported FPGA chips." ) -def cli(ctx, list_boards: bool, fpga: bool): +def cli(ctx, **kwargs): + # def cli(ctx, list_boards: bool, fpga: bool): """Manage FPGA boards.""" + # -- Extract the arguments + _list = kwargs[LIST] # -- bool + fpga = kwargs[FPGA] # -- bool + # -- Access to the apio resources resources = Resources() # -- Option 1: List boards - if list_boards: + if _list: resources.list_boards() # -- Option 2: List fpgas