Skip to content

Latest commit

 

History

History
54 lines (44 loc) · 914 Bytes

custom-js-input-completion.md

File metadata and controls

54 lines (44 loc) · 914 Bytes

Example: custom completion returned by js module based on input

js-completion-input.yml

commands:
  - name: js-completion-input
    description: prints hello world
    command: echo "hello world"
    completion:
      completionPath: ./completion-input.js
    positionalArguments:
      - name: foo
        description: string
        type: String
        required: true

completion-input.js

module.exports = function (input) {
  if (input.argv.foo === 'odd') {
    return ['1', '3', '5'];
  } else if (input.argv.foo === 'even') {
    return ['2', '4', '6'];
  } else {
    return ['error'];
  }
};

Usage

nca js-completion-input --foo=odd {tab}

Prints:

1 3 5
nca js-completion-input --foo=even {tab}

Prints:

2 4 6

Notes:

Adding the flag merge: true in the completion, merges the custom completion with the default yargs one.