| 1670 | } |
| 1671 | |
| 1672 | void |
| 1673 | crm_help(char cmd, int exit_code) |
| 1674 | { |
| 1675 | int i = 0; |
| 1676 | FILE *stream = (exit_code ? stderr : stdout); |
| 1677 | |
| 1678 | if (cmd == 'v' || cmd == '$') { |
| 1679 | fprintf(stream, "Pacemaker %s\n", VERSION); |
| 1680 | fprintf(stream, "Written by Andrew Beekhof\n"); |
| 1681 | goto out; |
| 1682 | } |
| 1683 | |
| 1684 | if (cmd == '!') { |
| 1685 | fprintf(stream, "Pacemaker %s (Build: %s): %s\n", VERSION, BUILD_VERSION, CRM_FEATURES); |
| 1686 | goto out; |
| 1687 | } |
| 1688 | |
| 1689 | fprintf(stream, "%s - %s\n", crm_system_name, crm_app_description); |
| 1690 | |
| 1691 | if (crm_app_usage) { |
| 1692 | fprintf(stream, "Usage: %s %s\n", crm_system_name, crm_app_usage); |
| 1693 | } |
| 1694 | |
| 1695 | if (crm_long_options) { |
| 1696 | fprintf(stream, "Options:\n"); |
| 1697 | for (i = 0; crm_long_options[i].name != NULL; i++) { |
| 1698 | if (crm_long_options[i].flags & pcmk_option_hidden) { |
| 1699 | |
| 1700 | } else if (crm_long_options[i].flags & pcmk_option_paragraph) { |
| 1701 | fprintf(stream, "%s\n\n", crm_long_options[i].desc); |
| 1702 | |
| 1703 | } else if (crm_long_options[i].flags & pcmk_option_example) { |
| 1704 | fprintf(stream, "\t#%s\n\n", crm_long_options[i].desc); |
| 1705 | |
| 1706 | } else if (crm_long_options[i].val == '-' && crm_long_options[i].desc) { |
| 1707 | fprintf(stream, "%s\n", crm_long_options[i].desc); |
| 1708 | |
| 1709 | } else { |
| 1710 | /* is val printable as char ? */ |
| 1711 | if (crm_long_options[i].val && crm_long_options[i].val <= UCHAR_MAX) { |
| 1712 | fprintf(stream, " -%c,", crm_long_options[i].val); |
| 1713 | } else { |
| 1714 | fputs(" ", stream); |
| 1715 | } |
| 1716 | fprintf(stream, " --%s%c%s\t%s\n", crm_long_options[i].name, |
| 1717 | crm_long_options[i].has_arg ? '=' : ' ', |
| 1718 | crm_long_options[i].has_arg ? "value" : "", |
| 1719 | crm_long_options[i].desc ? crm_long_options[i].desc : ""); |
| 1720 | } |
| 1721 | } |
| 1722 | |
| 1723 | } else if (crm_short_options) { |
| 1724 | fprintf(stream, "Usage: %s - %s\n", crm_system_name, crm_app_description); |
| 1725 | for (i = 0; crm_short_options[i] != 0; i++) { |
| 1726 | int has_arg = FALSE; |
| 1727 | |
| 1728 | if (crm_short_options[i + 1] == ':') { |
| 1729 | has_arg = TRUE; |