pycontribs / ansi2html

Convert text with ansi color codes to HTML
GNU Lesser General Public License v3.0
389 stars 78 forks source link

[>=1.9.1] Fix output for `--help` #236

Closed nehaljwani closed 10 months ago

nehaljwani commented 11 months ago

The output for --help after #205 started to error out:

(dev) /t/s/1703528681 ❯❯❯ ansi2html -h
Traceback (most recent call last):
  File "/private/tmp/scratch.nwani/1703528681/dev/bin/ansi2html", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/private/tmp/scratch.nwani/1703528681/dev/lib/python3.11/site-packages/ansi2html/converter.py", line 783, in main
    opts = parser.parse_args()
           ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1869, in parse_args
    args, argv = self.parse_known_args(args, namespace)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1902, in parse_known_args
    namespace, args = self._parse_known_args(args, namespace)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2114, in _parse_known_args
    start_index = consume_optional(start_index)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2054, in consume_optional
    take_action(action, args, option_string)
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1978, in take_action
    action(self, namespace, argument_values, option_string)
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 1119, in __call__
    parser.print_help()
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2601, in print_help
    self._print_message(self.format_help(), file)
                        ^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 2585, in format_help
    return formatter.format_help()
           ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 286, in format_help
    help = self._root_section.format_help()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in format_help
    item_help = join([func(*args) for func, args in self.items])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
                      ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in format_help
    item_help = join([func(*args) for func, args in self.items])
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 217, in <listcomp>
    item_help = join([func(*args) for func, args in self.items])
                      ^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 543, in _format_action
    help_text = self._expand_help(action)
                ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/python@3.11/3.11.3/Frameworks/Python.framework/Versions/3.11/lib/python3.11/argparse.py", line 640, in _expand_help
    return self._get_help_string(action) % params
           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~
TypeError: %d format: a real number is required, not dict

With this patch, the output is sane:

(dev) /t/s/1703528681 ❯❯❯ ansi2html --help
usage:
    $ ls --color=always | ansi2html > directories.html
    $ sudo tail /var/log/messages | ccze -A | ansi2html > logs.html
    $ task burndown | ansi2html > burndown.html

options:
  -h, --help            show this help message and exit
  -V, --version         show program's version number and exit
  -p, --partial         Process lines as them come in.  No headers are produced.
  -L, --latex           Export as LaTeX instead of HTML.
  -i, --inline          Inline style without headers or template.
  -H, --headers         Just produce the <style> tag.
  -f SIZE, --font-size SIZE
                        Set the global font size in the output.
  -l, --light-background
                        Set output to 'light background' mode.
  -W, --no-line-wrap    Disable line wrapping.
  -a, --linkify         Transform URLs into <a> links.
  -u, --unescape        Do not escape XML tags found in the input.
  -m, --markup-lines    Surround lines with <span id='line-n'>..</span>.
  --input-encoding ENCODING
                        Specify input encoding
  --output-encoding ENCODING
                        Specify output encoding
  -s SCHEME, --scheme SCHEME
                        Specify color palette scheme. Default: ansi2html.
                        Choices: ['ansi2html', 'dracula', 'mint-terminal', 'osx', 'osx-basic', 'osx-solid-colors', 'solarized', 'xterm']
  -t OUTPUT_TITLE, --title OUTPUT_TITLE
                        Specify output title
nehaljwani commented 10 months ago

Hi @hartwork, I've updated the PR with the proposed fix.

isidroas commented 9 months ago

Could this fix be uploaded to pypi.org?

The last version is 1.9.1 from Dec 11, 2023

hartwork commented 9 months ago

@isidroas my hands are tied, this needs @ssbarnea

phlummox commented 5 months ago

@hartwork, is it possible to at least make a new release on GitHub? That makes it possible to do a pip install based on that release, which many might feel more comfortable with than just depending on the main branch. I'm not sure whether that would require @ssbarnea's intervention or not.

hartwork commented 5 months ago

@phlummox I lack permissions to…

…but it seems I can

With that it seems I managed to release 1.9.2 to both PyPI (through GitHub Actions) and GitHub releases now.

I should not that workflow push.yml is broken

broken_push_Screenshot_20240622_193940

…because the referenced target…

https://github.com/pycontribs/ansi2html/blob/a3a93a65e9b98f6c27b3fae1ea47974f3bb0860a/.github/workflows/push.yml#L13

…apparently no longer exists at that location. If you can help with a pull request to repair, I may be able to approve and merge it. Any chance?