createFromArguments function
Using the flags set in the terminal and the provided information in the yaml file create the requested information
Implementation
Future<void> createFromArguments(List<String> arguments) async {
final ArgParser parser = ArgParser(allowTrailingOptions: true);
parser
..addFlag(
prefixOptions[1],
abbr: 'h',
help: 'Usage help',
negatable: false
)
// Make default null to differentiate when it is explicitly set
..addOption(
prefixOptions[0],
abbr: 'p',
help: 'Path to yaml file',
defaultsTo: '$defaultConfigFile or pubspec.yaml',
)
..addFlag(
prefixOptions[2],
abbr: 'v',
help: 'Verbose output',
defaultsTo: false
)
..addOption(
prefixOptions[7],
abbr: 'e',
help: 'Path to export zip files.',
defaultsTo: '.',
)
..addFlag(
prefixOptions[19],
abbr: 'm',
help: 'Merge hex files.',
defaultsTo: false,
)
..addFlag(
prefixOptions[11],
help: 'Debug Mode.',
defaultsTo: false,
)
..addFlag(
prefixOptions[14],
help: 'Generate new key file.',
defaultsTo: false
)
..addFlag(
prefixOptions[18],
help: 'Generate Settings.',
defaultsTo: false,
);
// ..addOption(
// prefixOptions[3],
// help: 'Generates public and private keys for signing dfu.',
// defaultsTo: '.',
// )
// ..addOption(
// prefixOptions[4],
// help: 'Path to application hex file.',
// )
// ..addOption(
// prefixOptions[6],
// help: 'Path to softdevice hex file.',
// )
// ..addOption(
// prefixOptions[5],
// help: 'Path to bootloader hex file.',
// )
// ..addOption(
// prefixOptions[8],
// help: 'Application Version.',
// defaultsTo: '0xffffff',
// )
// ..addOption(
// prefixOptions[9],
// help: 'Bootloader Version.',
// defaultsTo: '0xffffff',
// )
// ..addOption(
// prefixOptions[10],
// help: 'Softdevice Version.',
// defaultsTo: '0xffffff',
// )
// ..addOption(
// prefixOptions[12],
// help: 'Comment',
// )
// ..addOption(
// prefixOptions[13],
// help: 'Softdevice Type.',
// )
// ..addOption(
// prefixOptions[15],
// help: 'Public Key file.',
// )
// ..addOption(
// prefixOptions[16],
// help: 'Private Key file.',
// )
// ..addOption(
// prefixOptions[17],
// help: 'Hardware Version.',
// defaultsTo: '0xffffff',
// )
final ArgResults argResults = parser.parse(arguments);
final bool isVerbose = argResults[prefixOptions[2]];
logger = NRFLogger(isVerbose);
logger?.verbose('Received args ${argResults.arguments}');
if (argResults[prefixOptions[1]]) {
stdout.writeln('Generates dfu files for nRF51 and nRF52 devices');
stdout.writeln(parser.usage);
exit(0);
}
final String prefixPath = argResults[prefixOptions[0]];
// Load configs from given file(defaults to ./nrfutil.yaml) or from ./pubspec.yaml
Config? flutterLauncherIconsConfigs;
// if(
// argResults[prefixOptions[4]] != null ||
// argResults[prefixOptions[5]] != null ||
// argResults[prefixOptions[6]] != null ||
// argResults[prefixOptions[14]]
// ){
// flutterLauncherIconsConfigs = loadConfigFileFromArgResults(argResults);
// }
// else{
flutterLauncherIconsConfigs = loadConfigFileFromYaml(prefixPath);
// }
if (flutterLauncherIconsConfigs == null) {
throw NoConfigFoundException(
'No configuration found in $defaultConfigFile or in ${constants.pubspecFilePath}. '
'In case file exists in different directory use --file option',
);
}
try {
await createFromConfig(
flutterLauncherIconsConfigs,
argResults[prefixOptions[18]],
argResults[prefixOptions[19]]
);
stdout.writeln('\n✓ Successfully generated nrf files');
exit(0);
} catch (e) {
stderr.writeln('\n✕ Could not generate nrf files');
stderr.writeln(e);
exit(2);
}
}