[Ngms-svn] SVN-Commit: [96] [NMShell] create new command

Back to archive index

svnno****@sourc***** svnno****@sourc*****
2010年 1月 27日 (水) 20:25:49 JST


Revision: 96
          http://sourceforge.jp/projects/ngms/svn/view?view=rev&revision=96
Author:   takayah
Date:     2010-01-27 20:25:49 +0900 (Wed, 27 Jan 2010)

Log Message:
-----------
[NMShell] create new command

Added Paths:
-----------
    trunk/source/NMShell/src/info/ngms/commands/echo.scala
    trunk/source/NMShell/src/info/ngms/commands/mkdir.scala
    trunk/source/NMShell/src/info/ngms/commands/rm.scala
    trunk/source/NMShell/src/info/ngms/commands/touch.scala

Added: trunk/source/NMShell/src/info/ngms/commands/echo.scala
===================================================================
--- trunk/source/NMShell/src/info/ngms/commands/echo.scala	                        (rev 0)
+++ trunk/source/NMShell/src/info/ngms/commands/echo.scala	2010-01-27 11:25:49 UTC (rev 96)
@@ -0,0 +1,37 @@
+/*
+ *  Next Generation Management System Project
+ *  Copyright(c) 2009, NGMS Project Team All Rights Reserved.
+ */
+package info.ngms.commands
+
+import info.ngms.nmshell.NMCommand
+import info.ngms.nmshell.NMCommandContext
+import info.ngms.nmshell.NMCommandStream
+import info.ngms.nmshell.NMCommandStreamKind
+import info.ngms.nmshell.NMCommandParameterInfo
+import info.ngms.nmshell.NMRawStream
+import info.ngms.nmshell.RawStream
+import info.ngms.nmshell.NMShellEnvironment
+import info.ngms.nmtree.NMTreeElements
+
+class echo extends NMCommand {
+    val name = "echo"
+
+    private var arguments : Array[String] = null
+
+    def parseOption( args : Array[String] ) : Unit = {
+        arguments = args
+    }
+
+    def parameters : List[ NMCommandParameterInfo ] = {
+        Nil
+    }
+
+    def doWork( env : NMCommandContext ) : Unit = {
+        arguments foreach { arg => print(env, arg + " ") }
+        print(env, "\n")
+    }
+
+    def inputStreamKind  = RawStream()
+    def outputStreamKind = RawStream()
+}

Added: trunk/source/NMShell/src/info/ngms/commands/mkdir.scala
===================================================================
--- trunk/source/NMShell/src/info/ngms/commands/mkdir.scala	                        (rev 0)
+++ trunk/source/NMShell/src/info/ngms/commands/mkdir.scala	2010-01-27 11:25:49 UTC (rev 96)
@@ -0,0 +1,45 @@
+/*
+ *  Next Generation Management System Project
+ *  Copyright(c) 2009, NGMS Project Team All Rights Reserved.
+ */
+package info.ngms.commands
+
+import info.ngms.nmshell.NMCommand
+import info.ngms.nmshell.NMCommandContext
+import info.ngms.nmshell.NMCommandStream
+import info.ngms.nmshell.NMCommandStreamKind
+import info.ngms.nmshell.NMCommandParameterInfo
+import info.ngms.nmshell.NMRawStream
+import info.ngms.nmshell.RawStream
+import info.ngms.nmshell.NMShellEnvironment
+import info.ngms.nmtree.NMTree
+import info.ngms.nmtree.NMPath
+import info.ngms.nmtree.NMTreeElements
+
+class mkdir extends NMCommand {
+    val name = "mkdir"
+
+    private var targetDirnames : Option[Array[String]] = None
+
+    def parseOption( args : Array[String] ) : Unit = {
+        if (args.length > 0) targetDirnames = Some(args)
+    }
+
+    def parameters : List[ NMCommandParameterInfo ] = {
+        Nil
+    }
+
+    def doWork( env : NMCommandContext ) : Unit = {
+        val current = NMShellEnvironment.currentPath
+        targetDirnames match {
+            case Some(names) =>
+                names foreach { name =>
+                    NMTree.createDir(current.concat(name))
+                }
+            case None => print_err(env, "no enough arguments\n")
+        }
+    }
+
+    def inputStreamKind  = RawStream()
+    def outputStreamKind = RawStream()
+}

