PageConfig.fromArguments constructor

PageConfig.fromArguments(
  1. ArgResults? argResults
)

Creates a PageConfig from command arguments.

This factory constructor processes command-line arguments and creates a validated PageConfig object with all necessary parameters.

Parameters:

  • argResults: The parsed command-line arguments

Implementation

factory PageConfig.fromArguments(ArgResults? argResults) {
  final appsName = (argResults?['apps-name'] as String? ?? '').snakeCase;
  final pathApps = join(current, 'apps', appsName);
  String featureName =
      (argResults?['feature-name'] as String? ?? '').snakeCase;
  final pageName = (argResults?.rest.first ?? '').snakeCase;

  // Adjust feature name if apps context is provided
  if (appsName.isNotEmpty && !RegExp('^${appsName}_').hasMatch(featureName)) {
    featureName = '${appsName}_$featureName';
  }

  String pathFeature = join(current, 'features', featureName);
  if (appsName.isNotEmpty) {
    pathFeature = join(pathApps, 'features', featureName);
  }

  final className = pageName.pascalCase;
  final methodName = pageName.camelCase;

  return PageConfig(
    appsName: appsName,
    pathApps: pathApps,
    featureName: featureName,
    pageName: pageName,
    pathFeature: pathFeature,
    pathPage: join(pathFeature, 'lib', pageName),
    className: className,
    methodName: methodName,
  );
}