Skip to content

Commit c53b7eb

Browse files
committed
Add CLI arguments
1 parent bfd8159 commit c53b7eb

File tree

3 files changed

+93
-14
lines changed

3 files changed

+93
-14
lines changed

tools/config_editor/app.py

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,25 @@
66
This is a simple application to configure the static libraries for the ESP32 Arduino core.
77
It allows the user to select the targets to compile, change the configuration options and compile the libraries.
88
9-
The application is built using the 'textual' library, which is a Python library for building text-based user interfaces.
9+
The application is built using the "textual" library, which is a Python library for building text-based user interfaces.
1010
1111
The first argument to the script is the path to the Arduino core. If no argument is provided, it is assumed that the
1212
Arduino core is located in the default path `/arduino-esp32` (docker image default).
1313
1414
"""
1515

16+
import argparse
1617
import os
18+
import platform
19+
20+
from pathlib import Path
1721

1822
try:
1923
from textual.app import App, ComposeResult
2024
from textual.containers import Container
2125
from textual.widgets import Button, Header, Label
2226
except ImportError:
23-
print("Please install the 'textual-dev' package before running this script.")
27+
print("Please install the \"textual-dev\" package before running this script.")
2428
quit()
2529

2630
from targets import TargetsScreen
@@ -32,11 +36,16 @@ class ConfigEditorApp(App):
3236

3337
# Change to the root directory of the app to the root of the project
3438
script_path = os.path.abspath(os.path.dirname(__file__))
35-
root_path = os.path.abspath(os.path.join(script_path, '..', '..'))
39+
root_path = os.path.abspath(os.path.join(script_path, "..", ".."))
3640
os.chdir(root_path)
3741

38-
# Target is set to "all" by default
39-
target_str = "all"
42+
# Options
43+
option_target = None
44+
option_arduino_path = None
45+
option_arduino_branch = None
46+
option_idf_branch = None
47+
option_idf_commit = None
48+
option_debug_level = None
4049

4150
ENABLE_COMMAND_PALETTE = False
4251
CSS_PATH = "style.tcss"
@@ -50,19 +59,19 @@ def update_targets(self, targets: str) -> None:
5059
# Callback function to update the targets after returning from the targets screen
5160
print("Updating targets in app, received: " + targets)
5261
if targets:
53-
self.target_str = str(targets)
62+
self.option_target = str(targets)
5463

5564
def on_button_pressed(self, event: Button.Pressed) -> None:
5665
# Event handler called when a button is pressed
5766
if event.button.id == "compile-button":
5867
print("Compile button pressed")
59-
self.push_screen('compile')
68+
self.push_screen("compile")
6069
elif event.button.id == "targets-button":
6170
print("Targets button pressed")
62-
self.push_screen('targets', self.update_targets)
71+
self.push_screen("targets", self.update_targets)
6372
elif event.button.id == "options-button":
6473
print("Options button pressed")
65-
self.push_screen('editor')
74+
self.push_screen("editor")
6675
elif event.button.id == "quit-button":
6776
print("Quit button pressed")
6877
quit()
@@ -81,12 +90,82 @@ def on_mount(self) -> None:
8190
# Event handler called when the app is mounted for the first time
8291
self.title = "Configurator"
8392
self.sub_title = "Main Menu"
84-
print("App started")
85-
93+
print("App started. Initial Options:")
94+
print("Target: " + str(self.option_target))
95+
print("Arduino Path: " + str(self.option_arduino_path))
96+
print("Arduino Branch: " + str(self.option_arduino_branch))
97+
print("IDF Branch: " + str(self.option_idf_branch))
98+
print("IDF Commit: " + str(self.option_idf_commit))
99+
print("IDF Debug Level: " + str(self.option_debug_level))
100+
101+
def arduino_default_path():
102+
sys_name = platform.system()
103+
home = str(Path.home())
104+
if sys_name == "Linux":
105+
return os.path.join(home, "Arduino", "hardware", "espressif", "esp32")
106+
else: # Windows and MacOS
107+
return os.path.join(home, "Documents", "Arduino", "hardware", "espressif", "esp32")
86108

87109
def main() -> None:
110+
app = ConfigEditorApp()
111+
112+
parser = argparse.ArgumentParser(description="Configure and compile the ESP32 Arduino static libraries")
113+
114+
target_choices = ("all", "esp32", "esp32s2", "esp32s3", "esp32c2", "esp32c3", "esp32c6", "esp32h2")
115+
parser.add_argument("-t", "--target",
116+
metavar="<target>",
117+
type=str,
118+
default="all",
119+
choices=target_choices,
120+
required=False,
121+
help="Target to be compiled. Choose from: " + ", ".join(target_choices))
122+
123+
parser.add_argument("-c", "--arduino-path",
124+
metavar="<arduino path>",
125+
type=str,
126+
default=arduino_default_path(),
127+
required=False,
128+
help="Path to arduino-esp32 directory")
129+
130+
parser.add_argument("-A", "--arduino-branch",
131+
metavar="<arduino branch>",
132+
type=str,
133+
required=False,
134+
help="Branch of the arduino-esp32 repository to be used")
135+
136+
parser.add_argument("-I", "--idf-branch",
137+
metavar="<IDF branch>",
138+
type=str,
139+
required=False,
140+
help="Branch of the ESP-IDF repository to be used")
141+
142+
parser.add_argument("-i", "--idf-commit",
143+
metavar="<IDF commit>",
144+
type=str,
145+
required=False,
146+
help="Commit of the ESP-IDF repository to be used")
147+
148+
debug_level_choices = ("default", "none", "error", "warning", "info", "debug", "verbose")
149+
parser.add_argument("-D", "--debug-level",
150+
metavar="<level>",
151+
type=str,
152+
default="default",
153+
choices=debug_level_choices,
154+
required=False,
155+
help="Debug level to be set to ESP-IDF. Choose from: " + ", ".join(debug_level_choices))
156+
157+
args = parser.parse_args()
158+
159+
# Set the options in the app
160+
app.option_target = args.target
161+
app.option_arduino_path = args.arduino_path
162+
app.option_arduino_branch = args.arduino_branch
163+
app.option_idf_branch = args.idf_branch
164+
app.option_idf_commit = args.idf_commit
165+
app.option_debug_level = args.debug_level
166+
88167
# Main function to run the app
89-
ConfigEditorApp().run()
168+
app.run()
90169

91170
if __name__ == "__main__":
92171
# If this script is run directly, start the app

tools/config_editor/compile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ async def compile_libs(self) -> None:
3434

3535
label = self.query_one("#compile-title", Static)
3636
self.child_process = None
37-
target = self.app.target_str
37+
target = self.app.option_target
3838

3939
if os.path.exists(arduino_path):
4040
print("Starting compilation process. Using Arduino path: " + arduino_path)

tools/config_editor/targets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class TargetsScreen(Screen[str]):
1313

1414
def update_targets(self) -> None:
1515
# Update the targets in the screen
16-
self.temp_target_str = str(self.app.target_str)
16+
self.temp_target_str = str(self.app.option_target)
1717
print("Target updated in screen: " + self.temp_target_str)
1818

1919
def on_button_pressed(self, event: Button.Pressed) -> None:

0 commit comments

Comments
 (0)