From 6eba782291a999e4577bc8d3386f0dcb6945e6a4 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Sun, 17 May 2020 03:08:54 -0500 Subject: all: Add --version and --help support and unify output formats --- tools/hscript-fromjson/jsonconv.1 | 5 ++- tools/hscript-fromjson/jsonconv.cc | 16 ++++++- tools/hscript-simulate/simulator.1 | 6 ++- tools/hscript-simulate/simulator.cc | 76 +++++++++++++++++++-------------- tools/hscript-validate/validator.1 | 6 ++- tools/hscript-validate/validator.cc | 84 +++++++++++++++++++++---------------- 6 files changed, 121 insertions(+), 72 deletions(-) (limited to 'tools') diff --git a/tools/hscript-fromjson/jsonconv.1 b/tools/hscript-fromjson/jsonconv.1 index d8fe22e..a05a67f 100644 --- a/tools/hscript-fromjson/jsonconv.1 +++ b/tools/hscript-fromjson/jsonconv.1 @@ -8,6 +8,7 @@ .Nm .Op Fl fn .Op Fl h +.Op Fl v .Op Ar INSTALLFILE .Op Ar JSONFILE .Sh DESCRIPTION @@ -36,10 +37,12 @@ exists. By default, will display an error and quit without writing if a HorizonScript already exists at the specified path. .It Fl h -Display a help message, and then quit. +Displays a help message, and then exits. .It Fl n Disables colour output and ANSI escape sequences in any log messages. This is the default when not running from a terminal. +.It Fl v +Displays the version information for this utility, and then exits. .El .Sh EXIT STATUS .Ex -std diff --git a/tools/hscript-fromjson/jsonconv.cc b/tools/hscript-fromjson/jsonconv.cc index 3a5c564..b5c9504 100644 --- a/tools/hscript-fromjson/jsonconv.cc +++ b/tools/hscript-fromjson/jsonconv.cc @@ -146,7 +146,7 @@ bool parse_one_desc(json desc, std::ostream &out) { int main(int argc, char *argv[]) { using namespace boost::program_options; - bool needs_help{}, disable_pretty{}, force{}; + bool needs_help{}, disable_pretty{}, force{}, version_only{}; std::string if_path{"/etc/horizon/installfile"}, json_path; int exit_code = EXIT_SUCCESS; @@ -155,6 +155,7 @@ int main(int argc, char *argv[]) { options_description general{"General options"}; general.add_options() ("help,h", bool_switch(&needs_help), "Display this message.") + ("version,v", bool_switch(&version_only), "Show program version information") ("no-colour,n", bool_switch(&disable_pretty), "Do not 'prettify' output") ("force,f", bool_switch(&force), "Force writing, even if HorizonScript already exists") ; @@ -205,6 +206,19 @@ int main(int argc, char *argv[]) { json_path = "-"; } + if(version_only) { + bold_if_pretty(std::cout); + std::cout << "HorizonScript JSON Conversion Utility version " << VERSTR + << std::endl; + reset_if_pretty(std::cout); + std::cout << "Copyright (c) 2020 Adélie Linux and contributors." + << std::endl + << "This software is licensed to you under the terms of the " + << std::endl << "AGPL 3.0 license, unless otherwise noted." + << std::endl << std::endl; + return EXIT_SUCCESS; + } + if(!force && fs::exists(if_path)) { output_error("