0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ht_expand_hostspec.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
22 #include <Common/Compat.h>
23 #include <Common/Error.h>
25 #include <Common/String.h>
26 
27 #include <iostream>
28 #include <string>
29 #include <vector>
30 
31 using namespace Hypertable;
32 using namespace std;
33 
34 namespace {
35  void dump_usage_and_exit() {
36  cout << endl;
37  cout << "usage: ht_expand_hostspec <host-specification>" << endl;
38  cout << endl;
39  cout << "This program expands a host specification into a" << endl;
40  cout << "space-separated list of host names." << endl;
41  cout << endl;
42  quick_exit(EXIT_FAILURE);
43  }
44 }
45 
49 
50 int main(int argc, char **argv) {
51 
52  if (argc < 2)
53  dump_usage_and_exit();
54 
55  string spec;
56  for (int i=1; i<argc; i++)
57  spec.append(format(" (%s)", argv[i]));
58 
59  try {
60  vector<string> hosts = HostSpecification(spec);
61  bool first = true;
62  for (auto & host : hosts) {
63  if (!first)
64  cout << " ";
65  cout << host;
66  first = false;
67  }
68  cout << endl;
69  }
70  catch (Exception &e) {
71  cout << Error::get_text(e.code()) << " - " << e.what() << endl;
72  quick_exit(EXIT_FAILURE);
73  }
74 
75  quick_exit(EXIT_SUCCESS);
76 }
Declarations for HostSpecification.
Converts host specification pattern to list of host names.
String format(const char *fmt,...)
Returns a String using printf like format facilities Vanilla snprintf is about 1.5x faster than this...
Definition: String.cc:37
STL namespace.
int main(int argc, char **argv)
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
Compatibility Macros for C/C++.
Hypertable definitions
This is a generic exception class for Hypertable.
Definition: Error.h:314
A String class based on std::string.
Error codes, Exception handling, error logging.
int code() const
Returns the error code.
Definition: Error.h:391