Skip to content

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

@msabramo

Description

@msabramo

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions