| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <iostream> |
| 14 |
#include <vector> |
| 15 |
|
| 16 |
#include "eckit/option/CmdArgs.h" |
| 17 |
#include "eckit/option/Separator.h" |
| 18 |
#include "eckit/option/SimpleOption.h" |
| 19 |
#include "eckit/option/VectorOption.h" |
| 20 |
#include "eckit/runtime/Tool.h" |
| 21 |
|
| 22 |
#include "atlas/library/Library.h" |
| 23 |
#include "atlas/parallel/mpi/mpi.h" |
| 24 |
#include "atlas/runtime/Log.h" |
| 25 |
#include "atlas/util/Config.h" |
| 26 |
|
| 27 |
//-------------------------------------------------------------------------------- |
| 28 |
|
| 29 |
using atlas::util::Config; |
| 30 |
using eckit::option::CmdArgs; |
| 31 |
using eckit::option::Option; |
| 32 |
using eckit::option::Separator; |
| 33 |
using eckit::option::SimpleOption; |
| 34 |
using eckit::option::VectorOption; |
| 35 |
|
| 36 |
namespace atlas { |
| 37 |
|
| 38 |
class AtlasTool : public eckit::Tool { |
| 39 |
public: |
| 40 |
typedef std::vector<eckit::option::Option*> Options; |
| 41 |
typedef eckit::option::CmdArgs Args; |
| 42 |
|
| 43 |
protected: |
| 44 |
virtual bool serial() { return false; } |
| 45 |
virtual std::string indent() { return " "; } |
| 46 |
virtual std::string briefDescription() { return ""; } |
| 47 |
virtual std::string longDescription() { return ""; } |
| 48 |
virtual std::string usage() { return name() + " [OPTION]... [--help,-h] [--debug]"; } |
| 49 |
|
| 50 |
void add_option(eckit::option::Option* option); |
| 51 |
|
| 52 |
virtual void help(std::ostream& out = Log::info()); |
| 53 |
|
| 54 |
virtual int numberOfPositionalArguments() { return -1; } |
| 55 |
virtual int minimumPositionalArguments() { return 0; } |
| 56 |
|
| 57 |
bool handle_help(); |
| 58 |
|
| 59 |
std::string get_positional_arg(const Args&, size_t pos) const; |
| 60 |
|
| 61 |
public: |
| 62 |
AtlasTool(int argc, char** argv); |
| 63 |
|
| 64 |
int start(); |
| 65 |
|
| 66 |
virtual void run(); // unused |
| 67 |
|
| 68 |
virtual int execute(const Args&) = 0; |
| 69 |
|
| 70 |
static constexpr int success() { return 0; } |
| 71 |
static constexpr int failed() { return 1; } |
| 72 |
|
| 73 |
private: |
| 74 |
void setupLogging(); |
| 75 |
|
| 76 |
private: |
| 77 |
Options options_; |
| 78 |
}; |
| 79 |
|
| 80 |
} // namespace atlas |