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 38 #include "utils/cmdline/base_command.hpp" 39 #include "utils/cmdline/options.hpp" 40 #include "utils/cmdline/parser.hpp" 41 #include "utils/cmdline/ui.hpp" 42 #include "utils/config/tree.hpp" 43 #include "utils/datetime.hpp" 44 #include "utils/fs/path.hpp" 45 #include "utils/optional.hpp" 46 47 namespace utils { 48 namespace fs { 49 class path; 50 } // namespace fs 51 } // namespace utils 52 53 namespace engine { 54 struct test_filter; 55 class test_case; 56 class test_result; 57 } // namespace engine 58 59 namespace cli { 60 61 62 extern const utils::cmdline::path_option build_root_option; 63 extern const utils::cmdline::path_option kyuafile_option; 64 extern const utils::cmdline::path_option store_option; 65 extern const utils::cmdline::property_option variable_option; 66 67 68 /// Base type for commands defined in the cli module. 69 /// 70 /// All commands in Kyua receive a configuration object as their runtime 71 /// data parameter because the configuration file applies to all the 72 /// commands. 73 typedef utils::cmdline::base_command< utils::config::tree > cli_command; 74 75 76 /// Scoped, strictly owned pointer to a cli_command. 77 typedef std::auto_ptr< cli_command > cli_command_ptr; 78 79 80 utils::optional< utils::fs::path > get_home(void); 81 82 utils::optional< utils::fs::path > build_root_path( 83 const utils::cmdline::parsed_cmdline&); 84 utils::fs::path kyuafile_path(const utils::cmdline::parsed_cmdline&); 85 utils::fs::path store_path(const utils::cmdline::parsed_cmdline&); 86 87 std::set< engine::test_filter > parse_filters( 88 const utils::cmdline::args_vector&); 89 bool report_unused_filters(const std::set< engine::test_filter >&, 90 utils::cmdline::ui*); 91 92 std::string format_delta(const utils::datetime::delta&); 93 std::string format_result(const engine::test_result&); 94 std::string format_test_case_id(const engine::test_case&); 95 std::string format_test_case_id(const engine::test_filter&); 96 97 98 } // namespace cli 99 100 #endif // !defined(CLI_COMMON_HPP) 101