Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
Add --help and --version options
Browse files Browse the repository at this point in the history
To get --help you need to use -- --help because of
ceylon/ceylon-common#38.
  • Loading branch information
lucaswerkmeister committed Apr 24, 2014
1 parent f7cc4dc commit 14a9d73
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions source/ceylon/formatter/options/formattingOptions.ceylon
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,60 @@ Map<String,Anything(VariableOptions)> presets = HashMap {
};

shared [FormattingOptions, String[]] commandLineOptions(String[] arguments = process.arguments) {
// first of all, the special cases --help and --version, which both cause exiting
if (arguments.contains("--help")) {
print(
"ceylon.formatter – a Ceylon module / program to format Ceylon source code.
USAGE
ceylon run ceylon.formatter source
or, if you’re worried about it breaking your source code (which shouldn’t happen –
if anything bad happens, error recovery kicks in and the original file is destroyed)
or you just want to test it out:
ceylon run ceylon.formatter source --to source-formatted
You can also format multiple folders at the same time:
ceylon run ceylon.formatter source --and test-source --to formatted
which will recreate the ‘source’ and ‘test-source’ folders inside the new ‘formatted’ folder.
OPTIONS
--help
Print this help message.
--version
Print version information. The first line is always just the module name and version
in the format that ‘ceylon run’ understands (“ceylon.formatter/x.y.z”), which might be
useful for scripts.
--${option name}=${option value}
Set a formatting option. See the documentation of the FormattingOptions class for a list of
options. The most useful ones are:
--maxLineLength
The maximum line length, or “unlimited”.
--indentMode
The indentation mode. Syntax: “x spaces” or “y-wide tabs” or “mix x-wide tabs, y spaces”.
--lineBreak
“lf”, “crlf”, or “os” for the operating system’s native line breaks."
);
process.exit(0);
} else if (arguments.contains("--version")) {
print(
"`` `module ceylon.formatter`.name ``/`` `module ceylon.formatter`.version ``
Copyright 2014 Lucas Werkmeister
Licensed under the Apache License, Version 2.0."
);
process.exit(0);
}

variable FormattingOptions baseOptions = configOptions();

String[] splitArguments = concatenate(*arguments.map((String s) {
Expand Down

0 comments on commit 14a9d73

Please sign in to comment.