Skip to content

marcuth/command-options-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Command Options Handler

Command Options Handler is a library for handling options/arguments in string format.

Usage

import CommandHandler, { Command } from "command-options-handler"

const command: Command = {
    name: "Teste",
    description: "This is the description of the test command.",
    options: [
        {
            name: "want-something",
            description: "This is the description of the first argument/option. The names here have no impact whatsoever. I just put them to fit with my bot development architecture :)",
            type: "yesOrNo"
        }
    ]
}

const commandHandler = new CommandHandler(command)

console.dir(commandHandler.handleStringOptions([ "yes" ]), { depth: null })
console.dir(commandHandler.handleStringOptions([ "YeS ", "x" ]), { depth: null })
console.dir(commandHandler.handleStringOptions([ "yeah", "ok" ]), { depth: null })

Execution result

{
  isValid: true,
  argumentsExpected: 1,
  argumentsReceived: 1,
  optionsValidation: [
    {
      name: 'want-something',
      isValid: { type: true, value: true },
      value: { raw: 'yes', parsed: 'yes' } 
    }
  ]
}
{
  isValid: true,       
  argumentsExpected: 1,
  argumentsReceived: 2,
  optionsValidation: [ 
    {
      name: 'want-something',
      isValid: { type: true, value: true },
      value: { raw: 'YeS ', parsed: 'yes' }
    }
  ]
}
{
  isValid: false,
  argumentsExpected: 1,
  argumentsReceived: 2,
  optionsValidation: [
    {
      name: 'want-something',
      isValid: { type: false, value: false },
      value: { raw: 'yeah', parsed: null }
    }
  ]
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors