mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-27 05:13:10 +00:00
fish_indent: Change --debug-level to --debug with flog categories
The "debug-level" flag makes little sense since we have no more debug *levels* left.
This commit is contained in:
parent
e8dcef5a71
commit
6e9364ab50
3 changed files with 33 additions and 5 deletions
|
@ -30,6 +30,8 @@ The following options are available:
|
|||
|
||||
- ``--html`` outputs HTML, which supports syntax highlighting if the appropriate CSS is defined. The CSS class names are the same as the variable names, such as ``fish_color_command``.
|
||||
|
||||
- ``-d`` or ``--debug-level=DEBUG_LEVEL`` enables debug output and specifies a verbosity level. Defaults to 0.
|
||||
- ``-d`` or ``--debug=DEBUG_CATEGORIES`` enable debug output and specify a pattern for matching debug categories. See :ref:`Debugging <debugging-fish>` in :ref:`fish(1) <cmd-fish>` for details.
|
||||
|
||||
- ``-o`` or ``--debug-output=DEBUG_FILE`` specify a file path to receive the debug output, including categories and ``fish_trace``. The default is stderr.
|
||||
|
||||
- ``--dump-parse-tree`` dumps information about the parsed statements to stderr. This is likely to be of interest only to people working on the fish source code.
|
||||
|
|
|
@ -4,6 +4,7 @@ complete -c fish_indent -s i -l no-indent -d 'Do not indent output, only reforma
|
|||
complete -c fish_indent -l ansi -d 'Colorize the output using ANSI escape sequences'
|
||||
complete -c fish_indent -l html -d 'Output in HTML format'
|
||||
complete -c fish_indent -s w -l write -d 'Write to file'
|
||||
complete -c fish_indent -s d -l debug-level -x -d 'Enable debug at specified verbosity level'
|
||||
complete -c fish_indent -s d -l debug -x -d 'Enable debug at specified verbosity level'
|
||||
complete -c fish_indent -s o -l debug-output -d "Where to direct debug output to" -rF
|
||||
complete -c fish_indent -s D -l debug-stack-frames -x -d 'Specify how many stack frames to display in debug messages'
|
||||
complete -c fish_indent -l dump-parse-tree -d 'Dump information about parsed statements to stderr'
|
||||
|
|
|
@ -858,9 +858,12 @@ int main(int argc, char *argv[]) {
|
|||
} output_type = output_type_plain_text;
|
||||
const char *output_location = "";
|
||||
bool do_indent = true;
|
||||
// File path for debug output.
|
||||
std::string debug_output;
|
||||
|
||||
const char *short_opts = "+d:hvwicD:";
|
||||
const struct option long_opts[] = {{"debug-level", required_argument, nullptr, 'd'},
|
||||
const struct option long_opts[] = {{"debug", required_argument, nullptr, 'd'},
|
||||
{"debug-output", required_argument, nullptr, 'o'},
|
||||
{"debug-stack-frames", required_argument, nullptr, 'D'},
|
||||
{"dump-parse-tree", no_argument, nullptr, 'P'},
|
||||
{"no-indent", no_argument, nullptr, 'i'},
|
||||
|
@ -922,8 +925,12 @@ int main(int argc, char *argv[]) {
|
|||
if (tmp >= 0 && tmp <= 10 && !*end && !errno) {
|
||||
debug_level = static_cast<int>(tmp);
|
||||
} else {
|
||||
std::fwprintf(stderr, _(L"Invalid value '%s' for debug-level flag"), optarg);
|
||||
exit(1);
|
||||
activate_flog_categories_by_pattern(str2wcstring(optarg));
|
||||
}
|
||||
for (auto cat : get_flog_categories()) {
|
||||
if (cat->enabled) {
|
||||
printf("Debug enabled for category: %ls\n", cat->name);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -932,6 +939,10 @@ int main(int argc, char *argv[]) {
|
|||
// Either remove it or make it work with FLOG.
|
||||
break;
|
||||
}
|
||||
case 'o': {
|
||||
debug_output = optarg;
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
// We assume getopt_long() has already emitted a diagnostic msg.
|
||||
exit(1);
|
||||
|
@ -942,6 +953,20 @@ int main(int argc, char *argv[]) {
|
|||
argc -= optind;
|
||||
argv += optind;
|
||||
|
||||
// Direct any debug output right away.
|
||||
FILE *debug_output_file = nullptr;
|
||||
if (!debug_output.empty()) {
|
||||
debug_output_file = fopen(debug_output.c_str(), "w");
|
||||
if (!debug_output_file) {
|
||||
fprintf(stderr, "Could not open file %s\n", debug_output.c_str());
|
||||
perror("fopen");
|
||||
exit(-1);
|
||||
}
|
||||
set_cloexec(fileno(debug_output_file));
|
||||
setlinebuf(debug_output_file);
|
||||
set_flog_output_file(debug_output_file);
|
||||
}
|
||||
|
||||
int retval = 0;
|
||||
|
||||
wcstring src;
|
||||
|
|
Loading…
Reference in a new issue