|
Sharg 1.2.3-rc.1
The argument parser for bio-c++ tools.
|
A functor whose operator() performs the server http request and version checks. More...
#include <sharg/detail/version_check.hpp>
Public Member Functions | |
| void | operator() (std::promise< bool > prom) |
| Initialises the version_checker with the application name and version. | |
| bool | decide_if_check_is_performed (update_notifications developer_approval, std::optional< bool > user_approval) |
| The central decision whether to perform the version check or not. | |
Constructors, destructor and assignment | |
| version_checker ()=delete | |
| This class has to be initialised with name and version information. | |
| version_checker (version_checker const &)=default | |
| Defaulted. | |
| version_checker & | operator= (version_checker const &)=default |
| Defaulted. | |
| version_checker (version_checker &&)=default | |
| Defaulted. | |
| version_checker & | operator= (version_checker &&)=default |
| Defaulted. | |
| ~version_checker ()=default | |
| Defaulted. | |
| version_checker (std::string name_, std::string const &version_, std::string const &app_url=std::string{}) | |
| Initialises the version_checker with the application name and version. | |
Static Public Member Functions | |
| static std::filesystem::path | get_path () |
| Returns a writable path to store timestamp and version files or an empty path if none exists. | |
| static bool | is_disabled (update_notifications developer_approval, std::optional< bool > user_approval) |
| Whether the developer, the environment variable SHARG_NO_VERSION_CHECK or the user disabled the check. | |
Public Attributes | |
| std::string | message_app_update |
| The message directed to the user of the app if a new app version is available. | |
| std::string | name |
| The application name. | |
| std::string | version {"0.0.0"} |
| The version of the application. | |
| std::regex | version_regex {"^[[:digit:]]+\\.[[:digit:]]+\\.[[:digit:]]+$"} |
| The regex to verify a valid version string. | |
| std::filesystem::path | cookie_path = get_path() |
| The path to store timestamp and version files (either ~/.config/seqan or the tmp directory). | |
| std::filesystem::path | timestamp_filename |
| The timestamp filename. | |
Static Public Attributes | |
| static constexpr std::string_view | unregistered_app = "UNREGISTERED_APP" |
| The identification string that may appear in the version file if an app is unregistered. | |
| static constexpr std::string_view | message_sharg_update |
| The message directed to the developer of the app if a new sharg version is available. | |
| static constexpr std::string_view | message_unregistered_app |
| The message directed to the developer of the app if the app is not yet registered with us. | |
| static constexpr std::string_view | message_registered_app_update |
| The message directed to the developer if the application is registered but under a lower version. | |
| static constexpr std::string_view | message_no_writable_directory |
| The message if the version check is skipped because there is no writable directory for its files. | |
| static constexpr char const * | home_env_name |
| The environment name of the home environment used by getenv() | |
Private Member Functions | |
| double | get_time_diff_to_current (std::string const &str_time) const |
| Reads the timestamp file if possible and returns the time difference to the current time. | |
| std::array< int, 3 > | get_numbers_from_version_string (std::string const &str) const |
| Parses a version string into an array of length 3. | |
| template<typename msg_type > | |
| void | write_cookie (msg_type &&msg) |
| Writes a cookie file with a specified message. | |
Static Private Member Functions | |
| static std::string | get_program () |
| Returns the command line call as a std::string of an available program depending on the environment. | |
A functor whose operator() performs the server http request and version checks.
|
inline |
Initialises the version_checker with the application name and version.
| [in] | name_ | The application name. |
| [in] | version_ | The application version. |
| [in] | app_url | An (github) url with the newest release information of the application. |
|
inline |
The central decision whether to perform the version check or not.
| [in] | developer_approval | Whether the developer approved (update_notifications::on) or not (update_notifications::off). |
| [in] | user_approval | Whether the user approved (true) or not (false) or did not decide (unset optional). |
The following rules apply:
If the developer says no, it rules out all following decisions (even if the user specified –version-check true). No cookie is ever written.
If the environment variable SHARG_NO_VERSION_CHECK is set no version check is done (rules out all following). No cookie is written.
If the user explicitly uses the –version-check option (user_approval is set) it rules out all following decisions. No cookie is written. However, if there is no writable directory (see get_path()), no version check is done even if the user specified –version-check true. If the terminal is interactive, message_no_writable_directory is printed instead.
If none of the above apply, version check was not explicitly handled so cookie content is checked:
If the cookie content is "ASK" and the timestamp is older than a day we ask the user, if possible, what he wants to do, set the according cookie for the next time and continue. If we cannot ask the user, the default kicks in (do the check).
|
inlineprivate |
Parses a version string into an array of length 3.
| [in] | str | The version string that must match sharg::detail::version_regex. |
|
inlinestatic |
Returns a writable path to store timestamp and version files or an empty path if none exists.
The path is .config/seqan in the home directory given by the environment variable HOME (UserProfile on Windows). If this variable is not set or empty, .config/seqan is relative to the current working directory. If .config/seqan cannot be created, the temporary directory is used, see std::filesystem::temp_directory_path.
|
inlinestatic |
Whether the developer, the environment variable SHARG_NO_VERSION_CHECK or the user disabled the check.
| [in] | developer_approval | Whether the developer approved (update_notifications::on) or not (update_notifications::off). |
| [in] | user_approval | Whether the user approved (true) or not (false) or did not decide (unset optional). |
In contrast to decide_if_check_is_performed(), this does not need the directory for the timestamp and version files. Hence, the parser can call it before constructing the version_checker, which determines and creates this directory.
|
inline |
Initialises the version_checker with the application name and version.
| [in] | prom | The promise to track the state of the detached thread which calls sharg::detail::call_server. |
The operator performs the following steps:
|
inlineprivate |
Writes a cookie file with a specified message.
| msg_type | The type of message. |
| [in] | msg | The message to write into the file (no newline is appended). |
|
staticconstexpr |
The environment name of the home environment used by getenv()
| std::string sharg::detail::version_checker::message_app_update |
The message directed to the user of the app if a new app version is available.
|
staticconstexpr |
The message if the version check is skipped because there is no writable directory for its files.
|
staticconstexpr |
The message directed to the developer if the application is registered but under a lower version.
|
staticconstexpr |
The message directed to the developer of the app if a new sharg version is available.
|
staticconstexpr |
The message directed to the developer of the app if the app is not yet registered with us.