27void Sample::onBsCLIDefine() {
30 cli.DefineExitCodes <DateExitCodes >();
31 cli.DefineParameters<DateParameters>();
32 cli.DefineCommands <DateCommands >();
33 cli.DefineOptions <DateOptions >();
37void Sample::onBsPrepareConfig() {
39 App::onBsPrepareConfig();
43 if(!rc.
Do(
"sample.alibrc", __FILE__,
APP,
APP.ResourceCategory,
true,
63 cli.AppInfo.Allocate(cli.GetAllocator(), buffer.
Buffer);
68 if ( App::processCLICmd(cmd) )
71 if ( cmd ==
nullptr ) {
74 cOut->Add(dateWritten);
95 case DateCommands::Now: {
98 cOut->Add(dateWritten);
101 case DateCommands::File: {
105 cErr->Add(
APP.GetResource(
"MSNGFNAME"));
109 machine.SetExitCode(DateExitCodes::ErrMissingFilename);
114 String4K name( cmd->ParametersMandatory.front()->Args.front() );
115 std::filesystem::path stdpath( name.Terminate() );
126 std::error_code errorCode;
127 auto timeValue= std::filesystem::last_write_time( stdpath, errorCode );
128 if ( errorCode.value() != 0 ) {
130 if ( errorCode.value() ==
int(std::errc::no_such_file_or_directory) ) {
131 cErr->Add( APP.GetResource(
"FNOTFND"), name);
132 machine.SetExitCode( DateExitCodes::ErrFileNotFound );
137 if ( errorCode.value() ==
int(std::errc::permission_denied) ) {
138 cErr->Add( APP.GetResource(
"FNOACC"), name);
139 machine.SetExitCode( DateExitCodes::ErrPermissionDenied );
146 dt.
Import( std::chrono::clock_cast<std::chrono::system_clock>(timeValue) );
149 cOut->Add(dateWritten);
161void Sample::bulkloadResources() {
163 APP.GetResourcePool().BootstrapBulk(
APP.ResourceCategory,
166 "HlpCLIAppName" ,
A_CHAR(
"sample"),
167 "HlpUsage" ,
A_CHAR(
"sample [format=\"FORMATSPEC\" [now]|[file FILENAME]"),
168 "AppInfo" ,
A_CHAR(
"@HL-ALib Resource Compiler V. {}.{}\n")
169 A_CHAR(
"(c) 2023-{} AWorx GmbH. Published under MIT License (Open Source).\n")
170 A_CHAR(
"For more information, see: https://alib.dev/alib_mod_resources.html\n")
172 "HlpGeneral" ,
A_CHAR(
"\nABOUT sample\n")
173 A_CHAR(
"@>> This is a sample application provided with C++ library 'ALib' to demonstrate the use of its module \"ALib App\".\" \n")
175 "DateC<" ,
A_CHAR(
"datesample::Commands::"),
176 "DateC" ,
A_CHAR(
"1,now,1,,2,file,1,filename"),
177 "THlpCmdSht_now" ,
A_CHAR(
"Reports the actual date/time"),
178 "THlpCmdLng_now" ,
A_CHAR(
""),
179 "Reports" ,
A_CHAR(
"the actual date/time. May be omitted, as this is the default if no command is given."),
180 "THlpCmdSht_file" ,
A_CHAR(
"Returns the date/time of a file."),
181 "THlpCmdLng_file" ,
A_CHAR(
"Returns the last modification date/time of a file."),
182 "DateO<" ,
A_CHAR(
"datesample::Options::"),
183 "DateO" ,
A_CHAR(
"0,format,1,f,=,1,"),
184 "TOptUsg_format" ,
A_CHAR(
"--format[=]\"placeholders\""),
185 "TOptHlp_format" ,
A_CHAR(
"Sets the output format. The format specification is given with the documentation of the ALib method CalendarDateTime::Format, found here:\n")
186 A_CHAR(
"https://alib.dev/classalib_1_1strings_1_1util_1_1CalendarDateTime.html"),
187 "DateP<" ,
A_CHAR(
"datesample::Parameters::"),
188 "DateP" ,
A_CHAR(
"0,FILENAME,1,,=,,-1,0"),
189 "THlpParSht_FILENAME",
A_CHAR(
"Mandatory parameter of command \"file\"."),
190 "THlpParLng_FILENAME",
A_CHAR(
"Denotes the file that is used for retrieving the modification date. This parameter is mandatory to be given with command 'file' and has to be appended to this command, separated by '='\""),
191 "DateE<" ,
A_CHAR(
"datesample::"),
192 "DateE" ,
A_CHAR(
"101,ErrMissingFilename,-1,102,ErrFileNotFound,-1,103,ErrPermissionDenied,-1"),
193 "TExit101" ,
A_CHAR(
"Command 'file' given without a filename argument."),
194 "TExit102" ,
A_CHAR(
"File not found."),
195 "TExit103" ,
A_CHAR(
"Permission denied."),
196 "FNOTFND" ,
A_CHAR(
"The file {!Q} specified with command 'file' was not found."),
197 "FNOACC" ,
A_CHAR(
"Access denied to file {!Q} specified with command 'file'."),
198 "MSNGFNAME" ,
A_CHAR(
"Error: no filename given with command 'file'."),
#define ALIB_ASSERT_RESULT_EQUALS( func, value)
#define ALIB_CALLER_NULLED
#define ALIB_ALLOW_SWITCH_WITHOUT_DEFAULT
#define ALIB_LOCK_RECURSIVE_WITH(lock)
#define ALIB_POP_ALLOWANCE
static bool GetHelp(CommandLine &cmdLine, const String &topics, Paragraphs &text)
const Enum & Element() const
const String & Identifier()
bool Do(const NString &alibrcFileName, const NString &callingFile, Camp &campInstance, const NString &resourceCategory, bool allowReplacements, const NString &cppFileName)
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>".
strings::util::CalendarDateTime CalendarDateTime
Type alias in namespace #"%alib".
LocalString< 128 > String128
Type alias name for #"TLocalString;TLocalString<character,128>".
app::AppCamp APP
The singleton instance of the camp class used by class #"App".
format::Paragraphs Paragraphs
Type alias in namespace #"%alib".
time::DateTime DateTime
Type alias in namespace #"%alib".
A command argument of the command-line.
CommandDecl * Declaration
The underlying declaration.
ListMA< Parameter *, Recycling::Shared > ParametersMandatory
Mandatory parameters parsed.