cleanup to bin/markdown.dart
diff --git a/pkgs/markdown/bin/markdown.dart b/pkgs/markdown/bin/markdown.dart index 0df8040..fb6a460 100644 --- a/pkgs/markdown/bin/markdown.dart +++ b/pkgs/markdown/bin/markdown.dart
@@ -6,30 +6,14 @@ Future main(List<String> args) async { if (args.length > 1) { print('Usage: markdown.dart [file]'); - exit(1); + exitCode = 1; + return; } if (args.length == 1) { - var arg = args.first; - if (arg == '--help') usage(); - if (arg == '--version') { - print(version); - exit(0); - } - // Read argument as a file path. - print(markdownToHtml(new File(args[0]).readAsStringSync())); - exit(0); - } - - // Read from stdin. - var buffer = new StringBuffer(); - var line; - while ((line = stdin.readLineSync()) != null) buffer.writeln(line); - print(markdownToHtml(buffer.toString())); -} - -void usage() { - print('''Usage: + switch (args.first) { + case '--help': + print('''Usage: markdown [markdown file] Convert [markdown-file] from Markdown to HTML. If no file is passed on the commandline, then the Markdown source is read from STDIN. @@ -40,5 +24,24 @@ markdown --help Print this help text. '''); - exit(0); + return; + + case '--version': + print(version); + return; + + default: + // Read argument as a file path. + print(markdownToHtml(new File(args[0]).readAsStringSync())); + return; + } + } + + // Read from stdin. + var buffer = new StringBuffer(); + String line; + while ((line = stdin.readLineSync()) != null) { + buffer.writeln(line); + } + print(markdownToHtml(buffer.toString())); }