A functor whose operator() performs the server http request and version checks.
More...
#include <sharg/detail/version_check.hpp>
|
static std::filesystem::path | get_path () |
| Returns a writable path to store timestamp and version files or an empty path if none exists.
|
|
|
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 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.
◆ version_checker()
Initialises the version_checker with the application name and version.
- Parameters
-
[in] | name_ | The application name. |
[in] | version_ | The application version. |
[in] | app_url | An (github) url with the newest release information of the application. |
◆ decide_if_check_is_performed()
The central decision whether to perform the version check or not.
- Parameters
-
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.
If none of the above apply, version check was not explicitly handled so cookie content is checked:
- NEVER: Do not perform the version check and do not change the cookie.
- ALWAYS: Do perform the version check once a day and do not change the cookie.
- ASK: Ask the user or default the decision once a day.
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).
◆ get_numbers_from_version_string()
std::array< int, 3 > sharg::detail::version_checker::get_numbers_from_version_string |
( |
std::string const & | str | ) |
const |
|
inlineprivate |
Parses a version string into an array of length 3.
- Parameters
-
[in] | str | The version string that must match sharg::detail::version_regex. |
◆ operator()()
void sharg::detail::version_checker::operator() |
( |
std::promise< bool > | prom | ) |
|
|
inline |
Initialises the version_checker with the application name and version.
- Parameters
-
The operator performs the following steps:
- If a timestamp file already exists, the following behaviour can be expected depending on the file contents:
- content "NEVER": No server call is performed and no update information is printed.
- content "ALWAYS": A server call is performed and update information is printed if a version file exists.
- content is a timestamp: The "time-of-last-version-check" is read from file. The function only continues if the last version check is more than a day old.
- If a version file exists, the app version and Sharg version are compared to the current ones and the the following message may be printed: Debug mode (directed at the developer of the application)
- If the app is unregistered (no version information is available at the server) the developer will be notified that he has the possibility of registering his application with us (see sharg::version_checker::message_unregistered_app).
- If the current Sharg version is smaller than the one returned by the server call, the developer is notified that he may update to the newest Sharg version (see sharg::version_checker::message_sharg_update).
- If the current app version is greater than the one returned by the server call, we assume that the developer has released a new version and is notified to send us the new version (see sharg::version_checker::message_registered_app_update). Release mode (directed at the user of the application):
- If the current app version is lower than the one returned by the server call, the user is notified that a newer version exists.
◆ write_cookie()
template<typename msg_type >
void sharg::detail::version_checker::write_cookie |
( |
msg_type && | msg | ) |
|
|
inlineprivate |
Writes a cookie file with a specified message.
- Template Parameters
-
msg_type | The type of message. |
- Parameters
-
[in] | msg | The message to write into the file (no newline is appended). |
◆ home_env_name
constexpr char const* sharg::detail::version_checker::home_env_name |
|
staticconstexpr |
Initial value:
The environment name of the home environment used by getenv()
◆ message_app_update
std::string sharg::detail::version_checker::message_app_update |
Initial value:=
"[APP VERSION INFO] :: A new version of this application is now available.\n"
"[APP VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n"
The message directed to the user of the app if a new app version is available.
◆ message_registered_app_update
constexpr std::string_view sharg::detail::version_checker::message_registered_app_update |
|
staticconstexpr |
Initial value:=
"[APP VERSION INFO] :: We noticed the app version you use is newer than the one registered with us.\n"
"[APP VERSION INFO] :: Please send us an email with the new version so we can correct it "
"(support@seqan.de)\n\n"
The message directed to the developer if the application is registered but under a lower version.
◆ message_sharg_update
Initial value:=
"[SHARG VERSION INFO] :: A new Sharg version is available online.\n"
"[SHARG VERSION INFO] :: Please visit www.github.com/seqan/sharg-parser.git for an update\n"
"[SHARG VERSION INFO] :: or inform the developer of this app.\n"
"[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n"
The message directed to the developer of the app if a new sharg version is available.
◆ message_unregistered_app
constexpr std::string_view sharg::detail::version_checker::message_unregistered_app |
|
staticconstexpr |
Initial value:=
"[SHARG VERSION INFO] :: Thank you for using Sharg!\n"
"[SHARG VERSION INFO] :: Do you wish to register your app for update notifications?\n"
"[SHARG VERSION INFO] :: Just send an email to support@seqan.de with your app name and version number.\n"
"[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n"
The message directed to the developer of the app if the app is not yet registered with us.
The documentation for this class was generated from the following file: