2 * This file is open source software, licensed to you under the terms
3 * of the Apache License, Version 2.0 (the "License"). See the NOTICE file
4 * distributed with this work for additional information regarding copyright
5 * ownership. You may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing,
12 * software distributed under the License is distributed on an
13 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14 * KIND, either express or implied. See the License for the
15 * specific language governing permissions and limitations
19 * Copyright (C) 2014 Cloudius Systems, Ltd.
23 #include <boost/program_options.hpp>
25 #include <seastar/core/future.hh>
26 #include <seastar/core/sstring.hh>
34 /// The name of the application.
36 /// Will be used in the --help output to distinguish command line args
37 /// registered by the application, as opposed to those registered by
38 /// seastar and its subsystems.
40 /// The description of the application.
42 /// Will be printed on the top of the --help output. Lines should be
43 /// hard-wrapped for 80 chars.
44 sstring description = "";
45 std::chrono::duration<double> default_task_quota = std::chrono::microseconds(500);
46 /// \brief Handle SIGINT/SIGTERM by calling reactor::stop()
48 /// When true, Seastar will set up signal handlers for SIGINT/SIGTERM that call
49 /// reactor::stop(). The reactor will then execute callbacks installed by
50 /// reactor::at_exit().
52 /// When false, Seastar will not set up signal handlers for SIGINT/SIGTERM
53 /// automatically. The default behavior (terminate the program) will be kept.
54 /// You can adjust the behavior of SIGINT/SIGTERM by installing signal handlers
55 /// via reactor::handle_signal().
56 bool auto_handle_sigint_sigterm = true;
60 using configuration_reader = std::function<void (boost::program_options::variables_map&)>;
63 boost::program_options::options_description _opts;
64 boost::program_options::options_description _opts_conf_file;
65 boost::program_options::positional_options_description _pos_opts;
66 std::optional<boost::program_options::variables_map> _configuration;
67 configuration_reader _conf_reader;
69 configuration_reader get_default_configuration_reader();
71 struct positional_option {
73 const boost::program_options::value_semantic* value_semantic;
78 explicit app_template(config cfg = config());
80 boost::program_options::options_description& get_options_description();
81 boost::program_options::options_description& get_conf_file_options_description();
82 boost::program_options::options_description_easy_init add_options();
83 void add_positional_options(std::initializer_list<positional_option> options);
84 boost::program_options::variables_map& configuration();
85 int run_deprecated(int ac, char ** av, std::function<void ()>&& func);
87 void set_configuration_reader(configuration_reader conf_reader);
89 // Runs given function and terminates the application when the future it
90 // returns resolves. The value with which the future resolves will be
91 // returned by this function.
92 int run(int ac, char ** av, std::function<future<int> ()>&& func);
94 // Like run() which takes std::function<future<int>()>, but returns
95 // with exit code 0 when the future returned by func resolves
97 int run(int ac, char ** av, std::function<future<> ()>&& func);