rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Quiet mode for real info #107

Closed LeResKP closed 10 months ago

LeResKP commented 11 months ago

Hello,

Would it be possible to have an option to don't print info ?

These 2 info are printed on stderr on each run, it's not really easy to detect if it's a real error message without parsing the output.

    _info(f"{changed_files} template{s} {have} been reindented.")
    if unchanged_files:
        s = "s" if unchanged_files != 1 else ""
        were = "were" if s else "was"
        _info(f"{unchanged_files} template{s} {were} already perfect!")

I saw there was a quiet mode that has been removed, but it seems it wasn't the same purpose. https://github.com/rtts/djhtml/commit/0cb953418b0c5e4d391e9a89bcca3b687834fda5

Is it possible to have a quiet mode which doesn't print the info but only the error ?

If you are okay to add this option, I can contribute, let me know.

JaapJoris commented 11 months ago

Hi there, thanks for suggesting an improvement!

What kind of error do you mean? What are you trying to accomplish?

LeResKP commented 11 months ago

I'm talking about the _info that templates were perfects or have been reindented

    _info(f"{changed_files} template{s} {have} been reindented.")
     _info(f"{unchanged_files} template{s} {were} already perfect!")

It's not an error since it's info, but it's printed on sys.stderr. But I wouln't print them on sys.stdout since in some case the content is passed as stdin.

My goal is to fix the the djhtml-vscode plugin : https://github.com/tomusher/djhtml-vscode It's archived and not working anymore so I'm trying to fix it

So I pass the content of the document as stdin:

          const process = spawn(environment.path, [
            "-m",
            DJHTML_MODULE,
            "-",
          ]);

          process.stdin.write(document.getText());
          process.stdin.end()

But when listening on error, I need to check the error message to skip them, it's not really nice and robust. The stderr should only print error for me, and not info so I'd like to silence this message

          process.stderr.on("data", (data: String) => {
            if (data.includes(`No module named ${DJHTML_MODULE}`)) {
              vscode.window.showErrorMessage(
                `djhtml is not installed in the current Python environment`
              );
            } else {
              if (!data.includes('templates have been reindented') && !data.includes('template has been reindented.')) {
                vscode.window.showErrorMessage(
                  `djhtml failed with error: ${data}`
                );
              }
            }
          });
LeResKP commented 11 months ago

Just thought about this, but perhaps a --log-level option would be better

LeResKP commented 10 months ago

Finally I used the exit code, it's fine like this