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

Simplify slightly complex code for handling both -n and --no-newline flags #30

Open
msabramo opened this issue Sep 14, 2021 · 0 comments

Comments

@msabramo
Copy link
Contributor

msabramo commented Sep 14, 2021

There is some code that is unfortunately a bit complex, because we're trying to support both -n and --no-newline flags and this is a little tricky with the current state of meow and yargs-parser (which meow uses).

The line looks like this:

	if (!cli.flags.noNewline && cli.flags.newline !== false) {
		process.stdout.write('\n');
	}

There are two conditions in the if statement:

  • cli.flags.noNewline is set when -n is passed.
  • cli.flags.newline is set to false when --no-newline is passed.

The hope is that this complexity will be temporary and that the code can be refactored in the future, possibly along with some changes to either meow or yargs-parser, which meow uses.

We might be able to simplify this in the future if we use the boolean-negation feature in yargs-parser (see #16 (comment)) or if yargs-parser has or develops some way of indicating that a short flag is a negative flag (e.g.: -n sets a newline flag to false, just as --no-newline does).

msabramo added a commit to msabramo/chalk-cli that referenced this issue Sep 14, 2021
and referencing issue created to track simplifying it:

chalk#30
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

1 participant