Arguments.fromArgResults constructor

Arguments.fromArgResults(
  1. ArgResults results,
  2. ArgResults? globalResults
)

Factory constructor creating Arguments from command-line results.

Parses command-line argument results and global configuration to create a fully configured Arguments instance for custom build execution. This factory handles type conversion, default value application, and argument validation for all supported build parameters.

Parameters

  • results - Parsed command-line arguments specific to custom build
  • globalResults - Global CLI configuration and environment settings

Returns

Returns a configured Arguments instance with:

  • All command-line arguments properly parsed and typed
  • Default values applied where arguments not specified
  • Global configuration integrated with local arguments
  • Custom arguments split and processed into list format
  • Output path resolved with fallback to default directory

Argument Processing

The factory performs several processing steps:

  • String arguments extracted with proper type casting
  • Custom arguments string split on spaces into argument list
  • Build number converted to string representation
  • Output path resolved with default fallback
  • Boolean flags processed with default value support
  • Rest arguments used for build source directory specification

Example

// CLI: flutter distribute build custom --binary-type aab --arguments "--verbose"
final args = Arguments.fromArgResults(argResults, globalResults);

// Result configuration:
// - binaryType: 'aab'
// - customArgs: ['--verbose']
// - buildMode: 'release' (default)
// - pub: true (default)

Implementation

factory Arguments.fromArgResults(
  ArgResults results,
  ArgResults? globalResults,
) {
  return Arguments(
    Variables.fromSystem(globalResults),
    binaryType: results['binary-type'] as String,
    buildMode: results['build-mode'] as String?,
    target: results['target'] as String?,
    flavor: results['flavor'] as String?,
    dartDefines: results['dart-defines'] as String?,
    dartDefinesFile: results['dart-defines-file'] as String?,
    buildName: results['build-name'] as String?,
    buildNumber: results['build-number']?.toString(),
    pub: results['pub'] as bool? ?? true,
    customArgs: results['arguments']?.split(' ') as List<String>?,
    output: results['output'] as String? ?? Files.customOutputDir.path,
    buildSourceDir: results.rest.firstOrNull ?? Files.customOutputDir.path,
  );
}