(* 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