47 virtual void Init(
void);
48 virtual int Run(
void);
49 virtual void Exit(
void);
67 arg_desc->SetUsageContext(
GetArguments().GetProgramBasename(),
68 "CArgDescriptions demo program");
71 arg_desc->AddOptionalPositional
73 "This is an optional named positional argument without default value",
79 "This is a flag argument: TRUE if set, FALSE if not set");
81 arg_desc->AddPositional
83 "This is a mandatory plain (named positional) argument",
85 arg_desc->SetConstraint
90 arg_desc->AddDefaultKey
92 "This is an optional integer key argument, with default value",
94 arg_desc->SetConstraint
100 "These are the optional extra (unnamed positional) arguments. "
101 "They will be printed out to the file specified by the "
102 "2nd positional argument,\n\"logfile\"",
106 (
"k",
"MandatoryKey",
107 "This is a mandatory alpha-num key argument",
109 arg_desc->SetConstraint
112 arg_desc->AddOptionalKey
113 (
"ko",
"OptionalKey",
114 "This is another optional key argument, without default value",
120 "This is another flag argument: FALSE if set, TRUE if not set",
123 arg_desc->AddDefaultPositional
125 "This is an optional named positional argument with default value",
127 arg_desc->SetConstraint
144 cout <<
string(72,
'=') << endl;
153 ostream* x_lg = args[
"logfile"] ? &args[
"logfile"].AsOutputFile() : &cout;
156 if ( args[
"logfile"] )
157 cout <<
"Printing arguments to file `"
158 << args[
"logfile"].AsString() <<
"'..." << endl;
161 lg <<
"k: " << args[
"k"].AsString() << endl;
162 lg <<
"barfooetc: " << args[
"barfooetc"].AsString() << endl;
163 if ( args[
"logfile"] )
164 lg <<
"logfile: " << args[
"logfile"].AsString() << endl;
170 if (!ko_values.empty()) {
172 for (
const auto& v: ko_values) {
179 lg <<
"ko: not provided" << endl;
182 (void) args[
"ko"].AsString();
191 _ASSERT(args[
"f1"].AsBoolean());
194 _ASSERT(args[
"f2"].AsBoolean());
199 for (
size_t extra = 1; extra <= args.
GetNExtra(); extra++) {
200 lg <<
"#" << extra <<
": "
202 <<
" (passed as `" << args[extra].AsString() <<
"')"
206 lg <<
"(no unnamed positional arguments passed in the cmd-line)" << endl;
210 lg <<
string(44,
'-') << endl;
int NcbiSys_main(int argc, ncbi::TXChar *argv[])
virtual int Run(void)
Run the application.
virtual void Init(void)
Initialize the application.
virtual void Exit(void)
Cleanup on application exit.
virtual const CArgs & GetArgs(void) const
Get parsed command line arguments.
int AppMain(int argc, const char *const *argv, const char *const *envp=0, EAppDiagStream diag=eDS_Default, const char *conf=NcbiEmptyCStr, const string &name=NcbiEmptyString)
Main function (entry point) for the NCBI application.
virtual void SetupArgDescriptions(CArgDescriptions *arg_desc)
Setup the command line argument descriptions.
const CNcbiArguments & GetArguments(void) const
Get the application's cached unprocessed command-line arguments.
string & Print(string &str) const
Print (append) all arguments to the string "str" and return "str".
bool Exist(const string &name) const
Check existence of argument description.
vector< string > TStringArray
Some values types can contain several value lists.
size_t GetNExtra(void) const
Get the number of unnamed positional (a.k.a. extra) args.
@ fAllowMultiple
Repeated key arguments are legal (use with AddKey)
@ fBinary
Open as binary file; for eInputFile, eOutputFile, eIOFile.
@ fPreOpen
Open file right away; for eInputFile, eOutputFile, eIOFile.
@ eBoolean
{'true', 't', 'false', 'f'}, case-insensitive
@ eString
An arbitrary string.
@ eOutputFile
Name of file (must be writable)
@ eInteger
Convertible into an integer number (int or Int8)
@ eAlnum
Alphanumeric characters.
@ eConstraint
Constraint is not inverted (taken as is)
#define NCBI_REPORT_EXCEPTION(title, ex)
Generate a report on the exception.
virtual const char * what(void) const noexcept
Standard report (includes full backlog).
static const string BoolToString(bool value)
Convert bool to string.
Defines the CNcbiApplication and CAppException classes for creating NCBI applications.
Defines command line argument related classes.
Defines unified interface to application:
static const char * str(char *buf, int n)