Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/src/cli/cli_runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import '../commands/manifest_command.dart';
import '../commands/apply_command.dart';
import '../commands/module_command.dart';
import '../commands/xray_command.dart';
import '../commands/setup_command.dart';
import '../core/plugin_system/cli_aware_plugin.dart';
import '../core/plugin_system/plugin_registry.dart';
import '../core/error/suggestion_engine.dart';
Expand Down Expand Up @@ -85,6 +86,7 @@ class CliRunner {
_runner.addCommand(ModuleCommand());
_runner.addCommand(XrayCommand());
_runner.addCommand(UpdateCommand());
_runner.addCommand(SetupCommand());
}

/// Run CLI with arguments.
Expand Down Expand Up @@ -216,16 +218,21 @@ zfa - Zuraffa Code Generator v$version
USAGE:
zfa <command> [options]

BOOTSTRAP:
setup <name> Create a new Flutter/Dart app with zuraffa deps wired in
init Wire zuraffa dependencies + scaffold a test entity

CORE COMMANDS:
make <Name> Canonical architecture/code generation command
feature <Name> Wrapper over `make --preset=feature`
initialize Initialize a test entity
initialize Alias of init — wire deps + scaffold a test entity
entity Create and manage Zorphy entities
config Manage ZFA configuration
doctor Check your environment and v5 migration readiness
schema Output JSON schema
validate <file> Validate JSON configuration
migrate <target> Migrate v5 artifacts to v6 (state, gql, di)
build Run build_runner to generate code from annotations
Comment on lines +221 to +235

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

The alias description is inverted.

_InitializeCommand declares name => 'initialize' and aliases => ['init']. The help text at line 228 states that initialize is an alias of init, which reverses the relationship. zfa help and zfa initialize --help will disagree. Describe init as the alias of initialize.

📝 Proposed fix
 BOOTSTRAP:
   setup <name>        Create a new Flutter/Dart app with zuraffa deps wired in
