proxygen
Shell.h
Go to the documentation of this file.
1 /*
2  * Copyright 2016-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
25 #pragma once
26 
27 #include <string>
28 #include <vector>
29 
30 #include <folly/Conv.h>
31 #include <folly/Format.h>
32 #include <folly/Range.h>
33 
34 namespace folly {
35 
40 
41 namespace detail {
42 template <typename... Arguments>
43 std::vector<std::string> shellify(
45  Arguments&&... arguments) {
46  auto command = sformat(
47  format,
48  shellQuote(to<std::string>(std::forward<Arguments>(arguments)))...);
49  return {"/bin/sh", "-c", command};
50 }
51 
54  template <typename... Arguments>
55  std::vector<std::string> operator()(Arguments&&... arguments) const {
57  format, std::forward<Arguments>(arguments)...);
58  }
59 };
60 
61 } // namespace detail
62 
63 inline namespace literals {
64 inline namespace shell_literals {
65 constexpr detail::ShellCmdFormat operator"" _shellify(
66  char const* name,
67  std::size_t length) {
68  return {folly::StringPiece(name, length)};
69 }
70 } // namespace shell_literals
71 } // namespace literals
72 
83 // clang-format off
84 template <typename... Arguments>
85 [[deprecated(
86  "Use `\"command {} {} ...\"_shellify(argument1, argument2 ...)` from "
87  "namespace `folly::literals::shell_literals`")]]
88 std::vector<std::string> shellify(
90  Arguments&&... arguments) {
91  return detail::shellify(format, std::forward<Arguments>(arguments)...);
92 }
93 // clang-format on
94 
95 } // namespace folly
std::vector< std::string > operator()(Arguments &&...arguments) const
Definition: Shell.h:55
std::vector< std::string > shellify(StringPiece format, Arguments &&...arguments)
Definition: Shell.h:88
std::string sformat(StringPiece fmt, Args &&...args)
Definition: Format.h:280
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
std::vector< std::string > shellify(StringPiece format, Arguments &&...arguments)
Definition: Shell.h:43
const char * name
Definition: http_parser.c:437
std::string shellQuote(StringPiece argument)
Definition: Shell.cpp:21
const char * string
Definition: Conv.cpp:212
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
Definition: Format.h:271
Range< const char * > StringPiece