everydaydevops-luff 3.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. everydaydevops_luff-3.0.0.data/data/share/luff/skills/flutter-audit/SKILL.md +30 -0
  2. everydaydevops_luff-3.0.0.data/data/share/luff/skills/flutter-create/SKILL.md +27 -0
  3. everydaydevops_luff-3.0.0.data/data/share/luff/skills/flutter-feature/SKILL.md +30 -0
  4. everydaydevops_luff-3.0.0.data/data/share/luff/skills/flutter-migrate/SKILL.md +30 -0
  5. everydaydevops_luff-3.0.0.data/data/share/luff/skills/flutter-verify/SKILL.md +12 -0
  6. everydaydevops_luff-3.0.0.dist-info/METADATA +50 -0
  7. everydaydevops_luff-3.0.0.dist-info/RECORD +40 -0
  8. everydaydevops_luff-3.0.0.dist-info/WHEEL +5 -0
  9. everydaydevops_luff-3.0.0.dist-info/entry_points.txt +3 -0
  10. everydaydevops_luff-3.0.0.dist-info/licenses/LICENSE +21 -0
  11. everydaydevops_luff-3.0.0.dist-info/top_level.txt +1 -0
  12. flutter_setup/__init__.py +0 -0
  13. flutter_setup/appender.py +46 -0
  14. flutter_setup/bootstrap.py +1655 -0
  15. flutter_setup/cicd_generator.py +885 -0
  16. flutter_setup/cli.py +1193 -0
  17. flutter_setup/config.py +156 -0
  18. flutter_setup/config_manager.py +160 -0
  19. flutter_setup/core.py +204 -0
  20. flutter_setup/exceptions.py +37 -0
  21. flutter_setup/flutter_manager.py +579 -0
  22. flutter_setup/platform.py +15 -0
  23. flutter_setup/prerequisites.py +39 -0
  24. flutter_setup/prerequisites_linux.py +140 -0
  25. flutter_setup/prerequisites_macos.py +226 -0
  26. flutter_setup/project_cli.py +397 -0
  27. flutter_setup/project_creator.py +91 -0
  28. flutter_setup/standards.py +99 -0
  29. flutter_setup/standards_data/everyday-devops-flutter-1.0.0.json +97 -0
  30. flutter_setup/standards_data/manifest-v1.schema.json +209 -0
  31. flutter_setup/templates/everyday/AGENTS.md +5 -0
  32. flutter_setup/templates/everyday/app_log.dart +6 -0
  33. flutter_setup/templates/everyday/home_content.dart +9 -0
  34. flutter_setup/templates/everyday/home_repository.dart +8 -0
  35. flutter_setup/templates/everyday/home_screen.dart +60 -0
  36. flutter_setup/templates/everyday/offline_store.dart +5 -0
  37. flutter_setup/templates/everyday/sentry_startup.dart +16 -0
  38. flutter_setup/templates/everyday/theme.dart +12 -0
  39. flutter_setup/templates.py +73 -0
  40. flutter_setup/verification.py +160 -0
