From 260eac0dfa6d67588060f0cf7aec110969cec55c Mon Sep 17 00:00:00 2001 From: olabini Date: Mon, 14 Jan 2008 11:48:29 +0000 Subject: [PATCH] Fix for JRUBY-1947, support -C git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@5601 961051c9-f516-0410-bf72-c9f7e237a7b7 --- src/org/jruby/RubyInstanceConfig.java | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/org/jruby/RubyInstanceConfig.java b/src/org/jruby/RubyInstanceConfig.java index 69a770981..1cfd6e746 100644 --- a/src/org/jruby/RubyInstanceConfig.java +++ b/src/org/jruby/RubyInstanceConfig.java @@ -229,7 +229,7 @@ public class RubyInstanceConfig { .append(" -a autosplit mode with -n or -p (splits $_ into $F)\n") .append(" -b benchmark mode, times the script execution\n") .append(" -c check syntax only\n") - //.append(" -Cdirectory cd to directory, before executing your script\n") + .append(" -Cdirectory cd to directory, before executing your script\n") .append(" -d set debugging flags (set $DEBUG to true)\n") .append(" -e 'command' one line of script. Several -e's allowed. Omit [programfile]\n") .append(" -Fpattern split() pattern for autosplit (-a)\n") @@ -538,9 +538,27 @@ public class RubyInstanceConfig { case 'c' : shouldCheckSyntax = true; break; - // FIXME: -C flag not supported -// case 'C' : -// break; + case 'C' : + try { + String saved = grabValue(getArgumentError(" -C must be followed by a directory expression")); + File base = new File(currentDirectory); + File newDir = new File(saved); + if(newDir.isAbsolute()) { + currentDirectory = newDir.getCanonicalPath(); + } else { + currentDirectory = new File(base, newDir.getPath()).getCanonicalPath(); + } + if(!(new File(currentDirectory).isDirectory())) { + MainExitException mee = new MainExitException(1, "jruby: Can't chdir to " + saved + " (fatal)"); + mee.setUsageError(true); + throw mee; + } + } catch(IOException e) { + MainExitException mee = new MainExitException(1, getArgumentError(" -C must be followed by a valid directory")); + mee.setUsageError(true); + throw mee; + } + break; case 'd' : debug = true; verbose = true; -- 2.11.4.GIT