xref: /netbsd/external/bsd/kyua-cli/dist/cli/common.hpp (revision ab619639)
1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 //   notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 //   notice, this list of conditions and the following disclaimer in the
12 //   documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 //   may be used to endorse or promote products derived from this software
15 //   without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 /// \file cli/common.hpp
30 /// Utility functions to implement CLI subcommands.
31 
32 #if !defined(CLI_COMMON_HPP)
33 #define CLI_COMMON_HPP
34 
35 #include <memory>
36 #include <set>
37 #include <vector>
38 
39 #include "engine/test_result.hpp"
40 #include "utils/cmdline/base_command.hpp"
41 #include "utils/cmdline/options.hpp"
42 #include "utils/cmdline/parser.hpp"
43 #include "utils/cmdline/ui.hpp"
44 #include "utils/config/tree.hpp"
45 #include "utils/datetime.hpp"
46 #include "utils/fs/path.hpp"
47 #include "utils/optional.hpp"
48 
49 namespace utils {
50 namespace fs {
51 class path;
52 }  // namespace fs
53 }  // namespace utils
54 
55 namespace engine {
56 class test_case;
57 class test_filter;
58 }  // namespace engine
59 
60 namespace cli {
61 
62 
63 extern const utils::cmdline::path_option build_root_option;
64 extern const utils::cmdline::path_option kyuafile_option;
65 extern const utils::cmdline::list_option results_filter_option;
66 extern const utils::cmdline::path_option store_option;
67 extern const utils::cmdline::property_option variable_option;
68 
69 
70 /// Base type for commands defined in the cli module.
71 ///
72 /// All commands in Kyua receive a configuration object as their runtime
73 /// data parameter because the configuration file applies to all the
74 /// commands.
75 typedef utils::cmdline::base_command< utils::config::tree > cli_command;
76 
77 
78 /// Scoped, strictly owned pointer to a cli_command.
79 typedef std::unique_ptr< cli_command > cli_command_ptr;
80 
81 
82 /// Collection of result types.
83 ///
84 /// This is a vector rather than a set because we want to respect the order in
85 /// which the user provided the types.
86 typedef std::vector< engine::test_result::result_type > result_types;
87 
88 
89 utils::optional< utils::fs::path > get_home(void);
90 
91 utils::optional< utils::fs::path > build_root_path(
92     const utils::cmdline::parsed_cmdline&);
93 utils::fs::path kyuafile_path(const utils::cmdline::parsed_cmdline&);
94 result_types get_result_types(const utils::cmdline::parsed_cmdline&);
95 utils::fs::path store_path(const utils::cmdline::parsed_cmdline&);
96 
97 std::set< engine::test_filter > parse_filters(
98     const utils::cmdline::args_vector&);
99 bool report_unused_filters(const std::set< engine::test_filter >&,
100                            utils::cmdline::ui*);
101 
102 std::string format_delta(const utils::datetime::delta&);
103 std::string format_result(const engine::test_result&);
104 std::string format_test_case_id(const engine::test_case&);
105 std::string format_test_case_id(const engine::test_filter&);
106 
107 
108 }  // namespace cli
109 
110 #endif  // !defined(CLI_COMMON_HPP)
111