Code

frontend/grammar: Changed ‘LIST …’ to ‘LIST hosts …’.
authorSebastian Harl <sh@tokkee.org>
Sat, 2 Aug 2014 20:52:25 +0000 (22:52 +0200)
committerSebastian Harl <sh@tokkee.org>
Sat, 2 Aug 2014 20:52:25 +0000 (22:52 +0200)
This seems more consistent.

src/frontend/grammar.y
t/integration/simple_query.sh
t/unit/frontend/parser_test.c

index a2ae448cc744166875afd8e0f4904b5a186ad5cf..3ece01a9bddc708285789cf2ab59c3c756419908 100644 (file)
@@ -201,7 +201,7 @@ statement:
        ;
 
 /*
- * FETCH <hostname>;
+ * FETCH <hostname> [FILTER <condition>];
  *
  * Retrieve detailed information about a single host.
  */
@@ -218,17 +218,29 @@ fetch_statement:
        ;
 
 /*
- * LIST;
+ * LIST <type> [FILTER <condition>];
  *
  * Returns a list of all hosts in the store.
  */
 list_statement:
-       LIST filter_clause
+       LIST IDENTIFIER filter_clause
                {
+                       /* TODO: support other types as well */
+                       if (strcasecmp($2, "hosts")) {
+                               char errmsg[strlen($2) + 32];
+                               snprintf(errmsg, sizeof(errmsg),
+                                               YY_("unknown data-source %s"), $2);
+                               sdb_fe_yyerror(&yylloc, scanner, errmsg);
+                               free($2); $2 = NULL;
+                               sdb_object_deref(SDB_OBJ($3));
+                               YYABORT;
+                       }
+
                        $$ = SDB_CONN_NODE(sdb_object_create_dT(/* name = */ NULL,
                                                conn_list_t, conn_list_destroy));
-                       CONN_LIST($$)->filter = CONN_MATCHER($2);
+                       CONN_LIST($$)->filter = CONN_MATCHER($3);
                        $$->cmd = CONNECTION_LIST;
+                       free($2); $2 = NULL;
                }
        ;
 
index 86ac03fd80962dae080dc08c7425ee4319f172c3..942b77cb9960ff7da15c88f0afe1080307d6e878 100755 (executable)
@@ -54,7 +54,7 @@ echo "$output" | grep "Failed to parse query 'INVALID'"
 echo "$output" | grep "parse error: syntax error"
 
 # Simple, successful commands.
-output="$( run_sysdb -H "$SOCKET_FILE" -c LIST )"
+output="$( run_sysdb -H "$SOCKET_FILE" -c 'LIST hosts' )"
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"' \
@@ -62,7 +62,7 @@ echo "$output" \
        | grep -F '"other.host.name"' \
        | grep -F '"some.host.name"'
 
-output="$( echo 'LIST;' | run_sysdb -H "$SOCKET_FILE" )" || echo $?
+output="$( echo 'LIST hosts;' | run_sysdb -H "$SOCKET_FILE" )" || echo $?
 echo "$output" \
        | grep -F '"host1.example.com"' \
        | grep -F '"host2.example.com"' \
@@ -80,7 +80,7 @@ echo "$output" | grep -F 'localhost' && exit 1
 echo "$output" | grep -F 'other.host.name' && exit 1
 echo "$output" | grep -F 'some.host.name' && exit 1
 
-(echo 'LIST;'; sleep 1; echo "FETCH 'host1.example.com'") \
+(echo 'LIST hosts;'; sleep 1; echo "FETCH 'host1.example.com'") \
        | run_sysdb -H "$SOCKET_FILE"
 
 # When requesting information for unknown hosts, expect a non-zero exit code.
index bca86452dffc44afe22f2fb5b3418eaa7e6f42f3..16f61afaf79bd07e6457176382430a08fb4501a8 100644 (file)
@@ -56,11 +56,11 @@ START_TEST(test_parse)
                { "FETCH 'host' FILTER "
                  "host = 'host'",       -1,  1, CONNECTION_FETCH  },
 
-               { "LIST",                -1,  1, CONNECTION_LIST   },
-               { "LIST -- comment",     -1,  1, CONNECTION_LIST   },
-               { "LIST;",               -1,  1, CONNECTION_LIST   },
-               { "LIST; INVALID",        5,  1, CONNECTION_LIST   },
-               { "LIST FILTER "
+               { "LIST hosts",          -1,  1, CONNECTION_LIST   },
+               { "LIST hosts -- foo",   -1,  1, CONNECTION_LIST   },
+               { "LIST hosts;",         -1,  1, CONNECTION_LIST   },
+               { "LIST hosts; INVALID", 11,  1, CONNECTION_LIST   },
+               { "LIST hosts FILTER "
                  "host = 'host'",       -1,  1, CONNECTION_LIST   },
 
                { "LOOKUP hosts",        -1,  1, CONNECTION_LOOKUP },
@@ -190,6 +190,7 @@ START_TEST(test_parse)
                { "LIST; INVALID",        8, -1, 0 },
                { "/* some incomplete",  -1, -1, 0 },
 
+               { "LIST",                -1, -1, 0 },
                { "LIST MATCHING "
                  "host = 'host'",       -1, -1, 0 },
                { "FETCH 'host' MATCHING "