goaljobs_config.ml.in \
goaljobs.ml \
goaljobs.mli \
+ goaljobs_memory.ml \
goaljobs.pod \
goaljobs-reference.pod \
goaljobs.spec \
sources = \
goaljobs_config.ml \
goaljobs.ml \
- goaljobs.mli
+ goaljobs.mli \
+ goaljobs_memory.ml
-bin_SCRIPTS = goaljobs
+bin_SCRIPTS = goaljobs goaljobs-memory
# These targets are noinst because we use a custom install hook to
# install them, and are _SCRIPTS because automake doesn't know how to
$(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -package camlp4.lib -linkpkg \
-pp $(CAMLP4OF) -c $< -o $@
+# Standalone program for examining the goaljobs memory.
+goaljobs-memory: goaljobs_config.cmx goaljobs.cmx goaljobs_memory.cmx
+ $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) $(OCAMLOPTPACKAGES) \
+ $^ -linkpkg -o $@
+
# Install.
install-data-hook:
mkdir -p $(DESTDIR)$(OCAMLLIB)
val memory_delete : string -> unit
(** Delete the [key]. If the key doesn't exist, has no effect. *)
+val memory_list : unit -> (string * string) list
+ (** Return all [(key, value)] pairs in the memory. *)
+
(** {2 Publishing goals} *)
val publish : string -> (string list -> unit) -> unit
--- /dev/null
+(* goaljobs
+ * Copyright (C) 2013-2014 Red Hat Inc.
+ *
+ * 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 2 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, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *)
+
+open Unix
+open Printf
+
+open Goaljobs
+
+(* Stand-alone tool to read and modify the user's goaljobs memory. *)
+
+let usage ret =
+ printf " %s list\n" Sys.executable_name;
+ printf " %s [exists|get|delete] key\n" Sys.executable_name;
+ printf " %s set key value\n" Sys.executable_name;
+ printf "Subcommands:\n";
+ printf " exists - Check if key exists, exit code 0 if exists, 1 if not\n";
+ printf " get - Print the current value of the key\n";
+ printf " set - Set the key to a new value\n";
+ printf " delete - Delete the key\n";
+ printf " list - List the names and values of all keys\n";
+ exit ret
+
+let () =
+ match Array.to_list Sys.argv with
+ | [] -> usage 1
+ | [ ("--help" | "-h" | "-?") ] -> usage 0
+ | [ _; "exists"; key ] ->
+ if memory_exists key then exit 0 else exit 1
+ | [ _; "get"; key ] ->
+ (match memory_get key with
+ | None ->
+ eprintf "%s: key '%s' not found in memory\n" Sys.executable_name key;
+ exit 1
+ | Some v -> print_endline v
+ )
+ | [ _; "set"; key; value ] ->
+ memory_set key value
+ | [ _; "delete"; key ] ->
+ memory_delete key
+ | [ _; "list" ] ->
+ let mem = memory_list () in
+ List.iter (fun (key, value) -> printf "%s\t%s\n" key value) mem
+ | _ -> usage 1