Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Gerwitz <mike@mikegerwitz.com>2011-10-02 23:18:32 -0400
committerMike Gerwitz <mike@mikegerwitz.com>2011-10-02 23:18:32 -0400
commit1bd9246f87fcd60e19093331e13fe0f7031643dc (patch)
tree869cfc8187b21dbfcfe2e085716d2aebb0a1138d
parent56175579def599f624d404c801046e424518d868 (diff)
downloadgsgp-1bd9246f87fcd60e19093331e13fe0f7031643dc.tar.gz
gsgp-1bd9246f87fcd60e19093331e13fe0f7031643dc.tar.bz2
gsgp-1bd9246f87fcd60e19093331e13fe0f7031643dc.zip
Basic command interpreter
-rwxr-xr-xtest/test-cmd29
-rwxr-xr-xutil/cmd35
2 files changed, 64 insertions, 0 deletions
diff --git a/test/test-cmd b/test/test-cmd
new file mode 100755
index 0000000..ffd419a
--- /dev/null
+++ b/test/test-cmd
@@ -0,0 +1,29 @@
+#!/bin/bash
+#
+# Tests command interpreter
+#
+# Copyright (C) 2011 Mike Gerwitz
+#
+# This file is part of gsgp. This program is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
+
+mypath=$( dirname $0 )
+. "$mypath/common"
+
+# MSG command should output the given message (consuming all arguments) to
+# stdout
+msg="This is a test message"
+assert-equal "$( cmd MSG $msg )" "$msg" || {
+ fail "Should properly output MSGs"
+}
diff --git a/util/cmd b/util/cmd
new file mode 100755
index 0000000..24e35d3
--- /dev/null
+++ b/util/cmd
@@ -0,0 +1,35 @@
+#!/bin/bash
+#
+# Basic command interpreter
+#
+# Copyright (C) 2011 Mike Gerwitz
+#
+# This file is part of gsgp. This program is free software: you can
+# redistribute it and/or modify it under the terms of the GNU General Public
+# License as published by the Free Software Foundation, either version 3 of
+# the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+##
+
+# we accept the data as an argument list
+data="$@"
+
+# the command will be the first word and the remaining text will act as the
+# argument list
+cmd=$( cut -d' ' -f1 <<< "$data" )
+args=$( cut -sd' ' -f2- <<< "$data" )
+
+case "$cmd" in
+ MSG)
+ # the entire argument list represents the message
+ echo "$args"
+ ;;
+esac
+