@@ -11,7 +11,7 @@ import java.io.{ BufferedReader, FileReader }
1111import java .util .concurrent .locks .ReentrantLock
1212import scala .sys .process .Process
1313import session ._
14- import scala .tools .util .{ Signallable , Javap }
14+ import scala .tools .util .{ Signallable , Javap , StringOps }
1515import scala .annotation .tailrec
1616import scala .collection .mutable .ListBuffer
1717import scala .concurrent .ops
@@ -591,31 +591,31 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
591591 }
592592 }
593593
594- def withFile (filename : String )(action : File => Unit ) {
595- val f = File (filename)
594+ def smartPath (path : String ) = if (File (path).exists) path else path.trim
595+
596+ def withPath (path : String )(action : File => Unit ) {
597+ val f = File (path)
596598
597599 if (f.exists) action(f)
598- else echo(" That file does not exist" )
600+ else echo(" The path ' " + f + " ' doesn't seem to exist. " )
599601 }
600602
601603 def loadCommand (arg : String ) = {
602604 var shouldReplay : Option [String ] = None
603- withFile( arg)(f => {
605+ withPath(smartPath( arg) )(f => {
604606 interpretAllFrom(f)
605607 shouldReplay = Some (" :load " + arg)
606608 })
607609 Result (true , shouldReplay)
608610 }
609611
610612 def addClasspath (arg : String ): Unit = {
611- val f = File (arg).normalize
612- if (f.exists) {
613+ withPath(File (arg).normalize.path)(f => {
613614 addedClasspath = ClassPath .join(addedClasspath, f.path)
614615 val totalClasspath = ClassPath .join(settings.classpath.value, addedClasspath)
615616 echo(" Added '%s'. Your new classpath is:\n\" %s\" " .format(f.path, totalClasspath))
616617 replay()
617- }
618- else echo(" The path '" + f + " ' doesn't seem to exist." )
618+ })
619619 }
620620
621621 def powerCmd (): Result = {
@@ -641,9 +641,10 @@ class ILoop(in0: Option[BufferedReader], protected val out: JPrintWriter)
641641 * if any. */
642642 def command (line : String ): Result = {
643643 if (line startsWith " :" ) {
644- val cmd = line.tail takeWhile (x => ! x.isWhitespace)
644+ val lineNoColon = line.tail
645+ val (cmd, arg) = StringOps .splitLeft(lineNoColon, ' ' ).getOrElse((lineNoColon, " " ))
645646 uniqueCommand(cmd) match {
646- case Some (lc) => lc(line.tail stripPrefix cmd dropWhile (_.isWhitespace) )
647+ case Some (lc) => lc(arg )
647648 case _ => ambiguousError(cmd)
648649 }
649650 }
0 commit comments