JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1
  • Score
    100M100P100Q47565F
  • License MIT

Yet another command line tool using Javascript. (By the way my last name is Yax)

Package Exports

  • yax-cli
  • yax-cli/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (yax-cli) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

yax-cli

Yet another command line tool using Javascript. (By the way my last name is Yax)

Install

npm install yax-cli

With Typrescript

Main structure

As a example, It uses src as source path.

repository
├── src
│   ├── cmds ## relative path 
│   │   ├──find 
│   │   │  └── index.ts ## export an object that implements CommandInterface
│   ├── index.ts  ##  Command line Register file

files

Command line registration

#!/usr/bin/env node // Don't forget add this at the first line
// repository/src/index.ts
new Register({
  description: 'Country Command Line Tool', // Your description
  commandsPath: `${__dirname}/cmds`, //  Add here your full path to the directory
  process,  // Procees runtime variable
});

Find command definition

import { CommandInterface, Options, Rule, logger } from "yax-cli";

const centralAmericaCountries = [ "Belice", "Costa Rica", "El Salvador", "Guatemala", "Honduras", "Nicaragua", "Panamá" ];

export default class Cmd implements CommandInterface {
  description = 'Find country by name';
  examples = [
    'country find --name Guatemala',
    'country find -n Belice'
  ];
  validations: Rule[] = [
    {
      flag: 'name',
      alias: 'n',
      description: "Country name",
      required: true,
      type: 'string'
    }
  ];
  handler(options: Options) { 
    // You can do here wethever you want
    const name = options.get('name');
    const result = centralAmericaCountries.find((c) => c === name) ?? [];
    logger.log(result);
  }
};

Build and Link/Publish your CLI

command

country --help

output

USAGE: bin <COMMAND> [OPTIONS]
DESCRIPTION: Country Command Line Tool
COMMANDS:
  - find
  - search
OPTIONS:
--help, -h                             (optional) Display help
countries find --name Guatemala

Output

Guatemala

That's it, I hope this tool can help you :)