diff --git a/common.cpp b/common.cpp index dc5da19..b53b39f 100644 --- a/common.cpp +++ b/common.cpp @@ -3689,14 +3689,11 @@ string Application::key2shortHelp (const string &name) const -string Application::getInstruction (bool coutP) const +string Application::getInstruction (bool screen) const { string instr (description); - if (isRedirected (cout)) - coutP = false; - - instr += "\n\n" + colorize ("USAGE", coutP) + ": " + programName; + instr += "\n\n" + colorize ("USAGE", screen) + ": " + programName; for (const Positional& p : positionalArgs) instr += " " + p. str (); @@ -3728,10 +3725,10 @@ string Application::getInstruction (bool coutP) const if (! requiredGroup_prev. empty ()) instr += ")"; - instr += "\n" + colorize ("HELP", coutP) + ": " + programName + " " + ifS (gnu, "-") + "-" + helpS; + instr += "\n" + colorize ("HELP", screen) + ": " + programName + " " + ifS (gnu, "-") + "-" + helpS; if (gnu) instr += " or " + programName + " -" + helpS [0]; - instr += "\n" + colorize ("VERSION", coutP) + ": " + programName + " " + ifS (gnu, "-") + "-" + versionS; + instr += "\n" + colorize ("VERSION", screen) + ": " + programName + " " + ifS (gnu, "-") + "-" + versionS; if (gnu) instr += " or " + programName + " -" + versionS [0]; @@ -3740,42 +3737,43 @@ string Application::getInstruction (bool coutP) const -string Application::getDocumentation () const +string Application::getDocumentation (bool screen) const { if (documentationUrl. empty ()) return noString; - return "\n\n" + colorize ("DOCUMENTATION", true) + "\n See " + documentationUrl + " for full documentation"; + return "\n\n" + colorize ("DOCUMENTATION", screen) + "\n See " + colorizeUrl (documentationUrl, screen) + " for full documentation"; } -string Application::getUpdates () const +string Application::getUpdates (bool screen) const { if (updatesDoc. empty ()) return noString; - return "\n\n" + colorize ("UPDATES", true) + "\n" + updatesDoc; + string s ("\n\n" + colorize ("UPDATES", screen) + "\n" + updatesDoc); + if (! updatesUrl. empty ()) + s += ": " + colorizeUrl (updatesUrl, screen); + return s; } -string Application::getHelp () const +string Application::getHelp (bool screen) const { - string instr (getInstruction (true)); + string instr (getInstruction (screen)); const string par ("\n "); - const bool coutP = ! isRedirected (cout); - if (! positionalArgs. empty ()) { - instr += "\n\n" + colorize ("POSITIONAL PARAMETERS", coutP) /*+ ":"*/; + instr += "\n\n" + colorize ("POSITIONAL PARAMETERS", screen) /*+ ":"*/; for (const Positional& p : positionalArgs) instr += "\n" + p. str () + par + p. description; } if (! keyArgs. empty ()) { - instr += "\n\n" + colorize ("NAMED PARAMETERS", coutP) /*+ ":"*/; + instr += "\n\n" + colorize ("NAMED PARAMETERS", screen) /*+ ":"*/; for (const Key& key : keyArgs) { instr += "\n" + key. getShortHelp () + par + key. description; @@ -3875,7 +3873,8 @@ int Application::run (int argc, if (name == helpS || (name. empty () && c == helpS [0] && gnu)) { - cout << getHelp () << getDocumentation () << getUpdates () << endl; + const bool screen = ! isRedirected (cout); + cout << getHelp (screen) << getDocumentation (screen) << getUpdates (screen) << endl; return 0; } if (name == versionS || (name. empty () && c == versionS [0] && gnu)) @@ -3921,7 +3920,8 @@ int Application::run (int argc, if (programArgs. size () == 1 && (! positionalArgs. empty () || needsArg)) { - cout << getInstruction (true) << getDocumentation () << endl; + const bool screen = ! isRedirected (cout); + cout << getInstruction (screen) << getDocumentation (screen) << endl; return 1; } @@ -4142,9 +4142,9 @@ void ShellApplication::initVar () -string ShellApplication::getHelp () const +string ShellApplication::getHelp (bool screen) const { - string help (Application::getHelp ()); + string help (Application::getHelp (screen)); if (useTmp) help += "\n\nTemporary directory used is $TMPDIR or \"/tmp\""; return help; diff --git a/common.hpp b/common.hpp index 119bb32..3eb5da5 100644 --- a/common.hpp +++ b/common.hpp @@ -1481,20 +1481,21 @@ struct Color }; -inline string colorize (const string &s, - bool active) - { if (! active) +inline string colorize_raw (const string &s, + Color::Type color, + bool screen) + { if (! screen) return s; - return Color::code (Color::white, true) + s + Color::code (); + return Color::code (color, true) + s + Color::code (); } +inline string colorize (const string &s, + bool screen) + { return colorize_raw (s, Color::white, screen); } + inline string colorizeUrl (const string &s, - bool active) - { const string prefix ("https://"); - if (! active) - return prefix + s; - return Color::code (Color::blue, true) + prefix + s + Color::code (); - } + bool screen) + { return colorize_raw (s, Color::blue, screen); } class OColor @@ -2978,21 +2979,24 @@ template { operator= (other); } template Set& operator= (const map &other) - { universal = false; + { P::clear (); + universal = false; for (const auto& it : other) P::insert (it. first); return *this; } template Set& operator= (const unordered_map &other) - { universal = false; + { P::clear (); + universal = false; for (const auto& it : other) P::insert (it. first); return *this; } template Set& operator= (const vector &other) - { universal = false; + { P::clear (); + universal = false; for (const U& u : other) P::insert (u); return *this; @@ -4459,7 +4463,10 @@ struct Application : Singleton, Root { const string description; string version {"0.0.0"}; - string documentationUrl; + // Without "https://" + string documentationUrl; + string updatesUrl; + // string updatesDoc; const bool needsArg; const bool gnu; @@ -4617,10 +4624,10 @@ struct Application : Singleton, Root {} virtual void initVar () {} - string getInstruction (bool coutP) const; - string getDocumentation () const; - string getUpdates () const; - virtual string getHelp () const; + string getInstruction (bool screen) const; + string getDocumentation (bool screen) const; + string getUpdates (bool screen) const; + virtual string getHelp (bool screen) const; // Requires: must be printed to cout string makeKey (const string ¶m, const string &value) const @@ -4678,7 +4685,7 @@ struct ShellApplication : Application void initVar () override; // stderr << "Running: " << getCommandLine () // threads_max correction - string getHelp () const override; + string getHelp (bool screen) const override; private: void body () const final; virtual void shellBody () const = 0; diff --git a/stxtyper.cpp b/stxtyper.cpp index 5446144..cac0c5e 100644 --- a/stxtyper.cpp +++ b/stxtyper.cpp @@ -32,6 +32,7 @@ * Dependencies: NCBI BLAST, gunzip (optional) * * Release changes: +* 1.0.24 08/05/2024 PD-5076 "na" -> "NA" * 1.0.23 07/29/2024 PD-5064 AMBIGUOUS operon type * 1.0.22 07/25/2024 First codon L|I|V -> M * 1.0.21 07/15/2024 PD-5038 --nucleotide_output @@ -112,7 +113,7 @@ constexpr size_t intergenic_max {36}; // Max. intergenic region in the referenc constexpr size_t slack = 30; const string stxS ("stx"); -const string na ("na"); +const string na ("NA"); diff --git a/version.txt b/version.txt index 154b9fc..79728fe 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.0.23 +1.0.24