25namespace sharg::detail
42 if (system(command.
c_str()))
73 for (
char const c : argument)
76 result.
append(escaped_quote);
81 result.push_back(
'\'');
116 if (!app_url.empty())
130 if (!version_.
empty() &&
172 if (version_file.is_open())
187 version_file.close();
191 if (srv_sharg_version != empty_version)
200 if (srv_app_version != empty_version)
229 +
std::string{
"https://seqan-update.cs.uni-tuebingen.de/check/SeqAn-Sharg_"} +
243#if __x86_64__ || __ppc64__
251 "; exit [int] -not $?}\" > nul 2>&1";
272 if (
char * home_env = getenv(
home_env_name); home_env !=
nullptr)
274 tmp_path /=
".config";
278 create_directory(tmp_path, err);
284 create_directory(tmp_path, err);
290 tmp_path = temp_directory_path(err);
305 std::ofstream file{dummy, std::ios::out | std::ios::noreplace};
307 bool is_open = file.is_open();
308 bool is_good = file.good();
314 if (!is_good || !is_open)
334 || user_approval ==
false;
366 if (
is_disabled(developer_approval, user_approval))
387 if (timestamp_file.is_open())
398 if (cookie_line ==
"NEVER")
402 else if (cookie_line ==
"ALWAYS")
408 timestamp_file.close();
419#######################################################################
420 Automatic Update Notifications
421#######################################################################
423 This app can look for updates automatically in the background,
424 do you want to do that?
426 [a] Always perform version checks for this app.
427 [n] Never perform version checks for this app.
428 [y] Yes, perform a version check now, and ask again tomorrow.
429 [s] Skip the version check now, but ask again tomorrow (the default).
431 Please enter one of [a, n, y, s] and press [RETURN].
433 For more information, see:
434 https://docs.seqan.de/sharg/main_user/about_update_notifications.html
436#######################################################################
475 "[SHARG VERSION INFO] :: A new Sharg version is available online.\n"
476 "[SHARG VERSION INFO] :: Please visit www.github.com/seqan/sharg-parser.git for an update\n"
477 "[SHARG VERSION INFO] :: or inform the developer of this app.\n"
478 "[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
481 "[SHARG VERSION INFO] :: Thank you for using Sharg!\n"
482 "[SHARG VERSION INFO] :: Do you wish to register your app for update notifications?\n"
483 "[SHARG VERSION INFO] :: Just send an email to support@seqan.de with your app name and version number.\n"
484 "[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
487 "[APP VERSION INFO] :: We noticed the app version you use is newer than the one registered with us.\n"
488 "[APP VERSION INFO] :: Please send us an email with the new version so we can correct it "
489 "(support@seqan.de)\n\n";
492 "[SHARG VERSION INFO] :: The version check was skipped because there is no writable directory for its files.\n"
493 "[SHARG VERSION INFO] :: For details, see "
494 "https://docs.seqan.de/sharg/main_user/about_update_notifications.html\n"
495 "[SHARG VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
498 "[APP VERSION INFO] :: A new version of this application is now available.\n"
499 "[APP VERSION INFO] :: If you don't wish to receive further notifications, set --version-check false.\n\n";
528 return "powershell.exe -NoLogo -NonInteractive -Command \"& {Invoke-WebRequest -erroraction 'silentlycontinue' "
531 if (!system(
"/usr/bin/env -i wget --version > /dev/null 2>&1"))
532 return "/usr/bin/env -i wget --timeout=10 --tries=1 -q -O";
533 else if (!system(
"/usr/bin/env -i curl --version > /dev/null 2>&1"))
534 return "/usr/bin/env -i curl --connect-timeout 10 -o";
537# if defined(__OpenBSD__)
538 return "/usr/bin/env -i ftp -w10 -Vo";
539# elif defined(__FreeBSD__)
540 return "/usr/bin/env -i fetch --timeout=10 -o";
551 double curr = co::duration_cast<co::seconds>(co::system_clock::now().time_since_epoch()).count();
556 return curr - d_time;
580 template <
typename msg_type>
585 auto curr = co::duration_cast<co::seconds>(co::system_clock::now().time_since_epoch()).count();
589 if (timestamp_file.is_open())
591 timestamp_file << curr <<
'\n' << msg;
592 timestamp_file.close();
Provides auxiliary information.
The <charconv> header from C++17's standard library.
A functor whose operator() performs the server http request and version checks.
Definition version_check.hpp:93
static constexpr std::string_view message_sharg_update
The message directed to the developer of the app if a new sharg version is available.
Definition version_check.hpp:454
void write_cookie(msg_type &&msg)
Writes a cookie file with a specified message.
Definition version_check.hpp:561
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.
Definition version_check.hpp:111
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.
Definition version_check.hpp:460
version_checker()=delete
This class has to be initialised with name and version information.
std::string version
The version of the application.
Definition version_check.hpp:495
std::filesystem::path timestamp_filename
The timestamp filename.
Definition version_check.hpp:501
static constexpr std::string_view unregistered_app
The identification string that may appear in the version file if an app is unregistered.
Definition version_check.hpp:452
static std::filesystem::path get_path()
Returns a writable path to store timestamp and version files or an empty path if none exists.
Definition version_check.hpp:266
static std::string get_program()
Returns the command line call as a std::string of an available program depending on the environment.
Definition version_check.hpp:505
std::string name
The application name.
Definition version_check.hpp:493
version_checker & operator=(version_checker const &)=default
Defaulted.
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.
Definition version_check.hpp:466
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...
Definition version_check.hpp:331
version_checker(version_checker const &)=default
Defaulted.
version_checker & operator=(version_checker &&)=default
Defaulted.
std::filesystem::path cookie_path
The path to store timestamp and version files (either ~/.config/seqan or the tmp directory).
Definition version_check.hpp:499
version_checker(version_checker &&)=default
Defaulted.
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.
Definition version_check.hpp:528
void operator()(std::promise< bool > prom)
Initialises the version_checker with the application name and version.
Definition version_check.hpp:164
std::regex version_regex
The regex to verify a valid version string.
Definition version_check.hpp:497
~version_checker()=default
Defaulted.
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.
Definition version_check.hpp:471
std::string message_app_update
The message directed to the user of the app if a new app version is available.
Definition version_check.hpp:477
std::array< int, 3 > get_numbers_from_version_string(std::string const &str) const
Parses a version string into an array of length 3.
Definition version_check.hpp:542
static constexpr char const * home_env_name
The environment name of the home environment used by getenv()
Definition version_check.hpp:484
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.
Definition version_check.hpp:364
update_notifications
Indicates whether application allows automatic update notifications by the sharg::parser.
Definition auxiliary.hpp:27
@ off
Automatic update notifications should be disabled.
bool stderr_is_terminal()
Check whether the standard error output is interactive.
Definition terminal.hpp:63
bool stdin_is_terminal()
Check whether the standard input is interactive.
Definition terminal.hpp:33
std::string quote_argument(std::string const &argument)
Quotes a string such that the shell executing the server call treats it as a single,...
Definition version_check.hpp:59
void call_server(std::string const &command, std::promise< bool > prom)
Writes a timestamp file and performs the server call to get the newest version information.
Definition version_check.hpp:39
T regex_search(T... args)
Checks if program is run interactively and retrieves dimensions of terminal (Transferred from seqan2)...
#define SHARG_VERSION_MINOR
The minor version as MACRO.
Definition version.hpp:18
#define SHARG_VERSION_PATCH
The patch version as MACRO.
Definition version.hpp:20
constexpr std::size_t sharg_version
The full version as std::size_t.
Definition version.hpp:61
#define SHARG_VERSION_MAJOR
The major version as MACRO.
Definition version.hpp:16