26void Sample::bsCLIDefine() {
27 AppCli::bsCLIDefine();
29 cli.DefineExitCodes <DateExitCodes >();
30 cli.DefineParameters<DateParameters>();
31 cli.DefineCommands <DateCommands >();
32 cli.DefineOptions <DateOptions >();
35void Sample::onBsPrepareConfig() {
37 AppCli::onBsPrepareConfig();
45"HlpCLIAppName",
A_CHAR(
"sample"),
46"HlpUsage" ,
A_CHAR(
"sample [format=\"FORMATSPEC\" [now]|[file FILENAME]"),
52 "This is a sample application provided with C++ library 'ALib'\n"
53 "to demonstrate the use of its module \"ALib App\"."
57"DateC<",
A_CHAR(
"datesample::Commands::"),
60 "1," "now" ",1" "," ","
61 "2," "file" ",1" ",filename" ) EOS
63"THlpCmdSht_now",
A_CHAR(
"Reports the actual date/time"),
64"THlpCmdLng_now",
A_CHAR(
"Reports the actual date/time. May be omitted, as this is the\n"
65 "default if no command is given.") EOS
67"THlpCmdSht_file",
A_CHAR(
"Returns the date/time of a file. "),
68"THlpCmdLng_file",
A_CHAR(
"Returns the last modification date/time of a file.") EOS
71"DateO<",
A_CHAR(
"datesample::Options::"),
74 "0," "format" ",1," "f," "=" ",1" "," ) EOS
76"TOptUsg_format",
A_CHAR(
"--format[=]\"placeholders\""),
77"TOptHlp_format",
A_CHAR(
"Sets the output format. The format specification is given with\n"
78 "documentation of ALib method CalendarDateTime::Format, found here:\n"
79 "https://alib.dev/classalib_1_1strings_1_1util_1_1CalendarDateTime.html" ) ,
82"DateP<",
A_CHAR(
"datesample::Parameters::"),
86"0," "FILENAME" ",1," "" "," "=" "," ",-1" ",0" ) EOS
88"THlpParSht_FILENAME",
A_CHAR(
"Mandatory parameter of command 'file."),
89"THlpParLng_FILENAME",
A_CHAR(
"Denotes the file that is used for retrieving the modification date.\n"
90 "This parameter is mandatory to command file and has to be appended\n"
91 "to this command, separated by '='") EOS
93"DateE<",
A_CHAR(
"datesample::"),
96"101," "ErrMissingFilename" ",-1,"
97"102," "ErrFileNotFound" ",-1,"
98"103," "ErrPermissionDenied" ",-1" ) EOS
100"TExit101" ,
A_CHAR(
"Command 'file' given without a filename argument." ) EOS
101"TExit102" ,
A_CHAR(
"File not found." ) EOS
102"TExit103" ,
A_CHAR(
"Permission denied." ) EOS
105"FNOTFND" ,
A_CHAR(
"The file {!Q} specified with command 'file' was not found.") EOS
106"FNOACC" ,
A_CHAR(
"Access denied to file {!Q} specified with command 'file'." ) EOS
107"MSNGFNAME",
A_CHAR(
"Error: no filename given with command 'file'" ) EOS
121 if ( AppCli::cliProcessCmd(cmd) )
124 if ( cmd ==
nullptr ) {
127 cOut->Add(dateWritten);
148 case DateCommands::Now: {
151 cOut->Add(dateWritten);
154 case DateCommands::File: {
162 machine.SetExitCode(DateExitCodes::ErrMissingFilename);
167 String4K name( cmd->ParametersMandatory.front()->Args.front() );
168 std::filesystem::path stdpath( name.Terminate() );
179 std::error_code errorCode;
180 auto timeValue= std::filesystem::last_write_time( stdpath, errorCode );
181 if ( errorCode.value() != 0 ) {
183 if ( errorCode.value() ==
int(std::errc::no_such_file_or_directory) ) {
184 cErr->Add( APPCLI_CAMP.GetResource(
"FNOTFND"), name);
185 machine.SetExitCode( DateExitCodes::ErrFileNotFound );
190 if ( errorCode.value() ==
int(std::errc::permission_denied) ) {
191 cErr->Add( APPCLI_CAMP.GetResource(
"FNOACC"), name);
192 machine.SetExitCode( DateExitCodes::ErrPermissionDenied );
199 dt.
Import( std::chrono::clock_cast<std::chrono::system_clock>(timeValue) );
202 cOut->Add(dateWritten);
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
#define ALIB_CALLER_NULLED
#define ALIB_ALLOW_SWITCH_WITHOUT_DEFAULT
#define ALIB_POP_ALLOWANCE
static bool GetHelp(CommandLine &cmdLine, const String &topics, Paragraphs &text)
const Enum & Element() const
const String & Identifier()
void Import(TTimePoint timePoint)
void Bootstrap(camp::Camp &camp, const NString &name, character innerDelim=',', character outerDelim=',')
Exception CreateExceptionFromSystemError(const CallerInfo &ci, std::error_code errorCode)
LocalString< 4096 > String4K
Type alias name for #"TLocalString;TLocalString<character,4096>".
app::AppCliCamp APPCLI_CAMP
The singleton instance of the camp class used by class #"AppCli".
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace alib.
LocalString< 128 > String128
Type alias name for #"TLocalString;TLocalString<character,128>".
time::DateTime DateTime
Type alias in namespace alib.
A command of a ALib CLI command-line.
CommandDecl * Declaration
The underlying declaration.
ListMA< Parameter *, Recycling::Shared > ParametersMandatory
Mandatory parameters parsed.