Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make help indentation configurable #741

Closed
mojavelinux opened this issue Jan 5, 2018 · 6 comments
Closed

Make help indentation configurable #741

mojavelinux opened this issue Jan 5, 2018 · 6 comments

Comments

@mojavelinux
Copy link
Contributor

mojavelinux commented Jan 5, 2018

commander.js indents all lines in the help output. This is atypical. I don't know many commands that output help with this formatting (if you consider node, npm, lerna, ruby, docker, git, grep, find, vim, rpm). I'd like to make my command look more like the typical command. Please make the indentation size configurable, or provide a switch to disable it outright.

Commands which do use indentation include yarn and gem. Yarn happens to have indentation because it's using this package ;)

@mojavelinux
Copy link
Contributor Author

I'm currently using the following patch as a workaround:

const { Command } = require('commander')
  
const helpInformation = Command.prototype.helpInformation
const indentation = '  '

Command.prototype.helpInformation = function () {
  return helpInformation.call(this).split(/^/m).reduce((accum, line) => {
    if (line === '\n') {
      const lastLine = accum[accum.length - 1]
      if (!lastLine || !(lastLine === '\n' || lastLine.endsWith(':\n'))) {
        accum.push(line)
      }
    } else {
      accum.push(line.substr(indentation.length))
    }
    return accum
  }, []).join('')
}

I'd also like to remove the extra blank line between sections.

mojavelinux added a commit to mojavelinux/commander.js that referenced this issue Jan 6, 2018
mojavelinux added a commit to mojavelinux/commander.js that referenced this issue Jan 6, 2018
@abadraja
Copy link

abadraja commented Jan 11, 2018

Try this:

const { Command } = require('commander')
const helpInformation = Command.prototype.helpInformation;

Command.prototype.helpInformation = function () {
return helpInformation.call(this).split('\n').map(row => {
return row.replace(/^\s{2}/, '');
}).join('\n');
}

@mojavelinux
Copy link
Contributor Author

That's effectively the same as what I proposed.

@shadowspawn
Copy link
Collaborator

For interest, the help indentation was removed in commander v2.18.0 via this Pull Request: #853

@mojavelinux
Copy link
Contributor Author

Now that the help output has been standardized, I no longer think that configuration of the indentation is necessary. I had only proposed that as a compromise for changing the default behavior. But now that the default has changed, I think we're good. 👍

@ctjlewis

This comment was marked as abuse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants