Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Tweaks for command line tool

  • Loading branch information...
commit cb9b2adb3d61b3269ba6b8f97ac717022b1a6e65 1 parent 87529c1
@mdr authored
View
53 README.rst
@@ -1,26 +1,27 @@
Scalariform
===========
-Scalariform is a code formatter for Scala 2.8. It is a stand-alone
-library and an Eclipse plug-in. Currently, Scalariform supports only a
-limited set of options, although it is intended to be compatible with
-the recommendations of the `Scala Style Guide`_ (see below). Please
-let me know what other features people would like.
+Scalariform is a code formatter for Scala 2.8. It is both a
+stand-alone command line tool / library and an Eclipse
+plug-in. Currently, Scalariform supports only a limited set of
+options, although it is intended to be compatible with the
+recommendations of the `Scala Style Guide`_ (see below). Please let me
+know what other features people would like.
Scalariform is licenced under `The MIT Licence`_.
.. _Scala Style Guide: http://davetron5000.github.com/scala-style/
.. _The MIT Licence: http://www.opensource.org/licenses/mit-license.php
-Installation
-------------
+Installation in Eclipse
+-----------------------
-In Eclipse 3.5, install the latest nightly Scala Eclipse plugin using
-the update site mechanism:
+In Eclipse 3.5, install the latest nightly build of Scala IDE for
+Eclipse using the update site mechanism:
http://download.scala-ide.org/nightly-update-master-trunk
-(See http://www.scala-lang.org/node/94 for more detailed instructions.)
+(See http://www.assembla.com/wiki/show/scala-ide/Requirements_and_Installation for more detailed instructions.)
Then install Scalariform from this update site:
@@ -33,6 +34,38 @@ To format:
To configure preferences, go to Window -> Preferences -> Scala -> Scala Formatter Preferences
+Command line tool
+-----------------
+
+Scalariform can be used as a stand-alone command line utility. Sample script::
+
+ #!/bin/bash
+ scala -cp /path/to/scalariform-X.Y.Z.jar scalariform.commandline.Main "$@"
+
+Usage::
+
+ scalariform [options] [files...]
+
+ Options:
+ --help, -h Show help
+ --inPlace, -i Replace the input file(s) in place with a formatted version.
+ --test, -t Check the input(s) to see if they are correctly formatted, return a non-zero error code if not.
+ --verbose -v Verbose output
+
+ Preferences:
+ [+|-]alignParameters Enable/disable Align parameters on different lines in the same column
+ [+|-]compactStringConcatenation Enable/disable Omit spaces when formatting a '+' operator on String literals
+ [+|-]doubleIndentClassDeclaration Enable/disable Double indent either a class's parameters or its inheritance list
+ -indentSpaces=[1-10] Set Number of spaces to use for indentation
+ [+|-]preserveSpaceBeforeArguments Enable/disable Preserve a space before a parenthesis argument
+ [+|-]rewriteArrowSymbols Enable/disable Replace arrow tokens with unicode equivalents: => with ⇒, and <- with ←
+ [+|-]spaceBeforeColon Enable/disable Add a space before colons
+
+ Examples:
+ scalariform +spaceBeforeColon -alignParameters -indentSpaces=2 --inPlace foo.scala
+ find . -name '*.scala' | xargs scalariform +rewriteArrowSymbols --verbose --test
+ echo 'class A ( n :Int )' | scalariform
+
Preferences
-----------
View
2  ...orm/commandline/CommandOptionParser.scala → ...commandline/CommandLineOptionParser.scala
@@ -13,7 +13,7 @@ class CommandLineOptionParser extends JavaTokenParsers with RegexParsers {
lazy val verbose = ("--verbose" | "-v") ^^^ Verbose
- lazy val help = ("--help" | "-h" | "-help") ^^^ Help
+ lazy val help = ("--help" | "-help" | "-h") ^^^ Help
lazy val toggle = plusOrMinus ~ ident ^^ { case onOrOff ~ key PreferenceOption(key, onOrOff.toString) }
View
59 core/src/main/scala/scalariform/commandline/Main.scala
@@ -14,32 +14,7 @@ object Main {
val arguments = args.toList map parser.getArgument
if (arguments contains Help) {
- println("Usage: scalariform [options] [files...]")
- println()
- println("Options:")
- println(" --help, -h Show help")
- println(" --inPlace, -i Replace the input file(s) in place with a formatted version.")
- println(" --test, -t Check the input(s) to see if they are correctly formatted, return a non-zero error code if not.")
- println(" --verbose -v Verbose output")
- println()
- println("Preferences:")
- for (key AllPreferences.preferencesByKey.keySet.toList.sorted) {
- def handlePreference[T](preference: PreferenceDescriptor[T]) {
- preference.preferenceType match {
- case BooleanPreference
- val filler = " " * (30 - key.length)
- println(" [+|-]" + key + filler + "Enable/disable " + preference.description)
- case IntegerPreference(min, max)
- val filler = " " * (28 - key.length)
- println(" " + key + "=[" + min + "-" + max + "]" + filler + "Set " + preference.description)
- }
- }
- handlePreference(AllPreferences.preferencesByKey(key))
- }
- println()
- println("Examples:")
- println(" scalariform +spaceBeforeColon -indentSpaces=2 --inPlace foo.scala")
- println(" find . -name '*.scala' | xargs scalariform +rewriteArrowSymbols --verbose --test")
+ printUsage()
System.exit(0)
}
@@ -141,4 +116,36 @@ object Main {
}
}
+ private def printUsage() {
+ println("Usage: scalariform [options] [files...]")
+ println()
+ println("Options:")
+ println(" --help, -h Show help")
+ println(" --inPlace, -i Replace the input file(s) in place with a formatted version.")
+ println(" --test, -t Check the input(s) to see if they are correctly formatted, return a non-zero error code if not.")
+ println(" --verbose -v Verbose output")
+ println()
+ println("Preferences:")
+ for (key AllPreferences.preferencesByKey.keySet.toList.sorted) {
+ def handlePreference[T](preference: PreferenceDescriptor[T]) {
+ preference.preferenceType match {
+ case BooleanPreference
+ val optionText = " [+|-]" + key
+ val filler = " " * (38 - optionText.length)
+ println(optionText + filler + "Enable/disable " + preference.description)
+ case IntegerPreference(min, max)
+ val optionText = " -" + key + "=[" + min + "-" + max + "]"
+ val filler = " " * (38 - optionText.length)
+ println(optionText + filler + "Set " + preference.description)
+ }
+ }
+ handlePreference(AllPreferences.preferencesByKey(key))
+ }
+ println()
+ println("Examples:")
+ println(" scalariform +spaceBeforeColon -alignParameters -indentSpaces=2 --inPlace foo.scala")
+ println(" find . -name '*.scala' | xargs scalariform +rewriteArrowSymbols --verbose --test")
+ println(" echo 'class A ( n :Int )' | scalariform")
+ }
+
}
Please sign in to comment.
Something went wrong with that request. Please try again.