ArgParser Dart
Version vom 28. August 2022, 13:33 Uhr von Hamatoma (Diskussion | Beiträge) (Die Seite wurde neu angelegt: „= Links = * Dart = Standard = <syntaxhighlight lang=dart> void usage(String message, ArgParser parser) { log(''' Usage: scrambler <command> <args_and_op…“)
Links[Bearbeiten]
Standard[Bearbeiten]
void usage(String message, ArgParser parser) {
log('''
Usage: scrambler <command> <args_and_opts>'
Modifies source code.''');
log(parser.usage);
log('''
scrambler codepoints <text1> [<text2> ...]
Shows the codepoints of <textN>.''');
log(parser.commands['codepoints']!.usage);
log('''
scrambler shuffle <input> <output>
Reorders source code from file <input> into file <output>.''');
log(parser.commands['shuffle']!.usage);
error(message);
exit(1);
}
void main(List<String> args) {
final parser = ArgParser();
//M1
parser.addFlag(
'verbose',
abbr: 'v',
help: 'shows more information',
);
final codepointParser = ArgParser();
final shuffleParser = ArgParser();
parser.addCommand('codepoints', codepointParser);
parser.addCommand('shuffle', shuffleParser);
shuffleParser.addFlag(
'reverse',
abbr: 'h',
help: 'Sorts ranges in reverse order (for testing).',
);
final results = parser.parse(args);
if (results.command == null) {
usage('missing <command>', parser);
}
final mode = results.command!.name!;
if ('codepoints'.startsWith(mode)) {
codepoints(results.command!, parser);
} else if ('decode'.startsWith(mode)) {
...
}
}