]> git.proxmox.com Git - ceph.git/blob - ceph/src/librados-config.cc
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / librados-config.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2004-2006 Sage Weil <sage@newdream.net>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public
10 * License version 2, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include "common/config.h"
16
17 #include "common/ceph_argparse.h"
18 #include "global/global_init.h"
19 #include "global/global_context.h"
20 #include "include/rados/librados.h"
21
22 void usage()
23 {
24 cout << "usage: librados-config [option]\n"
25 << "where options are:\n"
26 << " --version library version\n"
27 << " --vernum library version code\n";
28 }
29
30 void usage_exit()
31 {
32 usage();
33 exit(1);
34 }
35
36 int main(int argc, const char **argv)
37 {
38 vector<const char*> args;
39 argv_to_vec(argc, argv, args);
40 if (args.empty()) {
41 cerr << argv[0] << ": -h or --help for usage" << std::endl;
42 exit(1);
43 }
44 if (ceph_argparse_need_usage(args)) {
45 usage();
46 exit(0);
47 }
48
49 bool opt_version = false;
50 bool opt_vernum = false;
51
52 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
53 CODE_ENVIRONMENT_UTILITY,
54 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
55 common_init_finish(g_ceph_context);
56 for (std::vector<const char*>::iterator i = args.begin();
57 i != args.end(); ) {
58 if (strcmp(*i, "--") == 0) {
59 break;
60 }
61 else if (strcmp(*i, "--version") == 0) {
62 opt_version = true;
63 i = args.erase(i);
64 }
65 else if (strcmp(*i, "--vernum") == 0) {
66 opt_vernum = true;
67 i = args.erase(i);
68 }
69 else
70 ++i;
71 }
72
73 if (!opt_version && !opt_vernum)
74 usage_exit();
75
76 if (opt_version) {
77 int maj, min, ext;
78 rados_version(&maj, &min, &ext);
79 cout << maj << "." << min << "." << ext << std::endl;
80 } else if (opt_vernum) {
81 cout << hex << LIBRADOS_VERSION_CODE << dec << std::endl;
82 }
83
84 return 0;
85 }
86