Skip to content

Commit fd0ebbe

Browse files
committed
Refactor Flutter command execution in CLI commands
Replaces 'flutter_build' with 'run_flutter' in build and debug commands, consolidating command execution logic. Updates method names for clarity and moves status updates and logging to command-specific implementations. Improves code maintainability and consistency across build and debug workflows.
1 parent 49fbaab commit fd0ebbe

File tree

3 files changed

+38
-33
lines changed

3 files changed

+38
-33
lines changed

sdk/python/packages/flet-cli/src/flet_cli/commands/build.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def handle(self, options: argparse.Namespace) -> None:
5757
self.update_flutter_dependencies()
5858
self.customize_icons()
5959
self.customize_splash_images()
60-
self.flutter_build()
60+
self.run_flutter()
6161
self.copy_build_output()
6262

6363
self.cleanup(
@@ -77,7 +77,7 @@ def handle(self, options: argparse.Namespace) -> None:
7777
),
7878
)
7979

80-
def add_flutter_build_args(self, args: list[str]):
80+
def add_flutter_command_args(self, args: list[str]):
8181
assert self.options
8282
assert self.build_dir
8383
assert self.get_pyproject
@@ -122,3 +122,19 @@ def add_flutter_build_args(self, args: list[str]):
122122
or []
123123
):
124124
args.append(arg)
125+
126+
def run_flutter(self):
127+
assert self.platforms
128+
assert self.target_platform
129+
130+
self.update_status(
131+
f"[bold blue]Building [cyan]"
132+
f"{self.platforms[self.target_platform]['status_text']}[/cyan]..."
133+
)
134+
135+
self._run_flutter_command()
136+
137+
console.log(
138+
f"Built [cyan]{self.platforms[self.target_platform]['status_text']}"
139+
f"[/cyan] {self.emojis['checkmark']}",
140+
)

sdk/python/packages/flet-cli/src/flet_cli/commands/debug.py

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import argparse
2+
import contextlib
23
import os
34
import platform
45

@@ -98,24 +99,8 @@ def handle(self, options: argparse.Namespace) -> None:
9899
self.update_flutter_dependencies()
99100
self.customize_icons()
100101
self.customize_splash_images()
101-
self.flutter_build()
102-
103-
self.cleanup(
104-
0,
105-
message=(
106-
f"Successfully built your [cyan]"
107-
f"{self.platforms[self.target_platform]['status_text']}"
108-
f"[/cyan]! {self.emojis['success']} "
109-
f"Find it in [cyan]{self.rel_out_dir}[/cyan] directory. "
110-
f"{self.emojis['directory']}"
111-
+ (
112-
"\nRun [cyan]flet serve[/cyan] command to start a web server "
113-
"with your app. "
114-
if self.target_platform == "web"
115-
else ""
116-
)
117-
),
118-
)
102+
self.run_flutter()
103+
self.cleanup(0, message=("Debug session ended."))
119104

120105
def check_device_id(self):
121106
if self.device_id is None and self.debug_platform in [
@@ -130,10 +115,20 @@ def check_device_id(self):
130115
"Use --show-devices option to list connected devices.",
131116
)
132117

133-
def add_flutter_build_args(self, args: list[str]):
118+
def add_flutter_command_args(self, args: list[str]):
134119
assert self.device_id
135120
args.extend(["run", "-d", self.device_id])
136121

122+
def run_flutter(self):
123+
assert self.platforms
124+
assert self.target_platform
125+
self.update_status(
126+
f"[bold blue]Running the app on [cyan]{self.debug_platform}[/cyan]..."
127+
)
128+
129+
with contextlib.suppress(KeyboardInterrupt):
130+
self._run_flutter_command()
131+
137132
def run_flutter_devices(self):
138133
self.update_status("[bold blue]Checking connected devices...")
139134
flutter_devices = self.run(

sdk/python/packages/flet-cli/src/flet_cli/commands/flutter_base.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,24 +1939,22 @@ def get_bool_setting(self, cli_option, pyproj_setting, default_value):
19391939
)
19401940
)
19411941

1942-
def add_flutter_build_args(self, args: list[str]):
1942+
def add_flutter_command_args(self, args: list[str]):
19431943
pass
19441944

1945-
def flutter_build(self):
1945+
def run_flutter(self):
1946+
self._run_flutter_command()
1947+
1948+
def _run_flutter_command(self):
19461949
assert self.options
19471950
assert self.build_dir
19481951
assert self.get_pyproject
19491952
assert self.template_data
19501953
assert self.target_platform
19511954

1952-
self.update_status(
1953-
f"[bold blue]Building [cyan]"
1954-
f"{self.platforms[self.target_platform]['status_text']}[/cyan]..."
1955-
)
1956-
19571955
# flutter build
19581956
build_args = [self.flutter_exe]
1959-
self.add_flutter_build_args(build_args)
1957+
self.add_flutter_command_args(build_args)
19601958
build_args.extend(
19611959
[
19621960
"--no-version-check",
@@ -2027,10 +2025,6 @@ def flutter_build(self):
20272025
if build_result.stderr:
20282026
console.log(build_result.stderr, style=error_style)
20292027
self.cleanup(build_result.returncode if build_result.returncode else 1)
2030-
console.log(
2031-
f"Built [cyan]{self.platforms[self.target_platform]['status_text']}"
2032-
f"[/cyan] {self.emojis['checkmark']}",
2033-
)
20342028

20352029
def copy_build_output(self):
20362030
assert self.template_data

0 commit comments

Comments
 (0)