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 --- fetch/fetch.cc | 13 ++++-- image/creator.1 | 3 ++ image/creator.cc | 20 ++++++--- 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 +++++++++++++++++++++---------------- ui/qt5/CMakeLists.txt | 2 +- ui/qt5/main.cc | 24 +++++++++++ 11 files changed, 173 insertions(+), 82 deletions(-) diff --git a/fetch/fetch.cc b/fetch/fetch.cc index b1a9f56..25e13bc 100644 --- a/fetch/fetch.cc +++ b/fetch/fetch.cc @@ -173,9 +173,12 @@ int main(int argc, char *argv[]) { bold_if_pretty(std::cout); std::cout << "HorizonScript Locator version " << VERSTR; reset_if_pretty(std::cout); - std::cout << std::endl; - std::cout << "Copyright (c) 2019 Adélie Linux and contributors. AGPL-3.0 license." << std::endl; - std::cout << std::endl; + std::cout << std::endl + << "Copyright (c) 2019-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; if(argc == 1) { if(access(IFILE_PATH, F_OK) == 0) { @@ -195,6 +198,10 @@ int main(int argc, char *argv[]) { } std::string path(argv[1]); + if(path == "--version") { + /* Banner printed above is our version statement. */ + return EXIT_SUCCESS; + } if(path[0] == '/') { return process_local(path); diff --git a/image/creator.1 b/image/creator.1 index 0a5a916..5673f75 100644 --- a/image/creator.1 +++ b/image/creator.1 @@ -11,6 +11,7 @@ .Op Fl n .Op Fl o Ar OUTPUT-FILE .Op Fl t Ar TYPE +.Op Fl v .Op Ar INSTALLFILE .Sh DESCRIPTION The @@ -77,6 +78,8 @@ utility can be obtained by specifying .Cm list as the argument to .Fl t . +.It Fl v +Displays the version information for this utility, and then exits. .It Ar INSTALLFILE Specifies the location of the HorizonScript to use for configuring the image. You may specify diff --git a/image/creator.cc b/image/creator.cc index 805e13b..c83c597 100644 --- a/image/creator.cc +++ b/image/creator.cc @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) { using namespace boost::program_options; using namespace Horizon::Image; - bool needs_help{}, disable_pretty{}; + bool needs_help{}, disable_pretty{}, version_only{}; int exit_code = EXIT_SUCCESS; std::string if_path{"/etc/horizon/installfile"}, ir_dir{"/target"}, output_path{"image.tar"}, type_code{"tar"}; @@ -42,7 +42,8 @@ int main(int argc, char *argv[]) { options_description general{"General options"}; general.add_options() ("help,h", bool_switch(&needs_help), "Display this message.") - ("no-colour,n", bool_switch(&disable_pretty), "Do not 'prettify' output") + ("no-colour,n", bool_switch(&disable_pretty), "Do not 'prettify' output.") + ("version,v", bool_switch(&version_only), "Show program version information.") ; options_description target{"Target control options"}; target.add_options() @@ -113,12 +114,19 @@ int main(int argc, char *argv[]) { } /* Announce our presence */ + bold_if_pretty(std::cout); std::cout << "HorizonScript Image Creation Utility version " << VERSTR + << std::endl; + reset_if_pretty(std::cout); + std::cout << "Copyright (c) 2020 Adélie Linux and contributors." << std::endl - << "Copyright (c) 2020 Adélie Linux and contributors." - << std::endl - << "This software is licensed to you under the AGPL 3.0, " - << "unless otherwise noted." << std::endl << 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; + + if(version_only) { + return EXIT_SUCCESS; + } /* Load the proper backend. */ for(const auto &candidate : BackendManager::available_backends()) { 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("