Skip to content

Add a way to create commands that can receive from a pipe without being standalone commands #487

@nfischer

Description

@nfischer

This is kind of a weird use-case, but it might be nice to allow plugin writers to create commands of the following form (tr() is the example):

var ret = shell.cat('file.txt').tr('-d', 'A'); // ShellStrings have a .tr() method
assert.equal(shell.hasOwnProperty('tr'), false); // The shell.tr() command doesn't exist

This example would stay consistent with how the unix tr command works, since it doesn't actually take a filename as an argument and can only be used via pipes.

This is related to #486, but I think there's an important distinction. This still takes advantage of option parsing and perhaps other features of the plugin API. #486 is more about adding pure methods without any sort of wrapping, or completely changing the implementation of ShellStrings.

This functionality could be offered as an option to plugin.register:

plugin.register('tr', _tr, {
  wrapOutput: true,
  cmdOptions: {
    d: 'delete',
  },
  canReceivePipe: true,
  pipedOnly: true, // perhaps there's a way to tie this in to the option above
});

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions