| 1 |
/* |
| 2 |
Copyright 2019 Google Inc. All rights reserved. |
| 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 |
|
| 17 |
#ifndef JSONNET_CMD_UTILS_H |
| 18 |
#define JSONNET_CMD_UTILS_H |
| 19 |
|
| 20 |
#include <string> |
| 21 |
#include <vector> |
| 22 |
|
| 23 |
/** Like std::strtol with base 10 but exits the program if str is not a number. |
| 24 |
*/ |
| 25 |
long strtol_check(const std::string &str); |
| 26 |
|
| 27 |
/** Advances i and returns args[i]. |
| 28 |
* Exits the program if args is not large enough. |
| 29 |
*/ |
| 30 |
std::string next_arg(unsigned &i, const std::vector<std::string> &args); |
| 31 |
|
| 32 |
/** Collect commandline args into a vector of strings, and expand -foo to -f -o -o. */ |
| 33 |
std::vector<std::string> simplify_args(int argc, const char **argv); |
| 34 |
|
| 35 |
/** Reads from the input file or stdin into the input buffer. */ |
| 36 |
bool read_input_content(std::string filename, std::string *input); |
| 37 |
|
| 38 |
/** Changes filename for stdin and filename_is_code case. */ |
| 39 |
void change_special_filename(bool filename_is_code, std::string *filename); |
| 40 |
|
| 41 |
/** Gets Jsonnet code from any source into the input buffer and changes |
| 42 |
* the filename if it's not an actual filename (e.g. "-"). */ |
| 43 |
bool read_input( |
| 44 |
bool filename_is_code, std::string *filename, std::string *input); |
| 45 |
|
| 46 |
/** Writes the output text to the specified output file. |
| 47 |
*/ |
| 48 |
bool write_output_file(const char *output, const std::string &output_file); |
| 49 |
|
| 50 |
#endif |