Zeth - Zerocash on Ethereum  0.8
Reference implementation of the Zeth protocol by Clearmatics
subcommand.hpp
Go to the documentation of this file.
1 // Copyright (c) 2015-2022 Clearmatics Technologies Ltd
2 //
3 // SPDX-License-Identifier: LGPL-3.0+
4 
5 #ifndef __ZETH_LIBTOOL_SUBCOMMAND_HPP__
6 #define __ZETH_LIBTOOL_SUBCOMMAND_HPP__
7 
8 #include <boost/program_options.hpp>
9 #include <map>
10 #include <string>
11 
12 namespace po = boost::program_options;
13 
14 namespace libtool
15 {
16 
18 template<typename GlobalOptionsT> class subcommand
19 {
20 public:
21  subcommand(
22  const std::string &subcommand_name, const std::string &description);
23  virtual ~subcommand();
24  const std::string &description() const;
25 
27  int execute(
28  const char *argv0,
29  const std::vector<std::string> command_args,
30  const GlobalOptionsT &global);
31 
32 protected:
33  void usage(
34  const char *argv0,
35  const boost::program_options::options_description &options);
36 
38  virtual void initialize_suboptions(
39  boost::program_options::options_description &options,
40  boost::program_options::options_description &all_options,
41  boost::program_options::positional_options_description &pos) = 0;
42 
45  virtual void parse_suboptions(
46  const boost::program_options::variables_map &vm) = 0;
47 
49  virtual void subcommand_usage(const char *argv0) = 0;
50 
52  virtual int execute_subcommand(const GlobalOptionsT &global) = 0;
53 
54  std::string subcommand_name;
56 };
57 
58 } // namespace libtool
59 
60 #include "libtool/subcommand.tcc"
61 
62 #endif // __ZETH_LIBTOOL_SUBCOMMAND_HPP__
libtool::subcommand::initialize_suboptions
virtual void initialize_suboptions(boost::program_options::options_description &options, boost::program_options::options_description &all_options, boost::program_options::positional_options_description &pos)=0
Instantiation can now set up the boost program_options structures.
libtool::subcommand::description
const std::string & description() const
libtool::subcommand::~subcommand
virtual ~subcommand()
libtool::subcommand::usage
void usage(const char *argv0, const boost::program_options::options_description &options)
libtool::subcommand::subcommand_description
std::string subcommand_description
Definition: subcommand.hpp:55
libtool::subcommand::execute
int execute(const char *argv0, const std::vector< std::string > command_args, const GlobalOptionsT &global)
Common code to parse options and invoke the virtual execute entrypoint.
libtool
Utilities that are likely to be useful for command line tools.
Definition: command.hpp:10
libtool::subcommand::subcommand_name
std::string subcommand_name
Definition: subcommand.hpp:54
libtool::subcommand::subcommand_usage
virtual void subcommand_usage(const char *argv0)=0
Any command-specific output for usage.
subcommand.tcc
libtool::subcommand::parse_suboptions
virtual void parse_suboptions(const boost::program_options::variables_map &vm)=0
libtool::subcommand::execute_subcommand
virtual int execute_subcommand(const GlobalOptionsT &global)=0
Execute the command using global options defined by the caller.
libtool::subcommand::subcommand
subcommand(const std::string &subcommand_name, const std::string &description)
libtool::subcommand
Class representing a tool subcommand.
Definition: subcommand.hpp:18