Added: trunk/source/NMShell/src/info/ngms/commands/rm.scala
===================================================================
--- trunk/source/NMShell/src/info/ngms/commands/rm.scala	                        (rev 0)
+++ trunk/source/NMShell/src/info/ngms/commands/rm.scala	2010-01-27 11:25:49 UTC (rev 96)
@@ -0,0 +1,57 @@
+/*
+ *  Next Generation Management System Project
+ *  Copyright(c) 2009, NGMS Project Team All Rights Reserved.
+ */
+package info.ngms.commands
+
+import info.ngms.nmshell.NMCommand
+import info.ngms.nmshell.NMCommandContext
+import info.ngms.nmshell.NMCommandStream
+import info.ngms.nmshell.NMCommandStreamKind
+import info.ngms.nmshell.NMCommandParameterInfo
+import info.ngms.nmshell.NMRawStream
+import info.ngms.nmshell.RawStream
+import info.ngms.nmshell.NMShellEnvironment
+import info.ngms.nmtree.NMTree
+import info.ngms.nmtree.NMPath
+import info.ngms.nmtree.Delete
+import info.ngms.nmtree.NMTreeElements
+
+
+class rm extends NMCommand {
+    val name = "rm"
+
+    private case class RmArg(name : String, recursive : Boolean)
+    private var rmArgs : List[RmArg] = Nil
+
+    def parseOption( args : Array[String] ) : Unit = {
+        var recursive = false
+        for (arg <- args) {
+            if (arg equals "-r") {
+                recursive = true
+            } else {
+                rmArgs = RmArg(arg, recursive) :: rmArgs
+            }
+        }
+        rmArgs = rmArgs.reverse
+    }
+
+    def parameters : List[ NMCommandParameterInfo ] = {
+        Nil
+    }
+
+    def doWork( env : NMCommandContext ) : Unit = {
+        val current = NMShellEnvironment.currentPath
+        if (rmArgs == Nil) {
+            print_err(env, "not enouch arguments\n")
+        } else {
+            val ops = rmArgs map { rmArg =>
+                            Delete(current.concat(rmArg.name), rmArg.recursive)
+                        }
+            NMTree.localCommit(ops)
+        }
+    }
+
+    def inputStreamKind  = RawStream()
+    def outputStreamKind = RawStream()
+}

Added: trunk/source/NMShell/src/info/ngms/commands/touch.scala
===================================================================
--- trunk/source/NMShell/src/info/ngms/commands/touch.scala	                        (rev 0)
+++ trunk/source/NMShell/src/info/ngms/commands/touch.scala	2010-01-27 11:25:49 UTC (rev 96)
@@ -0,0 +1,48 @@
+/*
+ *  Next Generation Management System Project
+ *  Copyright(c) 2009, NGMS Project Team All Rights Reserved.
+ */
+package info.ngms.commands
+
+import info.ngms.nmshell.NMCommand
+import info.ngms.nmshell.NMCommandContext
+import info.ngms.nmshell.NMCommandStream
+import info.ngms.nmshell.NMCommandStreamKind
+import info.ngms.nmshell.NMCommandParameterInfo
+import info.ngms.nmshell.NMRawStream
+import info.ngms.nmshell.RawStream
+import info.ngms.nmshell.NMShellEnvironment
+import info.ngms.nmtree.NMTree
+import info.ngms.nmtree.NMPath
+import info.ngms.nmtree.NMTreeElements
+
+/**
+ * file を生成するだけの touch
+ */
+class touch extends NMCommand {
+    val name = "touch"
+
+    private var fileNames : Option[Array[String]] = None
+
+    def parseOption( args : Array[String] ) : Unit = {
+        if (args.length > 0) fileNames = Some(args)
+    }
+
+    def parameters : List[ NMCommandParameterInfo ] = {
+        Nil
+    }
+
+    def doWork( env : NMCommandContext ) : Unit = {
+        val current = NMShellEnvironment.currentPath
+        fileNames match {
+            case Some(names) =>
+                names foreach { name =>
+                    NMTree.createStream(current.concat(name))
+                }
+            case None => print_err(env, "missing file operand\n")
+        }
+    }
+
+    def inputStreamKind  = RawStream()
+    def outputStreamKind = RawStream()
+}




Ngms-svn メーリングリストの案内
Back to archive index