LibAC-dart/lib/argparse/CLIHelper.dart

51 lines
1.8 KiB
Dart

import 'package:libac_dart/argparse/Args.dart';
class ArgumentHelpers {
/// Generates a command-line help message for the provided arguments.
///
/// [arguments] The list of arguments to generate help for.
/// [programName] The name of the program.
/// Returns a string containing the help message.
static String generateHelpMessage(
List<Argument<dynamic>> arguments, String programName) {
final StringBuffer helpMessage = StringBuffer();
helpMessage.writeln('Usage: $programName [options]');
for (var arg in arguments) {
final description = _getArgumentDescription(arg);
final valueType = arg.getType().toString();
helpMessage.writeln(
' --${arg.name} [${valueType.split('.').last}] $description');
}
return helpMessage.toString();
}
/// Gets a description for an argument. This can be extended to provide more info.
///
/// [argument] The argument for which to generate a description.
/// Returns a description of the argument.
static String _getArgumentDescription(Argument<dynamic> argument) {
// You can extend this to add more detailed descriptions for specific arguments
return argument.hasValue()
? 'Default value: ${argument.getValue()}'
: 'No default value assigned';
}
/// Retrieves the type of an argument in a human-readable format.
///
/// [argument] The argument to get the type for.
/// Returns a string describing the argument type.
static String _getArgumentType(Argument<dynamic> argument) {
switch (argument.getType()) {
case ArgumentType.STRING:
return 'string';
case ArgumentType.INTEGER:
return 'integer';
case ArgumentType.BOOL:
return 'boolean';
case ArgumentType.DOUBLE:
return 'double';
}
}
}