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

Add option to display only name and description for help command #119

Closed
gunnx opened this issue Feb 25, 2017 · 12 comments
Closed

Add option to display only name and description for help command #119

gunnx opened this issue Feb 25, 2017 · 12 comments

Comments

@gunnx
Copy link
Collaborator

gunnx commented Feb 25, 2017

  • nps version: 5.0.3
  • node version: 7.4.0
  • npm version: 4.0.5

Problem description:
Some scripts can be very long making the help output harder to read.

Suggested solution:
Either remove displaying the script completely, or supply a way to configure help so you can hide the script output, this could be done via a flag, or perhaps per script in the config file, much like hiddenFromHelp works, could even use that and change it from a boolean to other option like: hiddenFromHelp: 'script'

@kentcdodds
Copy link
Collaborator

Thanks. Definitely open to doing this. Just unsure of what's best. I think I like using hiddenFromHelp, but what does everyone else think?

@robwise
Copy link
Contributor

robwise commented Apr 2, 2017

For me, I like this idea because I like using nps as a menu of what I might want to run, but usually I'm not interested in looking at the source script code, I just want the names and maybe the descriptions. Accomplishing that by adding an option on a per-script basis would be kind of un-DRY.

What about just adding a built-in nps command called "commands" or a flag? I guess you might be worried about name conflicts though. But this way you could just make your script:

  "start": "nps commands",

@kentcdodds
Copy link
Collaborator

What if it was just nps help --no-scripts?

@robwise
Copy link
Contributor

robwise commented Apr 2, 2017

Well if it's going to be based off of help, then we should also remove this type of thing with that flag:

Usage: node_modules/.bin/nps [options] <script>...

Commands:
  init        automatically migrate from npm scripts to nps
  completion  generate bash completion script

Options:
  --config, -c     Config file to use (defaults to nearest package-scripts.yml
                   or package-scripts.js)                              [default:
         "/Users/Rob/dev/shakacode/friendsandguests/client/package-scripts.yml"]
  --silent, -s     Silent nps output                  [boolean] [default: false]
  --log-level, -l  The log level to use
                   [choices: "error", "warn", "info", "debug"] [default: "info"]
  --require, -r    Module to preload
  -h, --help       Show help                                           [boolean]
  -v, --version    Show version number                                 [boolean]

Examples:
  node_modules/.bin/nps test build          Runs the `test` script then the
                                            `build` script
  node_modules/.bin/nps "test --cover"      Runs the `test` script and forwards
  "build --prod"                            the "--cover" flag then the `build`
                                            script and forwards the "--prod"
                                            flag

The idea being I know how to use nps, I just forgot the name of the script, but I'll know it when I see it?

@kentcdodds
Copy link
Collaborator

Good point!

@RichDonnellan
Copy link

RichDonnellan commented Jun 7, 2017

Piggybacking on this idea, can we also include a way to hide the script output when executing nps? Really long scripts do clutter the log and shouldn't be important to see once your setup is "bulletproof".

[PREFIX] nps is executing `task`: <script displayed here and could be 
really looooong spanning multiple lines>
[PREFIX] nps is executing `nextTask`: <script displayed here and could be really looooong 
spanning multiple lines>

// Preferred
[PREFIX] nps is executing `task`
[PREFIX] nps is executing `nextTask`

@kentcdodds
Copy link
Collaborator

We could definitely make that be part of the options in your config (which I think only supports silent right now). That could be a separate PR if you're up for it!

@K3TH3R
Copy link
Collaborator

K3TH3R commented Sep 17, 2017

@kentcdodds What do you think about this format:

options: {
    'help-style': 'basic' // 'all', 'scripts' 
}

all would be the default and basically gives you the entire output like the command does currently. scripts would be something like this:

default - Get help on what commands are available - nps help
commit - Start a new commit with commitizen - git-cz
dev - Run the Webpack HMR Dev Server - node ./build/dev-server.js
build - Build the Project for deployment  - node ./build/build.js
test - Run all of the tests for the app - node node_modules/concurrently/src/main.js --kill-others-on-fail --prefix-colors "bgBlue.bold,bgMagenta.bold" --prefix "[{name}]" --names 

And then basic would give it to you without the scripts appended to the end:

default - Get help on what commands are available
commit - Start a new commit with commitizen
dev - Run the Webpack HMR Dev Server
build - Build the Project for deployment
test - Run all of the tests for the app

@kentcdodds
Copy link
Collaborator

Sounds fine to me!

Let's just make sure it's tested and documented too! 👍

@K3TH3R
Copy link
Collaborator

K3TH3R commented Sep 25, 2017

@kentcdodds I've mostly figured out how to do this, but I want some feedback on my direction in case I'm missing something in the library. Is there a way to globally access the current options object? Or do I need to re-write functions all the way up the call stack to carry the options object down to the right functions?

[edit]
Specifically, I need it in scriptObjectToChalk(), but in order to get it in there as the library is currently, I need to go back up the chain to push it into the chain at getAvailableScripts or change the filteredScripts.map call to be an anonymous function that injects the options or maybe uses a bind like this?

const scriptLines = filteredScripts.map(scriptObjectToChalk.bind(null, options))

Any guidance would be much appreciated.

@kentcdodds
Copy link
Collaborator

@iamkether, what you have there seems fine to me 👍

@K3TH3R
Copy link
Collaborator

K3TH3R commented Nov 9, 2017

This was fixed in #164. You can now specify a 'help-style' in your config.options object. See my above message for details on what each option provides for output.

@K3TH3R K3TH3R closed this as completed Nov 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants