| 602 | } |
| 603 | |
| 604 | int main(int argc, char *argv[]) |
| 605 | { |
| 606 | setup_locale(); |
| 607 | |
| 608 | int fd; |
| 609 | size_t off; |
| 610 | const char *method; |
| 611 | char *cmd, *resp, *idstr; |
| 612 | struct sockaddr_un addr; |
| 613 | jsmntok_t *toks; |
| 614 | const jsmntok_t *result, *error, *id; |
| 615 | const tal_t *ctx = tal(NULL, char); |
| 616 | char *config_filename, *lightning_dir, *net_dir, *rpc_filename; |
| 617 | jsmn_parser parser; |
| 618 | int parserr; |
| 619 | enum format format = DEFAULT_FORMAT; |
| 620 | enum input input = DEFAULT_INPUT; |
| 621 | enum log_level notification_level = LOG_INFORM; |
| 622 | bool last_was_progress = false; |
| 623 | char *command = NULL; |
| 624 | |
| 625 | err_set_progname(argv[0]); |
| 626 | jsmn_init(&parser); |
| 627 | |
| 628 | tal_set_backend(NULL, NULL, NULL, tal_error); |
| 629 | |
| 630 | setup_option_allocators(); |
| 631 | |
| 632 | initial_config_opts(ctx, argc, argv, |
| 633 | &config_filename, &lightning_dir, &net_dir, |
| 634 | &rpc_filename); |
| 635 | |
| 636 | opt_register_noarg("--help|-h", opt_usage_and_exit, |
| 637 | "<command> [<params>...]", "Show this message. Use the command help (without hyphens -- \"lightning-cli help\") to get a list of all RPC commands"); |
| 638 | opt_register_noarg("-H|--human-readable", opt_set_human, &format, |
| 639 | "Human-readable output"); |
| 640 | opt_register_noarg("-F|--flat", opt_set_flat, &format, |
| 641 | "Flatten output ('x.y.x=' format)"); |
| 642 | opt_register_noarg("-J|--json", opt_set_json, &format, |
| 643 | "JSON output (default unless 'help')"); |
| 644 | opt_register_noarg("-R|--raw", opt_set_raw, &format, |
| 645 | "Raw, unformatted JSON output"); |
| 646 | opt_register_noarg("-k|--keywords", opt_set_keywords, &input, |
| 647 | "Use format key=value for <params>"); |
| 648 | opt_register_noarg("-o|--order", opt_set_ordered, &input, |
| 649 | "Use params in order for <params>"); |
| 650 | opt_register_arg("-N|--notifications", opt_set_level, |
| 651 | opt_show_level, ¬ification_level, |
| 652 | "Set notification level, or none"); |
| 653 | |
| 654 | opt_register_version(); |
| 655 | |
| 656 | opt_early_parse(argc, argv, opt_log_stderr_exit); |
| 657 | opt_parse(&argc, argv, opt_log_stderr_exit); |
| 658 | |
| 659 | method = argv[1]; |
| 660 | if (!method) { |
| 661 | char *usage = opt_usage(argv[0], NULL); |
nothing calls this directly
no test coverage detected