Commit 636eea6

unknown <mkhan@.arcresources.ca>
2009-10-09 14:39:02
working on a regular expression to parse the command line arguments.
1 parent d360fb1
Changed files (4)
product/application/application.csproj
@@ -56,6 +56,7 @@
     <Compile Include="ParameterizedCommand.cs" />
     <Compile Include="Properties\AssemblyInfo.cs" />
     <Compile Include="RunMigrationsCommand.cs" />
+    <Compile Include="StringExtensions.cs" />
   </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
product/application/ConsoleArguments.cs
@@ -1,4 +1,4 @@
-using System;
+using System.Text.RegularExpressions;
 
 namespace simple.migrations
 {
@@ -23,7 +23,29 @@ namespace simple.migrations
 
         public virtual string parse_for(string argument_name)
         {
-            throw new NotImplementedException();
+            return
+                new Regex(@"^-{0}:\'[A-Za-z0-9\]\'$".format_using(argument_name), RegexOptions.Singleline)
+                .Match( arguments[0]).Value;
+        }
+
+        public bool Equals(ConsoleArguments other)
+        {
+            if (ReferenceEquals(null, other)) return false;
+            if (ReferenceEquals(this, other)) return true;
+            return Equals(other.arguments, arguments);
+        }
+
+        public override bool Equals(object obj)
+        {
+            if (ReferenceEquals(null, obj)) return false;
+            if (ReferenceEquals(this, obj)) return true;
+            if (obj.GetType() != typeof (ConsoleArguments)) return false;
+            return Equals((ConsoleArguments) obj);
+        }
+
+        public override int GetHashCode()
+        {
+            return (arguments != null ? arguments.GetHashCode() : 0);
         }
     }
 }
\ No newline at end of file
product/application/StringExtensions.cs
@@ -0,0 +1,10 @@
+namespace simple.migrations
+{
+    public static class StringExtensions
+    {
+        public static string format_using(this string formatted_string, params object[] arguments)
+        {
+            return string.Format(formatted_string, arguments);
+        }
+    }
+}
\ No newline at end of file
product/application.tests/ConsoleSpecs.cs
@@ -17,9 +17,6 @@ namespace tests
 
         public class when_processing_a_new_request : concern
         {
-            it should_run_the_command_that_can_handle_the_request =
-                () => { correct_command.received(x => x.run_against(console_arguments)); };
-
             context c = () =>
                             {
                                 console_arguments = new[] {""};
@@ -29,6 +26,9 @@ namespace tests
 
             because b = () => { controller.sut.run_against(console_arguments); };
 
+            it should_run_the_command_that_can_handle_the_request =
+                () => { correct_command.received(x => x.run_against(console_arguments)); };
+
             static string[] console_arguments;
             static ParameterizedCommand<ConsoleArguments> correct_command;
         }