flutter_setup/cli.py ADDED
@@ -0,0 +1,1193 @@
1
+ #!/usr/bin/env python3
2
+ """Flutter Setup CLI - Main entry point."""
3
+
4
+ import sys
5
+ from pathlib import Path
6
+ from typing import Any, Dict, cast
7
+
8
+ import click
9
+ from rich.console import Console
10
+ from rich.panel import Panel
11
+
12
+ from .appender import (
13
+ PLATFORM_DIRS,
14
+ detect_flutter_project,
15
+ detect_platforms,
16
+ )
17
+ from .bootstrap import ProjectBootstrap
18
+ from .core import FlutterSetup
19
+ from .config import (
20
+ Config,
21
+ FlutterChannel,
22
+ TemplateType,
23
+ IosLanguage,
24
+ AndroidLanguage,
25
+ UpdateMode,
26
+ Architecture,
27
+ Database,
28
+ Testing,
29
+ E2ETesting,
30
+ AuthProvider,
31
+ CloudDatabase,
32
+ NotificationsProvider,
33
+ )
34
+ from .config_manager import ConfigManager
35
+ from .exceptions import FlutterSetupError
36
+ from .prerequisites import PrerequisitesManager
37
+ from .flutter_manager import FlutterManager
38
+ from .platform import detect_runtime_platform
39
+
40
+ console = Console()
41
+ VALID_PLATFORMS = set(PLATFORM_DIRS.keys())
42
+
43
+
44
+ def _is_interactive() -> bool:
45
+ """Return True when stdin is a TTY (interactive session)."""
46
+ return sys.stdin.isatty()
47
+
48
+
49
+ def _get_merged_or_prompt(
50
+ ctx: click.Context,
51
+ param_name: str,
52
+ cli_value: Any,
53
+ config_dict: Dict[str, Any],
54
+ prompt_text: str,
55
+ choices: list[str] | None = None,
56
+ config_key: str | None = None,
57
+ ) -> Any:
58
+ """Use CLI value if explicit, config file value if present and valid, else prompt."""
59
+ key = config_key or param_name
60
+ if ctx.get_parameter_source(param_name) == click.core.ParameterSource.COMMANDLINE:
61
+ return cli_value
62
+ if key in config_dict:
63
+ value = config_dict[key]
64
+ normalized = value.lower() if isinstance(value, str) else value
65
+ if choices is None or normalized in choices:
66
+ return normalized if isinstance(value, str) else value
67
+ if not _is_interactive():
68
+ return cli_value
69
+ if choices:
70
+ return click.prompt(
71
+ prompt_text,
72
+ default=cli_value,
73
+ type=click.Choice(choices, case_sensitive=False),
74
+ )
75
+ return click.prompt(prompt_text, default=cli_value)
76
+
77
+
78
+ def _get_merged(
79
+ ctx: click.Context,
80
+ param_name: str,
81
+ cli_value: Any,
82
+ config_dict: Dict[str, Any],
83
+ config_key: str | None = None,
84
+ ) -> Any:
85
+ """Use CLI value if explicit, config file value if present, else CLI default (no prompt)."""
86
+ key = config_key or param_name
87
+ if ctx.get_parameter_source(param_name) == click.core.ParameterSource.COMMANDLINE:
88
+ return cli_value
89
+ return config_dict.get(key, cli_value)
90
+
91
+
92
+ def print_banner() -> None:
93
+ """Print the application banner."""
94
+ banner = """
95
+ [bold blue]Luff[/bold blue]
96
+ [dim]Build better Flutter applications.[/dim]
97
+ """
98
+ console.print(Panel(banner, border_style="blue"))
99
+
100
+
101
+ @click.group(invoke_without_command=True)
102
+ @click.pass_context
103
+ def cli(ctx: click.Context) -> None:
104
+ """Luff engineering tools for Flutter applications."""
105
+ # If no subcommand provided, show banner and help
106
+ if ctx.invoked_subcommand is None:
107
+ print_banner()
108
+ click.echo(ctx.get_help())
109
+
110
+
111
+ @cli.command("init")
112
+ @click.option(
113
+ "--force",
114
+ is_flag=True,
115
+ help="Overwrite existing config file if it exists",
116
+ )
117
+ @click.option(
118
+ "--flutter-location",
119
+ default=None,
120
+ help="Flutter SDK location (skips prompt)",
121
+ )
122
+ @click.option(
123
+ "--channel",
124
+ type=click.Choice(["stable", "beta"], case_sensitive=False),
125
+ default=None,
126
+ help="Flutter channel (skips prompt)",
127
+ )
128
+ @click.option(
129
+ "--org",
130
+ default=None,
131
+ help="Organization identifier, e.g. com.example (skips prompt)",
132
+ )
133
+ def init_config(
134
+ force: bool,
135
+ flutter_location: str | None,
136
+ channel: str | None,
137
+ org: str | None,
138
+ ) -> None:
139
+ """Initialize the configuration file interactively or via flags."""
140
+ config_manager = ConfigManager()
141
+ config_manager.ensure_config_dir()
142
+
143
+ # Load existing config if it exists
144
+ existing_config = None
145
+ if config_manager.config_file.exists():
146
+ if force:
147
+ config_manager.config_file.unlink()
148
+ console.print(
149
+ f"[yellow]Deleted existing config: {config_manager.config_file}[/yellow]\n"
150
+ )
151
+ else:
152
+ console.print(
153
+ f"[yellow]⚠️ Config file already exists at: {config_manager.config_file}[/yellow]"
154
+ )
155
+ console.print("[dim]Loading existing configuration for editing...[/dim]\n")
156
+ existing_config = config_manager.load_config()
157
+
158
+ # Start interactive configuration
159
+ console.print("[bold blue]Flutter Setup Configuration[/bold blue]\n")
160
+
161
+ # 1. Flutter Location
162
+ console.print("[bold]1. Flutter SDK Location[/bold]")
163
+ if flutter_location is not None:
164
+ resolved_location = Path(flutter_location).expanduser().resolve()
165
+ else:
166
+ if existing_config:
167
+ current_location = existing_config.get("flutter", {}).get("location", "")
168
+ console.print(f"[dim]Current: {current_location}[/dim]")
169
+ else:
170
+ detected = config_manager.detect_flutter_location()
171
+ if detected:
172
+ console.print(f"[green]✓ Detected Flutter at: {detected}[/green]")
173
+ current_location = str(detected)
174
+ else:
175
+ default_location = str(Path.home() / "development" / "flutter")
176
+ console.print(f"[dim]Default: {default_location}[/dim]")
177
+ current_location = default_location
178
+
179
+ flutter_location_input = click.prompt(
180
+ "Flutter location",
181
+ default=current_location,
182
+ type=str,
183
+ )
184
+ resolved_location = Path(flutter_location_input).expanduser().resolve()
185
+
186
+ if not resolved_location.exists():
187
+ console.print(
188
+ "[yellow]⚠️ Warning: Path does not exist. It will be created when Flutter is installed.[/yellow]"
189
+ )
190
+
191
+ # 2. Flutter Channel
192
+ console.print("\n[bold]2. Flutter Channel[/bold]")
193
+ if channel is None:
194
+ if existing_config:
195
+ current_channel = existing_config.get("flutter", {}).get(
196
+ "channel", "stable"
197
+ )
198
+ console.print(f"[dim]Current: {current_channel}[/dim]")
199
+ else:
200
+ current_channel = "stable"
201
+
202
+ channel = click.prompt(
203
+ "Flutter channel",
204
+ default=current_channel,
205
+ type=click.Choice(["stable", "beta"], case_sensitive=False),
206
+ )
207
+
208
+ # 3. Organization ID
209
+ console.print("\n[bold]3. Organization ID[/bold]")
210
+ if org is None:
211
+ if existing_config:
212
+ current_org = existing_config.get("project", {}).get("org", "com.example")
213
+ console.print(f"[dim]Current: {current_org}[/dim]")
214
+ else:
215
+ current_org = "com.example"
216
+
217
+ org = click.prompt(
218
+ "Organization ID (e.g., com.example, com.mycompany)",
219
+ default=current_org,
220
+ type=str,
221
+ )
222
+
223
+ # Build the config, preserving any existing project settings not covered by init prompts
224
+ existing_project = existing_config.get("project", {}) if existing_config else {}
225
+ config = {
226
+ "flutter": {
227
+ "location": str(resolved_location),
228
+ "channel": (channel or "stable").lower(),
229
+ "update_mode": (
230
+ existing_config.get("flutter", {}).get("update_mode", "skip")
231
+ if existing_config
232
+ else "skip"
233
+ ),
234
+ },
235
+ "project": {
236
+ "org": org,
237
+ "template": existing_project.get("template", "app"),
238
+ # setup-owned fields: only carry forward if already written by a prior setup run
239
+ **{
240
+ k: existing_project[k]
241
+ for k in [
242
+ "architecture",
243
+ "database",
244
+ "testing",
245
+ "e2e_testing",
246
+ "auth_provider",
247
+ "cloud_database",
248
+ "notifications_provider",
249
+ "ios_language",
250
+ "android_language",
251
+ ]
252
+ if k in existing_project
253
+ },
254
+ },
255
+ }
256
+
257
+ # Save the config
258
+ config_manager.save_config(config)
259
+
260
+ # Show summary
261
+ console.print("\n[green]✅ Configuration saved![/green]")
262
+ console.print("\n[bold]Config file location:[/bold]")
263
+ console.print(f" {config_manager.config_file}")
264
+ console.print("\n[bold]Configuration summary:[/bold]")
265
+ console.print(f" Flutter location: {config['flutter']['location']}")
266
+ console.print(f" Flutter channel: {config['flutter']['channel']}")
267
+ console.print(f" Organization: {config['project']['org']}")
268
+ console.print(
269
+ "\n[dim]You can edit this file directly or run 'luff init' again to update it.[/dim]"
270
+ )
271
+
272
+
273
+ @cli.command("check")
274
+ @click.option(
275
+ "--verbose",
276
+ "-v",
277
+ is_flag=True,
278
+ help="Enable verbose output",
279
+ )
280
+ def check_command(verbose: bool) -> None:
281
+ """Check that prerequisites and Flutter SDK are ready and updated."""
282
+ try:
283
+ print_banner()
284
+ console.print("\n[bold]🔍 Checking Flutter development environment...[/bold]\n")
285
+
286
+ # Load configuration from file
287
+ config_manager = ConfigManager()
288
+ config_manager.ensure_config_dir()
289
+ file_config = config_manager.load_config()
290
+
291
+ # Get Flutter location from config file
292
+ flutter_location_str = file_config.get("flutter", {}).get("location")
293
+ if flutter_location_str:
294
+ flutter_location = Path(flutter_location_str)
295
+ else:
296
+ # Fallback to default if not in config
297
+ flutter_location = Path.home() / "development" / "flutter"
298
+
299
+ # Get channel from config
300
+ channel = file_config.get("flutter", {}).get("channel", "stable")
301
+
302
+ # Create minimal config for checking (we don't need project details)
303
+ host_platform = detect_runtime_platform()
304
+ default_platform = "ios" if host_platform == "darwin" else "linux"
305
+
306
+ # Use dummy values for required fields
307
+ config = Config(
308
+ project_name="dummy",
309
+ platforms=[default_platform],
310
+ org="com.example",
311
+ channel=channel,
312
+ output_dir=Path("."),
313
+ template="app",
314
+ ios_language="swift",
315
+ android_language="kotlin",
316
+ flutter_update_mode="skip", # Don't update during check
317
+ dry_run=False,
318
+ verbose=verbose,
319
+ flutter_location=flutter_location,
320
+ )
321
+
322
+ # Check prerequisites
323
+ console.print("[bold]📋 Checking prerequisites...[/bold]")
324
+ prerequisites = PrerequisitesManager(config)
325
+ prerequisites_ok = prerequisites.check_only()
326
+
327
+ # Check Flutter SDK
328
+ console.print("\n[bold]🦋 Checking Flutter SDK...[/bold]")
329
+ flutter_manager = FlutterManager(config)
330
+ flutter_ok = flutter_manager.check_only()
331
+
332
+ # Summary
333
+ console.print("\n[bold]📊 Summary[/bold]")
334
+ if prerequisites_ok and flutter_ok:
335
+ console.print(
336
+ "[green]✅ All checks passed! Your Flutter development environment is ready.[/green]"
337
+ )
338
+ sys.exit(0)
339
+ else:
340
+ console.print(
341
+ "[yellow]⚠️ Some checks failed. Please review the issues above.[/yellow]"
342
+ )
343
+ if not prerequisites_ok:
344
+ console.print(
345
+ "[dim]Run 'luff create --help' for the new-project setup options.[/dim]"
346
+ )
347
+ if not flutter_ok:
348
+ console.print(
349
+ "[dim]Run 'luff create --help' for new-project SDK options.[/dim]"
350
+ )
351
+ sys.exit(1)
352
+
353
+ except Exception as e:
354
+ console.print(f"[red]❌ Check failed: {e}[/red]")
355
+ if verbose:
356
+ console.print_exception()
357
+ sys.exit(1)
358
+
359
+
360
+ @cli.command("create")
361
+ @click.argument("project_name", required=False, default=None)
362
+ @click.option(
363
+ "--platforms",
364
+ multiple=True,
365
+ type=click.Choice(sorted(VALID_PLATFORMS), case_sensitive=False),
366
+ help="Target platforms (repeat for multiple: --platforms ios --platforms android)",
367
+ )
368
+ @click.option(
369
+ "--org",
370
+ default="com.example",
371
+ help="Organization identifier (default: com.example)",
372
+ )
373
+ @click.option(
374
+ "--channel",
375
+ type=click.Choice(["stable", "beta"]),
376
+ default="stable",
377
+ help="Flutter channel (default: stable)",
378
+ )
379
+ @click.option(
380
+ "--dir",
381
+ default=".",
382
+ type=click.Path(exists=True, file_okay=False, dir_okay=True),
383
+ help="Output directory (default: current directory)",
384
+ )
385
+ @click.option(
386
+ "--template",
387
+ type=click.Choice(["app", "plugin"]),
388
+ default="app",
389
+ help="Project template (default: app)",
390
+ )
391
+ @click.option(
392
+ "--architecture",
393
+ type=click.Choice(["basic", "clean"]),
394
+ default="basic",
395
+ help="Application architecture scaffold (default: basic)",
396
+ )
397
+ @click.option(
398
+ "--database",
399
+ type=click.Choice(["none", "sqlite"]),
400
+ default="none",
401
+ help="Local persistence scaffold (default: none)",
402
+ )
403
+ @click.option(
404
+ "--testing",
405
+ type=click.Choice(["standard", "mocktail"]),
406
+ default="standard",
407
+ help="Testing starter scaffold (default: standard)",
408
+ )
409
+ @click.option(
410
+ "--e2e-testing",
411
+ type=click.Choice(["integration_test", "patrol"]),
412
+ default="integration_test",
413
+ help="End-to-end testing framework (default: integration_test)",
414
+ )
415
+ @click.option(
416
+ "--auth-provider",
417
+ type=click.Choice(["none", "firebase"]),
418
+ default="none",
419
+ help="Auth integration scaffold (default: none)",
420
+ )
421
+ @click.option(
422
+ "--cloud-database",
423
+ type=click.Choice(["none", "firestore"]),
424
+ default="none",
425
+ help="Cloud database integration scaffold (default: none)",
426
+ )
427
+ @click.option(
428
+ "--notifications-provider",
429
+ type=click.Choice(["none", "firebase"]),
430
+ default="none",
431
+ help="Push notifications scaffold (default: none)",
432
+ )
433
+ @click.option(
434
+ "--ios-language",
435
+ type=click.Choice(["swift", "objc"]),
436
+ default="swift",
437
+ help="iOS language for plugin templates (default: swift)",
438
+ )
439
+ @click.option(
440
+ "--android-language",
441
+ type=click.Choice(["kotlin", "java"]),
442
+ default="kotlin",
443
+ help="Android language for plugin templates (default: kotlin)",
444
+ )
445
+ @click.option(
446
+ "--flutter-update",
447
+ type=click.Choice(["reset", "reclone", "skip"]),
448
+ default="skip",
449
+ help="Flutter update mode (default: skip)",
450
+ )
451
+ @click.option(
452
+ "--flutter-version",
453
+ default=None,
454
+ help="Required Flutter SDK version (e.g. 3.24.0). Errors early if not installed.",
455
+ )
456
+ @click.option(
457
+ "--dry-run",
458
+ is_flag=True,
459
+ help="Preview actions without executing them",
460
+ )
461
+ @click.option(
462
+ "--verbose",
463
+ "-v",
464
+ is_flag=True,
465
+ help="Enable verbose output",
466
+ )
467
+ @click.pass_context
468
+ def create_command(
469
+ ctx: click.Context,
470
+ project_name: str | None,
471
+ platforms: tuple[str, ...],
472
+ org: str,
473
+ channel: FlutterChannel,
474
+ dir: str,
475
+ template: TemplateType,
476
+ architecture: Architecture,
477
+ database: Database,
478
+ testing: Testing,
479
+ e2e_testing: E2ETesting,
480
+ auth_provider: AuthProvider,
481
+ cloud_database: CloudDatabase,
482
+ notifications_provider: NotificationsProvider,
483
+ ios_language: IosLanguage,
484
+ android_language: AndroidLanguage,
485
+ flutter_update: UpdateMode,
486
+ flutter_version: str | None,
487
+ dry_run: bool,
488
+ verbose: bool,
489
+ ) -> None:
490
+ """Create a new Flutter project with complete development environment setup."""
491
+ try:
492
+ print_banner()
493
+
494
+ # Load configuration from file
495
+ config_manager = ConfigManager()
496
+ config_manager.ensure_config_dir()
497
+ file_config = config_manager.load_config()
498
+ file_project = file_config.get("project", {})
499
+ file_flutter = file_config.get("flutter", {})
500
+
501
+ # Get Flutter location from config file
502
+ flutter_location_str = file_config.get("flutter", {}).get("location")
503
+ if flutter_location_str:
504
+ flutter_location = Path(flutter_location_str)
505
+ else:
506
+ flutter_location = Path.home() / "development" / "flutter"
507
+ config_manager.set_flutter_location(flutter_location)
508
+
509
+ def get_merged_or_prompt(
510
+ param_name: str,
511
+ cli_value: Any,
512
+ config_dict: Dict[str, Any],
513
+ prompt_text: str,
514
+ choices: list[str] | None = None,
515
+ config_key: str | None = None,
516
+ ) -> Any:
517
+ return _get_merged_or_prompt(
518
+ ctx,
519
+ param_name,
520
+ cli_value,
521
+ config_dict,
522
+ prompt_text,
523
+ choices,
524
+ config_key,
525
+ )
526
+
527
+ def get_merged(
528
+ param_name: str,
529
+ cli_value: Any,
530
+ config_dict: Dict[str, Any],
531
+ config_key: str | None = None,
532
+ ) -> Any:
533
+ return _get_merged(ctx, param_name, cli_value, config_dict, config_key)
534
+
535
+ # Prompt for required arguments if not provided on the command line
536
+ if project_name is None:
537
+ project_name = click.prompt("Project name", type=str)
538
+ project_name = cast(str, project_name)
539
+
540
+ # Guard: refuse to create if the target directory already exists
541
+ target_project_dir = Path(dir) / project_name
542
+ if target_project_dir.exists():
543
+ raise click.UsageError(
544
+ f"Directory '{project_name}' already exists in {dir!r}. "
545
+ f"Use 'luff append' to add tooling to an existing project."
546
+ )
547
+
548
+ if not platforms:
549
+ console.print(
550
+ "[dim]Available platforms: ios, android, macos, linux, windows, web[/dim]"
551
+ )
552
+ platforms_str = click.prompt(
553
+ "Platforms (space-separated)",
554
+ default="ios android",
555
+ )
556
+ platforms = tuple(p.strip() for p in platforms_str.split() if p.strip())
557
+
558
+ if not platforms:
559
+ console.print("[red]Error: At least one platform is required[/red]")
560
+ sys.exit(1)
561
+
562
+ # Merge CLI options with config file, prompting for values not in either
563
+ merged_org = get_merged_or_prompt(
564
+ "org", org, file_project, "Organization ID (e.g., com.mycompany)"
565
+ )
566
+ merged_channel = cast(
567
+ FlutterChannel,
568
+ get_merged_or_prompt(
569
+ "channel",
570
+ channel,
571
+ file_flutter,
572
+ "Flutter channel",
573
+ choices=["stable", "beta"],
574
+ ),
575
+ )
576
+ merged_template = cast(
577
+ TemplateType,
578
+ get_merged_or_prompt(
579
+ "template",
580
+ template,
581
+ file_project,
582
+ "Project template",
583
+ choices=["app", "plugin"],
584
+ ),
585
+ )
586
+ merged_architecture = cast(
587
+ Architecture,
588
+ get_merged_or_prompt(
589
+ "architecture",
590
+ architecture,
591
+ file_project,
592
+ "Architecture",
593
+ choices=["basic", "clean"],
594
+ ),
595
+ )
596
+ merged_database = cast(
597
+ Database,
598
+ get_merged_or_prompt(
599
+ "database",
600
+ database,
601
+ file_project,
602
+ "Local database",
603
+ choices=["none", "sqlite"],
604
+ ),
605
+ )
606
+ merged_testing = cast(
607
+ Testing,
608
+ get_merged_or_prompt(
609
+ "testing",
610
+ testing,
611
+ file_project,
612
+ "Testing framework",
613
+ choices=["standard", "mocktail"],
614
+ ),
615
+ )
616
+ merged_e2e_testing = cast(
617
+ E2ETesting,
618
+ get_merged_or_prompt(
619
+ "e2e_testing",
620
+ e2e_testing,
621
+ file_project,
622
+ "End-to-end testing framework",
623
+ choices=["integration_test", "patrol"],
624
+ ),
625
+ )
626
+ merged_auth_provider = cast(
627
+ AuthProvider,
628
+ get_merged_or_prompt(
629
+ "auth_provider",
630
+ auth_provider,
631
+ file_project,
632
+ "Auth provider",
633
+ choices=["none", "firebase"],
634
+ ),
635
+ )
636
+ merged_cloud_database = cast(
637
+ CloudDatabase,
638
+ get_merged_or_prompt(
639
+ "cloud_database",
640
+ cloud_database,
641
+ file_project,
642
+ "Cloud database",
643
+ choices=["none", "firestore"],
644
+ ),
645
+ )
646
+ merged_notifications_provider = cast(
647
+ NotificationsProvider,
648
+ get_merged_or_prompt(
649
+ "notifications_provider",
650
+ notifications_provider,
651
+ file_project,
652
+ "Notifications provider",
653
+ choices=["none", "firebase"],
654
+ ),
655
+ )
656
+ # Language options only apply to plugin templates; never prompt for app projects
657
+ if merged_template == "plugin":
658
+ merged_ios_language = cast(
659
+ IosLanguage,
660
+ get_merged_or_prompt(
661
+ "ios_language",
662
+ ios_language,
663
+ file_project,
664
+ "iOS language",
665
+ choices=["swift", "objc"],
666
+ ),
667
+ )
668
+ merged_android_language = cast(
669
+ AndroidLanguage,
670
+ get_merged_or_prompt(
671
+ "android_language",
672
+ android_language,
673
+ file_project,
674
+ "Android language",
675
+ choices=["kotlin", "java"],
676
+ ),
677
+ )
678
+ else:
679
+ merged_ios_language = cast(
680
+ IosLanguage, get_merged("ios_language", ios_language, file_project)
681
+ )
682
+ merged_android_language = cast(
683
+ AndroidLanguage,
684
+ get_merged("android_language", android_language, file_project),
685
+ )
686
+ merged_flutter_update = cast(
687
+ UpdateMode,
688
+ get_merged_or_prompt(
689
+ "flutter_update",
690
+ flutter_update,
691
+ file_flutter,
692
+ "Flutter update mode",
693
+ choices=["reset", "reclone", "skip"],
694
+ config_key="update_mode",
695
+ ),
696
+ )
697
+
698
+ # Create configuration
699
+ config = Config(
700
+ project_name=project_name,
701
+ platforms=list(platforms),
702
+ org=merged_org,
703
+ channel=merged_channel,
704
+ output_dir=Path(dir),
705
+ template=merged_template,
706
+ ios_language=merged_ios_language,
707
+ android_language=merged_android_language,
708
+ flutter_update_mode=merged_flutter_update,
709
+ dry_run=dry_run,
710
+ verbose=verbose,
711
+ flutter_location=flutter_location,
712
+ architecture=merged_architecture,
713
+ database=merged_database,
714
+ testing=merged_testing,
715
+ e2e_testing=merged_e2e_testing,
716
+ auth_provider=merged_auth_provider,
717
+ cloud_database=merged_cloud_database,
718
+ notifications_provider=merged_notifications_provider,
719
+ flutter_version=flutter_version,
720
+ )
721
+
722
+ if dry_run:
723
+ console.print(
724
+ "\n[yellow]DRY RUN: Would create Flutter project (no changes made)[/yellow]"
725
+ )
726
+ return
727
+
728
+ # Create and run setup
729
+ setup = FlutterSetup(config)
730
+ setup.run()
731
+
732
+ console.print("\n[green]✅ Flutter setup completed successfully![/green]")
733
+
734
+ except FlutterSetupError as e:
735
+ console.print(f"[red]❌ Setup failed: {e}[/red]")
736
+ if verbose:
737
+ console.print_exception()
738
+ sys.exit(1)
739
+ except KeyboardInterrupt:
740
+ console.print("\n[yellow]⚠️ Setup interrupted by user[/yellow]")
741
+ sys.exit(1)
742
+ except Exception as e:
743
+ console.print(f"[red]❌ Unexpected error: {e}[/red]")
744
+ if verbose:
745
+ console.print_exception()
746
+ sys.exit(1)
747
+
748
+
749
+ @cli.command("append")
750
+ @click.argument("project_name", required=False, default=None)
751
+ @click.option(
752
+ "--platforms",
753
+ multiple=True,
754
+ type=click.Choice(sorted(VALID_PLATFORMS), case_sensitive=False),
755
+ help="Platforms for a new project (only used when target is not a Flutter project; "
756
+ "repeat for multiple: --platforms ios --platforms android)",
757
+ )
758
+ @click.option(
759
+ "--dir",
760
+ "target_dir",
761
+ default=".",
762
+ type=click.Path(exists=True, file_okay=False, dir_okay=True),
763
+ help="Target directory (default: current directory)",
764
+ )
765
+ @click.option(
766
+ "--force",
767
+ is_flag=True,
768
+ help="Overwrite existing editor config and workflow files",
769
+ )
770
+ @click.option(
771
+ "--org",
772
+ default="com.example",
773
+ help="Organization identifier (default: com.example)",
774
+ )
775
+ @click.option(
776
+ "--channel",
777
+ type=click.Choice(["stable", "beta"]),
778
+ default="stable",
779
+ help="Flutter channel (default: stable)",
780
+ )
781
+ @click.option(
782
+ "--template",
783
+ type=click.Choice(["app", "plugin"]),
784
+ default="app",
785
+ help="Project template (default: app)",
786
+ )
787
+ @click.option(
788
+ "--architecture",
789
+ type=click.Choice(["basic", "clean"]),
790
+ default="basic",
791
+ help="Application architecture scaffold (default: basic)",
792
+ )
793
+ @click.option(
794
+ "--database",
795
+ type=click.Choice(["none", "sqlite"]),
796
+ default="none",
797
+ help="Local persistence scaffold (default: none)",
798
+ )
799
+ @click.option(
800
+ "--testing",
801
+ type=click.Choice(["standard", "mocktail"]),
802
+ default="standard",
803
+ help="Testing starter scaffold (default: standard)",
804
+ )
805
+ @click.option(
806
+ "--e2e-testing",
807
+ type=click.Choice(["integration_test", "patrol"]),
808
+ default="integration_test",
809
+ help="End-to-end testing framework (default: integration_test)",
810
+ )
811
+ @click.option(
812
+ "--auth-provider",
813
+ type=click.Choice(["none", "firebase"]),
814
+ default="none",
815
+ help="Auth integration scaffold (default: none)",
816
+ )
817
+ @click.option(
818
+ "--cloud-database",
819
+ type=click.Choice(["none", "firestore"]),
820
+ default="none",
821
+ help="Cloud database integration scaffold (default: none)",
822
+ )
823
+ @click.option(
824
+ "--notifications-provider",
825
+ type=click.Choice(["none", "firebase"]),
826
+ default="none",
827
+ help="Push notifications scaffold (default: none)",
828
+ )
829
+ @click.option(
830
+ "--ios-language",
831
+ type=click.Choice(["swift", "objc"]),
832
+ default="swift",
833
+ help="iOS language for plugin templates (default: swift)",
834
+ )
835
+ @click.option(
836
+ "--android-language",
837
+ type=click.Choice(["kotlin", "java"]),
838
+ default="kotlin",
839
+ help="Android language for plugin templates (default: kotlin)",
840
+ )
841
+ @click.option(
842
+ "--flutter-update",
843
+ type=click.Choice(["reset", "reclone", "skip"]),
844
+ default="skip",
845
+ help="Flutter update mode (default: skip)",
846
+ )
847
+ @click.option(
848
+ "--flutter-version",
849
+ default=None,
850
+ help="Required Flutter SDK version (e.g. 3.24.0).",
851
+ )
852
+ @click.option(
853
+ "--dry-run",
854
+ is_flag=True,
855
+ help="Preview actions without executing them",
856
+ )
857
+ @click.option(
858
+ "--verbose",
859
+ "-v",
860
+ is_flag=True,
861
+ help="Enable verbose output",
862
+ )
863
+ @click.pass_context
864
+ def append_command(
865
+ ctx: click.Context,
866
+ project_name: str | None,
867
+ platforms: tuple[str, ...],
868
+ target_dir: str,
869
+ force: bool,
870
+ org: str,
871
+ channel: FlutterChannel,
872
+ template: TemplateType,
873
+ architecture: Architecture,
874
+ database: Database,
875
+ testing: Testing,
876
+ e2e_testing: E2ETesting,
877
+ auth_provider: AuthProvider,
878
+ cloud_database: CloudDatabase,
879
+ notifications_provider: NotificationsProvider,
880
+ ios_language: IosLanguage,
881
+ android_language: AndroidLanguage,
882
+ flutter_update: UpdateMode,
883
+ flutter_version: str | None,
884
+ dry_run: bool,
885
+ verbose: bool,
886
+ ) -> None:
887
+ """Append Luff tooling to an existing directory.
888
+
889
+ If the directory is already a Flutter project, adds editor configs,
890
+ Makefile targets, and CI/CD workflows without re-creating Flutter files.
891
+ If not, runs full setup to create the Flutter project first.
892
+ """
893
+ try:
894
+ print_banner()
895
+
896
+ # Load configuration from file for Flutter location
897
+ config_manager = ConfigManager()
898
+ config_manager.ensure_config_dir()
899
+ file_config = config_manager.load_config()
900
+
901
+ flutter_location_str = file_config.get("flutter", {}).get("location")
902
+ if flutter_location_str:
903
+ flutter_location = Path(flutter_location_str)
904
+ else:
905
+ flutter_location = Path.home() / "development" / "flutter"
906
+
907
+ file_flutter = file_config.get("flutter", {})
908
+ file_project = file_config.get("project", {})
909
+
910
+ # Prefer values from the config file over Click defaults when the user
911
+ # did not explicitly pass the option on the command line.
912
+ if org == "com.example" and file_project.get("org"):
913
+ org = file_project["org"]
914
+ if channel == "stable" and file_flutter.get("channel"):
915
+ channel = cast(FlutterChannel, file_flutter["channel"])
916
+ if ctx.get_parameter_source(
917
+ "e2e_testing"
918
+ ) != click.core.ParameterSource.COMMANDLINE and file_project.get("e2e_testing"):
919
+ raw = str(file_project["e2e_testing"]).lower()
920
+ if raw in ("integration_test", "patrol"):
921
+ e2e_testing = cast(E2ETesting, raw)
922
+
923
+ target_path = Path(target_dir).resolve()
924
+ is_flutter = detect_flutter_project(target_path)
925
+
926
+ if is_flutter:
927
+ detected_platforms = detect_platforms(target_path)
928
+ console.print(f"[dim]Detected Flutter project: {target_path.name}[/dim]")
929
+ console.print(
930
+ f"[dim]Detected platforms: {', '.join(detected_platforms)}[/dim]"
931
+ )
932
+
933
+ config = Config(
934
+ project_name=target_path.name,
935
+ platforms=detected_platforms,
936
+ org=org,
937
+ channel=channel,
938
+ output_dir=target_path.parent,
939
+ template="app",
940
+ ios_language="swift",
941
+ android_language="kotlin",
942
+ flutter_update_mode="skip",
943
+ dry_run=dry_run,
944
+ verbose=verbose,
945
+ flutter_location=flutter_location,
946
+ architecture=architecture,
947
+ database=database,
948
+ testing=testing,
949
+ e2e_testing=e2e_testing,
950
+ auth_provider=auth_provider,
951
+ cloud_database=cloud_database,
952
+ notifications_provider=notifications_provider,
953
+ flutter_version=flutter_version,
954
+ )
955
+
956
+ if dry_run:
957
+ console.print(
958
+ "\n[yellow]DRY RUN: Would append tooling to Flutter project (no changes made)[/yellow]"
959
+ )
960
+ return
961
+
962
+ bootstrap = ProjectBootstrap(config, force=force)
963
+ bootstrap.append_project()
964
+ else:
965
+ # Not a Flutter project: require project_name, run full setup
966
+ if not project_name:
967
+ raise click.UsageError(
968
+ "project_name is required when the target directory is not a Flutter project"
969
+ )
970
+
971
+ platforms_list: list[str]
972
+ if platforms:
973
+ platforms_list = list(platforms)
974
+ elif not _is_interactive():
975
+ platforms_list = ["ios", "android", "web"]
976
+ else:
977
+ console.print(
978
+ "[dim]Available platforms: ios, android, macos, linux, windows, web[/dim]"
979
+ )
980
+ platforms_str = click.prompt(
981
+ "Platforms (space-separated)",
982
+ default="ios android",
983
+ )
984
+ platforms_list = [p.strip() for p in platforms_str.split() if p.strip()]
985
+ invalid = [p for p in platforms_list if p not in VALID_PLATFORMS]
986
+ if invalid:
987
+ raise click.UsageError(
988
+ f"Unknown platform(s): {', '.join(invalid)}. "
989
+ f"Valid options: {', '.join(sorted(VALID_PLATFORMS))}"
990
+ )
991
+
992
+ merged_org = _get_merged_or_prompt(
993
+ ctx, "org", org, file_project, "Organization ID (e.g., com.mycompany)"
994
+ )
995
+ merged_channel = cast(
996
+ FlutterChannel,
997
+ _get_merged_or_prompt(
998
+ ctx,
999
+ "channel",
1000
+ channel,
1001
+ file_flutter,
1002
+ "Flutter channel",
1003
+ choices=["stable", "beta"],
1004
+ ),
1005
+ )
1006
+ merged_template = cast(
1007
+ TemplateType,
1008
+ _get_merged_or_prompt(
1009
+ ctx,
1010
+ "template",
1011
+ template,
1012
+ file_project,
1013
+ "Project template",
1014
+ choices=["app", "plugin"],
1015
+ ),
1016
+ )
1017
+ merged_architecture = cast(
1018
+ Architecture,
1019
+ _get_merged_or_prompt(
1020
+ ctx,
1021
+ "architecture",
1022
+ architecture,
1023
+ file_project,
1024
+ "Architecture",
1025
+ choices=["basic", "clean"],
1026
+ ),
1027
+ )
1028
+ merged_database = cast(
1029
+ Database,
1030
+ _get_merged_or_prompt(
1031
+ ctx,
1032
+ "database",
1033
+ database,
1034
+ file_project,
1035
+ "Local database",
1036
+ choices=["none", "sqlite"],
1037
+ ),
1038
+ )
1039
+ merged_testing = cast(
1040
+ Testing,
1041
+ _get_merged_or_prompt(
1042
+ ctx,
1043
+ "testing",
1044
+ testing,
1045
+ file_project,
1046
+ "Testing framework",
1047
+ choices=["standard", "mocktail"],
1048
+ ),
1049
+ )
1050
+ merged_e2e_testing = cast(
1051
+ E2ETesting,
1052
+ _get_merged_or_prompt(
1053
+ ctx,
1054
+ "e2e_testing",
1055
+ e2e_testing,
1056
+ file_project,
1057
+ "End-to-end testing framework",
1058
+ choices=["integration_test", "patrol"],
1059
+ ),
1060
+ )
1061
+ merged_auth_provider = cast(
1062
+ AuthProvider,
1063
+ _get_merged_or_prompt(
1064
+ ctx,
1065
+ "auth_provider",
1066
+ auth_provider,
1067
+ file_project,
1068
+ "Auth provider",
1069
+ choices=["none", "firebase"],
1070
+ ),
1071
+ )
1072
+ merged_cloud_database = cast(
1073
+ CloudDatabase,
1074
+ _get_merged_or_prompt(
1075
+ ctx,
1076
+ "cloud_database",
1077
+ cloud_database,
1078
+ file_project,
1079
+ "Cloud database",
1080
+ choices=["none", "firestore"],
1081
+ ),
1082
+ )
1083
+ merged_notifications_provider = cast(
1084
+ NotificationsProvider,
1085
+ _get_merged_or_prompt(
1086
+ ctx,
1087
+ "notifications_provider",
1088
+ notifications_provider,
1089
+ file_project,
1090
+ "Notifications provider",
1091
+ choices=["none", "firebase"],
1092
+ ),
1093
+ )
1094
+ if merged_template == "plugin":
1095
+ merged_ios_language = cast(
1096
+ IosLanguage,
1097
+ _get_merged_or_prompt(
1098
+ ctx,
1099
+ "ios_language",
1100
+ ios_language,
1101
+ file_project,
1102
+ "iOS language",
1103
+ choices=["swift", "objc"],
1104
+ ),
1105
+ )
1106
+ merged_android_language = cast(
1107
+ AndroidLanguage,
1108
+ _get_merged_or_prompt(
1109
+ ctx,
1110
+ "android_language",
1111
+ android_language,
1112
+ file_project,
1113
+ "Android language",
1114
+ choices=["kotlin", "java"],
1115
+ ),
1116
+ )
1117
+ else:
1118
+ merged_ios_language = cast(
1119
+ IosLanguage,
1120
+ _get_merged(ctx, "ios_language", ios_language, file_project),
1121
+ )
1122
+ merged_android_language = cast(
1123
+ AndroidLanguage,
1124
+ _get_merged(
1125
+ ctx, "android_language", android_language, file_project
1126
+ ),
1127
+ )
1128
+ merged_flutter_update = cast(
1129
+ UpdateMode,
1130
+ _get_merged_or_prompt(
1131
+ ctx,
1132
+ "flutter_update",
1133
+ flutter_update,
1134
+ file_flutter,
1135
+ "Flutter update mode",
1136
+ choices=["reset", "reclone", "skip"],
1137
+ config_key="update_mode",
1138
+ ),
1139
+ )
1140
+
1141
+ config = Config(
1142
+ project_name=project_name,
1143
+ platforms=platforms_list,
1144
+ org=merged_org,
1145
+ channel=merged_channel,
1146
+ output_dir=target_path,
1147
+ template=merged_template,
1148
+ ios_language=merged_ios_language,
1149
+ android_language=merged_android_language,
1150
+ flutter_update_mode=merged_flutter_update,
1151
+ dry_run=dry_run,
1152
+ verbose=verbose,
1153
+ flutter_location=flutter_location,
1154
+ architecture=merged_architecture,
1155
+ database=merged_database,
1156
+ testing=merged_testing,
1157
+ e2e_testing=merged_e2e_testing,
1158
+ auth_provider=merged_auth_provider,
1159
+ cloud_database=merged_cloud_database,
1160
+ notifications_provider=merged_notifications_provider,
1161
+ flutter_version=flutter_version,
1162
+ )
1163
+
1164
+ setup = FlutterSetup(config)
1165
+ setup.run()
1166
+
1167
+ console.print("\n[green]✅ Append completed successfully![/green]")
1168
+
1169
+ except click.UsageError:
1170
+ raise
1171
+ except FlutterSetupError as e:
1172
+ console.print(f"[red]❌ Append failed: {e}[/red]")
1173
+ if verbose:
1174
+ console.print_exception()
1175
+ sys.exit(1)
1176
+ except KeyboardInterrupt:
1177
+ console.print("\n[yellow]⚠️ Append interrupted by user[/yellow]")
1178
+ sys.exit(1)
1179
+ except Exception as e:
1180
+ console.print(f"[red]❌ Unexpected error: {e}[/red]")
1181
+ if verbose:
1182
+ console.print_exception()
1183
+ sys.exit(1)
1184
+
1185
+
1186
+ def main() -> None:
1187
+ """Main entry point that routes to appropriate command."""
1188
+ cli()
1189
+
1190
+
1191
+ if __name__ == "__main__":
1192
+ # Click handles argument parsing
1193
+ main()