-  init                Wire zuraffa dependencies + scaffold a test entity
+  init                Alias of initialize — wire deps + scaffold a test entity
-  initialize          Alias of init — wire deps + scaffold a test entity
+  initialize          Wire zuraffa dependencies + scaffold a test entity
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
BOOTSTRAP:
setup <name> Create a new Flutter/Dart app with zuraffa deps wired in
init Wire zuraffa dependencies + scaffold a test entity
CORE COMMANDS:
make <Name> Canonical architecture/code generation command
feature <Name> Wrapper over `make --preset=feature`
initialize Initialize a test entity
initialize Alias of init — wire deps + scaffold a test entity
entity Create and manage Zorphy entities
config Manage ZFA configuration
doctor Check your environment and v5 migration readiness
schema Output JSON schema
validate <file> Validate JSON configuration
migrate <target> Migrate v5 artifacts to v6 (state, gql, di)
build Run build_runner to generate code from annotations
BOOTSTRAP:
setup <name> Create a new Flutter/Dart app with zuraffa deps wired in
init Alias of initialize — wire deps + scaffold a test entity
CORE COMMANDS:
make <Name> Canonical architecture/code generation command
feature <Name> Wrapper over `make --preset=feature`
initialize Wire zuraffa dependencies + scaffold a test entity
entity Create and manage Zorphy entities
config Manage ZFA configuration
doctor Check your environment and v5 migration readiness
schema Output JSON schema
validate <file> Validate JSON configuration
migrate <target> Migrate v5 artifacts to v6 (state, gql, di)
build Run build_runner to generate code from annotations
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@lib/src/cli/cli_runner.dart` around lines 221 - 235, Update the CORE COMMANDS
help text for the initialize entry to state that init is an alias of initialize,
matching _InitializeCommand’s name and aliases declarations; leave the command
behavior unchanged.

update Check for updates and update the installed CLI

MODULAR COMMANDS:
Expand Down Expand Up @@ -294,11 +301,18 @@ class _InitializeCommand extends Command<void> {
String get name => 'initialize';

@override
String get description => 'Initialize a test entity';
List<String> get aliases => ['init'];

@override
String get description =>
'Wire zuraffa dependencies into pubspec.yaml + scaffold a test entity';

@override
ArgParser get argParser => ArgParser.allowAnything();

@override
Future<void> run() async {
await init.InitializeCommand().execute(argResults!.rest.toList());
await init.InitializeCommand().execute(argResults!.arguments);
}
}

Expand Down
108 changes: 99 additions & 9 deletions lib/src/commands/initialize_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:io';
import 'package:args/args.dart';
import 'package:path/path.dart' as path;
import '../config/zfa_config.dart';
import '../core/dependencies/dependency_wirer.dart';
import '../utils/file_utils.dart';
import '../utils/string_utils.dart';

Expand Down Expand Up @@ -34,6 +35,18 @@ class InitializeCommand {
help: 'Preview what would be generated without writing files',
negatable: false,
)
..addFlag(
'deps-only',
negatable: false,
help:
'Only wire zuraffa dependencies into pubspec.yaml; skip entity scaffolding.',
)
..addFlag(
'no-deps',
negatable: false,
help:
'Skip dependency wiring; only scaffold the test entity (legacy behavior).',
)
..addFlag(
'verbose',
abbr: 'v',
Expand All @@ -53,7 +66,78 @@ class InitializeCommand {
final force = results['force'] as bool;
final dryRun = results['dry-run'] as bool;
final verbose = results['verbose'] as bool;
final depsOnly = results['deps-only'] as bool;
final noDeps = results['no-deps'] as bool;

if (depsOnly && noDeps) {
print('❌ --deps-only and --no-deps are mutually exclusive.');
exit(1);
}

// --- Dependency wiring (issue #275) -----------------------------------
// `zfa init` / `zfa initialize` now wires the standard zuraffa dependency
// set (build_runner, zuraffa[_flutter], zorphy_annotation, analyzer
// override) into pubspec.yaml before scaffolding the test entity. This
// makes the "only zfa commands" contract viable on a fresh project.
if (!noDeps) {
final pubspecFile = File('pubspec.yaml');
if (!pubspecFile.existsSync()) {
print('❌ No pubspec.yaml found in current directory.');
print(
' Run `zfa setup <name>` to create a new app, or cd to a project root.',
);
exit(1);
}

final pubspecContent = pubspecFile.readAsStringSync();
final isFlutter = DependencyWirer.isFlutterProject(pubspecContent);

print('🔧 Wiring zuraffa dependencies'
'${isFlutter ? ' (Flutter project)' : ' (Dart project)'}...\n');
final wireResult = await DependencyWirer.wire(
isFlutter: isFlutter,
dryRun: dryRun,
projectRoot: '.',
);

if (!wireResult.isSuccess) {
print(
'\n⚠️ Some dependencies could not be wired automatically: '
'${wireResult.failed.join(', ')}',
);
print(' Add them manually and re-run `zfa init`.');
}

// Ensure build.yaml + domain directory structure exist.
print('');
await DependencyWirer.ensureProjectStructure(dryRun: dryRun);

// Ensure .zfa.json exists.
final config = ZfaConfig.load();
if (config == null) {
print('');
if (dryRun) {
print('🔍 Would create: .zfa.json (default configuration)');
} else {
await ZfaConfig.init();
}
}
print('');
}

if (depsOnly) {
if (dryRun) {
print('🔍 Dry-run: would skip entity scaffolding (--deps-only).');
} else {
print('✅ Dependencies wired. Skipping entity scaffolding (--deps-only).');
}
print('\n📝 Next steps:');
print(' • Create an entity: zfa entity create -n Product --field id:String');
print(' • Generate feature: zfa make Product --preset=crud --with=vpc,state,di,test');
return;
}

// --- Entity scaffolding (existing behavior) ---------------------------
final entitySnake = StringUtils.camelToSnake(entityName);

// Create entity directory path
Expand Down Expand Up @@ -94,7 +178,7 @@ class InitializeCommand {

void _printHelp(ArgParser parser) {
print('''
Initialize a test entity to quickly try out Zuraffa
Initialize a project for Zuraffa: wire dependencies + scaffold a test entity

USAGE:
zfa initialize [options]
Expand All @@ -104,18 +188,24 @@ OPTIONS:
${parser.usage}

EXAMPLES:
zfa initialize # Generate Product entity
zfa initialize --entity=User # Generate User entity
zfa init -e Order # Generate Order entity
zfa initialize # Wire deps + generate Product entity
zfa init # Same as above (alias)
zfa initialize --entity=User # Wire deps + generate User entity
zfa init --deps-only # Wire deps only, skip entity
zfa init --no-deps -e Order # Skip deps, only scaffold entity
zfa initialize --dry-run # Preview without writing files

DESCRIPTION:
Creates a sample entity with common fields (id, name, description, price, etc.)
under lib/src/domain/entities to help you quickly test Zuraffa's code generation
capabilities.
Wires the standard zuraffa dependency set (build_runner, zuraffa/zuraffa_flutter,
zorphy_annotation, analyzer override) into pubspec.yaml, creates build.yaml with
zorphy builder registration, ensures .zfa.json exists, then creates a sample
entity with common fields under lib/src/domain/entities.

For a brand-new app, prefer `zfa setup <name>` which runs flutter/dart create
AND wires dependencies in one step.

After running this command, use 'zfa make' to create the full Clean Architecture
structure around your entity.
Use --deps-only to wire dependencies without scaffolding an entity.
Use --no-deps to scaffold only the entity (legacy behavior).
''');
}

Expand Down
Loading
Loading