JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 132
  • Score
    100M100P100Q79230F
  • License GPL-3.0

✨ A simple CLI commander system

Package Exports

  • @hammerhq/cli-tool
  • @hammerhq/cli-tool/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 (@hammerhq/cli-tool) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@hammerhq/cli-tool

✨ A simple CLI commander system

📥 Installation

$ npm install @hammerhq/cli-tool

🔧 Usage

tool
    .createCommand(ICommand, callback(commandName, args) => unknown) // create command
    .createCommand(ICommand, callback(commandName, args) => unknown) // create another command
    .help() // If none of the above commands are used, execute the help command.
  • ICommand: Where command is defined to be used when separating arguments. Structure:
{
    name: "test", // Command name
    usage: "--message <your_message>", // Command usage
    example: [ "--message Hello, world!", "-m Test message" ], // Usage examples
    category: "test", // Command category
    aliases: [ "t" ], // Command aliases
    description: "just a test command", // Command description
    argDefinitions: [
        { name: "message", type: String, aliases: [ "m" ] }
    ] // Arg definition array (Learn about ArgDefinition below)
}
  • ArgDefinition: Where options are defined to be used when separating arguments. Structure:
{
    name: "message", // Option name
    type: String // Option type (function)
    aliases?: [ "m" ], // Option aliases (optional)
    default?: false, // optional
    isOptional?: false // optional
}
  • callback(commandName, args) => unknown: If the command you set is used, the action to be applied. Example:
tool.createCommand(ICommand, (commandName, args) => {
    //         callback(commandName, args) ⬇️
    console.log("You used", commandName, "command with arguments", args);
});

🛠️ Example

import { tool } from "@hammerhq/cli-tool";

tool
    .createCommand({
        name: "install",
        usage: "<module_name> [--version] <package_version>",
        example: [ "tool", "hargs --version 1.0.1" ],
        category: "utility",
        aliases: [ "i", "add" ],
        description: "Install packages from server",
        argDefinitions: [
            { name: "module", type: String, default: true },
            { name: "version", type: String, isOptional: true }
        ]
    }, (commandName, args) => {
        const { module, version } = args;
        console.log("You have downloaded package", module, "with version" version ? version : "latest");
    })
    .help()

License

Copyright © 2023 Barış DEMİRCİ.

Distributed under the GPL-3.0 License. See LICENSE for more information.

Contributing

Feel free to use GitHub's features.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/my-feature)
  3. Run prettier (npm run format)
  4. Commit your Changes (git commit -m 'my awesome feature my-feature')
  5. Push to the Branch (git push origin feature/my-feature)
  6. Open a Pull Request

Show your support

Give a ⭐️ if this project helped you!

Contact