0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
get_property.cc
Go to the documentation of this file.
1 
22 #include "Common/Compat.h"
23 #include "Common/Init.h"
24 
25 #include "AsyncComm/Config.h"
26 
27 #include <iostream>
28 
29 using namespace Hypertable;
30 using namespace Config;
31 using namespace std;
32 
33 namespace {
34 
35  String lookup_property;
36 
37  const char *usage =
38  "\n"
39  "Usage: get_property [options] <property>\n\nOptions"
40  ;
41 
42  struct AppPolicy : Policy {
43  static void init_options() {
44  cmdline_desc(usage);
45  cmdline_hidden_desc().add_options()("property", str(), "");
46  cmdline_positional_desc().add("property", -1);
47  }
48  static void init() {
49  if (has("property"))
50  lookup_property = get_str("property");
51  }
52  };
53 
55 
56 } // local namespace
57 
58 #define TRY(exp, t) \
59  try { cout << exp; goto bail; } catch (Exception &e) { if (t) throw e; }
60 
61 int main(int argc, char **argv)
62 {
63  try {
64  init_with_policy<Policies>(argc, argv);
65  if (properties->has(lookup_property)) {
66  // issue 869: in order to avoid type conversion errors we have to try
67  // all available conversion functions
68  TRY(properties->get_str(lookup_property), false)
69  TRY(properties->get_bool(lookup_property), false)
70  TRY(properties->get_i16(lookup_property), false)
71  TRY(properties->get_i32(lookup_property), false)
72  TRY(properties->get_i64(lookup_property), false)
73  TRY(properties->get_f64(lookup_property), true)
74  }
75  else {
76  cout << lookup_property << "-PROPERTY-DOES-NOT-EXIST";
77  }
78  }
79  catch (Exception &e) {
80  HT_ERROR_OUT << e << HT_END;
81  }
82 
83 bail:
84  cout << flush;
85  quick_exit(EXIT_SUCCESS);
86 }
Declarations for configuration properties.
Interface and base of config policy.
Definition: Config.h:149
PropertiesPtr properties
This singleton map stores all options.
Definition: Config.cc:47
std::string String
A String is simply a typedef to std::string.
Definition: String.h:44
void init(int argc, char *argv[], const Desc *desc=NULL)
Initialize with default policy.
Definition: Init.h:95
Po::typed_value< String > * str(String *v=0)
Definition: Properties.h:166
STL namespace.
Desc & cmdline_desc(const char *usage)
A macro which definds global functions like get_bool(), get_str(), get_i16() etc. ...
Definition: Config.cc:72
bool has(const String &name)
Check existence of a configuration value.
Definition: Config.h:57
Helpers to compose init policies; allow to combine two policies into one.
Definition: Config.h:174
Compatibility Macros for C/C++.
Initialization helper for applications.
#define HT_END
Definition: Logger.h:220
#define HT_ERROR_OUT
Definition: Logger.h:301
#define TRY(exp, t)
Definition: get_property.cc:58
Hypertable definitions
int main(int argc, char **argv)
Definition: get_property.cc:61
Meta::list< MyPolicy, DefaultPolicy > Policies
This is a generic exception class for Hypertable.
Definition: Error.h:314
Desc & cmdline_hidden_desc()
Get the command line hidden options description (for positional options)
Definition: Config.cc:81
PositionalDesc & cmdline_positional_desc()
Get the command line positional options description.
Definition: Config.cc:90