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

[Feature Request] Hide default value and flag type #1145

Closed
borela opened this issue Jun 6, 2018 · 15 comments
Closed

[Feature Request] Hide default value and flag type #1145

borela opened this issue Jun 6, 2018 · 15 comments

Comments

@borela
Copy link

borela commented Jun 6, 2018

Currently, my project shows:

Commands:
  index.js build     Build the project.
  index.js scaffold  Generate a project from the available templates.
  index.js lint      Check or fix code style.
  index.js test      Run test suites.

Options:
  --help            Show usage instructions.                           [boolean]
  --version         Show toolbox version.                              [boolean]
  --comment-flow    Convert Flow annotations to comments.              [boolean]
  --env             Used to determine the polyfills and fine tune the linter.
        [array] [choices: "browser", "node-js"] [default: ["browser","node-js"]]
  --flow            Enable Flow annotations.                           [boolean]
  --jsx             Enable JSX.                                        [boolean]
  --react           Enable React transformations.                      [boolean]
  --remove-flow     Remove Flow annotations.                           [boolean]
  --production      Remove debug plugins.                              [boolean]
  --target-browser  Browsers targeted by the project.
      [array] [default: ["chrome >= 49",">= 0.5%","last 2 versions","not dead"]]
  --target-node-js  Minimum NodeJS version targeted by the project.
                                                           [string] [default: 6]
  --type-script     Enable TypeScript.                                 [boolean]

But the default values and types pollutes it, is it possible already to hide them? I would like something like this:

Commands:
  index.js build     Build the project.
  index.js scaffold  Generate a project from the available templates.
  index.js lint      Check or fix code style.
  index.js test      Run test suites.

Options:
  --help            Show usage instructions.                           
  --version         Show toolbox version.                              
  --comment-flow    Convert Flow annotations to comments.              
  --env             Used to determine the polyfills and fine tune the linter.
  --flow            Enable Flow annotations.                           
  --jsx             Enable JSX.                                      
  --react           Enable React transformations.                    
  --remove-flow     Remove Flow annotations.                         
  --production      Remove debug plugins.                            
  --target-browser  Browsers targeted by the project.
  --target-node-js  Minimum NodeJS version targeted by the project.
  --type-script     Enable TypeScript.                                 
@Phothiabea
Copy link
Contributor

Phothiabea commented Jun 28, 2018

Afaik, there is no option to change the formatting of the of the help print out yet, besides usage() and epilogue() which will add a header/footer to it

@borela borela changed the title Hide default value and flag type [Feature Request] Hide default value and flag type Jun 28, 2018
@borela
Copy link
Author

borela commented Jul 19, 2018

@bcoe Would you a pull request of a function like hideExtras() to hide the types and default values?

@borela
Copy link
Author

borela commented Jul 19, 2018

Another suggestion would be hideTypes() and hideDefaultValues().

@orgrimarr
Copy link

I have the same issue, when i add a description + a type, yargs pollutes the output. (--help)
I found in the documentation a command to fit the text to the console size:
. wrap(yargs.terminalWidth())
This may help you

@bcoe
Copy link
Member

bcoe commented Mar 13, 2019

@borela there's now a way to configure advanced parsing options with parserConfiguration; I would be open to adding some options related to controlling view output, e.g., showDefaultInHelp, which defaults to true.

Do you want to help add this feature?

@bcoe bcoe added the triaged label Mar 13, 2019
@borela
Copy link
Author

borela commented Mar 13, 2019

That would great, a flag to hide the flag type would be interesting too, for example showTypeInHelp or showFlagTypeInHelp.

@sorenlouv
Copy link

showDefaultInHelp would be super useful.

@eulores
Copy link

eulores commented Sep 19, 2020

Here's a quick fix that solves the issue for me.
I patched the installed module, in file node_modules/yargs/build/index.cjs around line 900. The source code is in file usage.ts.

  1. I added a oneliner:
let x; const brackets = (v, suffix='') => ((x=__(v))!=='-') && `[${x}${suffix}]` || null;
  1. and then replaced most instances of the construct `[${__('string')}]` with brackets('string').

The patched section in file index.cjs (around line 900) looks like this:

        let x; const brackets = (v, suffix='') => ((x=__(v))!=='-') && `[${x}${suffix}]` || null;
        displayedGroups.forEach(({ groupName, normalizedKeys, switches }) => {
            ui.div(groupName);
            normalizedKeys.forEach((key) => {
                const kswitch = switches[key];
                let desc = descriptions[key] || '';
                let type = null;
                if (~desc.lastIndexOf(deferY18nLookupPrefix))
                    desc = __(desc.substring(deferY18nLookupPrefix.length));
                if (~options.boolean.indexOf(key))
                    type = brackets('boolean');
                if (~options.count.indexOf(key))
                    type = brackets('count');
                if (~options.string.indexOf(key))
                    type = brackets('string');
                if (~options.normalize.indexOf(key))
                    type = brackets('string');
                if (~options.array.indexOf(key))
                    type = brackets('array');
                if (~options.number.indexOf(key))
                    type = brackets('number');
                const deprecatedExtra = (deprecated) => typeof deprecated === 'string'
                    ? `[${__('deprecated: %s', deprecated)}]`
                    : `[${__('deprecated')}]`;
                const extra = [
                    (key in deprecatedOptions) ? brackets('deprecated') && deprecatedExtra(deprecatedOptions[key]) : null,
                    type,
                    (key in demandedOptions) ? brackets('required') : null,
                    options.choices && options.choices[key] ? brackets('choices:', ` ${self.stringifiedValues(options.choices[key])}]`) : null,
                    brackets('default:') && defaultString(options.default[key], options.defaultDescription[key])
                ].filter(Boolean).join(' ');
                ui.span({ text: getText(kswitch), padding: [0, 2, 0, 2 + getIndentation(kswitch)], width: maxWidth(switches, theWrap) + 4 }, desc);
                if (extra)
                    ui.div({ text: extra, padding: [0, 0, 0, 2], align: 'right' });
                else
                    ui.div();
            });
            ui.div();
        });

The application that calls yargs will need to use option updateStrings. Those bracketed strings that shall be hidden should be set to '-' as seen in this code fragment:

  yargs.updateStrings({
    'boolean': '-',
    'string': '-',
    'count': '-',
    'array': '-',
    'number': '-',
    'choices:': '-',
    'default:': '-',
  })

@ljharb
Copy link
Contributor

ljharb commented Dec 28, 2021

My use case is a "github token" argument, which defaults from process.env - but i do not want to display a secret value in the help output.

@vladikopl01
Copy link

Any updates on this feature?

@Nantris
Copy link

Nantris commented Jan 11, 2023

Not a very important complaint in our case, but it's a bit annoying that [boolean] shows next to --version and --help.

Even though they are booleans, no reasonable person is passing --version=false, so it just clutters the output.

@06000208
Copy link

Think this has been implemented by #2156, per #2153, and will be in the next release according to the info there.

@ljharb
Copy link
Contributor

ljharb commented Jan 29, 2023

@06000208 per #2156 (comment), that does not cover this issue, since it doesn't allow the type to be hidden on arbitrary options, only on everything all at once.

@bcoe bcoe closed this as completed Feb 13, 2023
@bcoe
Copy link
Member

bcoe commented Feb 13, 2023

@ljharb please feel free to open an additional feature request for hiding the default/type suffixes for individual commands.

Closing this as it addresses the feature request in this ticket (which was to turn the feature on or off globally).

@ljharb
Copy link
Contributor

ljharb commented Feb 13, 2023

Fair enough, opened #2299.

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

10 participants