String

The String type represents any user-entered value.

Properties

String options and arguments support any of the common type properties.

Examples

Use the .string method to add a flagged option.

sywac
  .string('-n, --name <name>', { desc: 'specify your name' })
  .parseAndExit().then(argv => {
    console.log(`Hello, ${argv.name}!`)
  })
$ my-app -n Jan
Hello, Jan!


The default value of a String is undefined.

$ my-app
Hello, undefined!


Use the .positional method to add a positional argument.

sywac
  .positional('<name:string>')
  .parseAndExit().then(argv => {
    console.log(`Hello, ${argv.name}!`)
  })
$ my-app Jan
Hello, Jan!


Tip:

You don’t need to specify :string, because it is the default type for arguments.

sywac.positional('<name>')