run method
Runs this command.
The return value is wrapped in a Future if necessary and returned by
CommandRunner.runCommand.
Implementation
@override
void run() async {
final args = argResults!.rest;
if (args.length < 3) {
print('Usage: \n nexon add <methodName> in <feature> \n nexon add <httpMethod> <methodName> in <feature>');
return;
}
String httpMethod = 'get';
late String methodName;
late String feature;
if (args.length >= 4 && args[2] == 'in') {
httpMethod = args[0].toLowerCase();
methodName = args[1];
feature = args[3];
} else if (args[1] == 'in') {
methodName = args[0];
feature = args[2];
} else {
print('Usage: \n nexon add <methodName> in <feature> \n nexon add <httpMethod> <methodName> in <feature>');
return;
}
print('🧩 Adding method $methodName to $feature feature.');
stdout.write(httpMethod == 'post' || httpMethod == 'postmultipart'
? 'Paste payload JSON (or leave empty): '
: 'Paste model JSON (or leave empty): ');
final modelJson = stdin.readLineSync();
stdout.write('Model class name: ');
final modelName = stdin.readLineSync();
stdout.write('Custom query class name (leave empty for default): ');
final queryClassName = stdin.readLineSync();
stdout.write('Paste query JSON fields (or leave empty): ');
final queryJson = stdin.readLineSync();
stdout.write('Has pagination? (y/n): ');
final hasPagination = stdin.readLineSync()?.toLowerCase() == 'y';
stdout.write('Should store response? (y/n): ');
final shouldStore = stdin.readLineSync()?.toLowerCase() == 'y';
generateMethodCode(
feature,
httpMethod,
methodName,
modelName ?? '',
hasPagination,
shouldStore,
modelJson,
queryClassName,
queryJson,
);
}