{"id":16678475,"url":"https://github.com/2fd/command","last_synced_at":"2025-07-20T13:36:12.204Z","repository":{"id":57093579,"uuid":"56178705","full_name":"2fd/command","owner":"2fd","description":"Modular command line interface","archived":false,"fork":false,"pushed_at":"2016-11-20T03:35:34.000Z","size":66,"stargazers_count":0,"open_issues_count":2,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-17T21:52:38.998Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2fd.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-13T19:06:23.000Z","updated_at":"2024-06-07T23:37:20.000Z","dependencies_parsed_at":"2022-08-22T21:40:19.831Z","dependency_job_id":null,"html_url":"https://github.com/2fd/command","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/2fd/command","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2fd%2Fcommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2fd%2Fcommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2fd%2Fcommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2fd%2Fcommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2fd","download_url":"https://codeload.github.com/2fd/command/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2fd%2Fcommand/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265844785,"owners_count":23837654,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-12T13:29:25.509Z","updated_at":"2025-07-20T13:36:12.184Z","avatar_url":"https://github.com/2fd.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# @2fd/command [![Build Status](https://travis-ci.org/2fd/command.svg?branch=master)](https://travis-ci.org/2fd/command)\n\nModular command line interface\n\n## install\n\n```bash\n    npm install --save @2fd/command\n```\n\n## Node Compatibility\n\n* node v6\n* node v5\n* node v4\n* node v0.12\n\n## Goals\n\n- **Lazy load.**\n\n    Commands can be defined as a string that represents its location,\n    which allows to generate complex tools without the large number of\n    files slowing down the boot.\n\n- **Commands are user-defined.**\n\n    - The name that invokes a command is defined by the implementation,\n      which allows you to specify more practical commands\n      (such as 'migration:init'or 'mgt:i' instead of 'module-name:migracions:init').\n\n    - Third-party packages can only suggest the list of commands and names\n      that implement them, but always you can implement only those you need\n      and even replace them with your own ones.\n\n- **Fully modular.**\n    A simple and completely object-oriented APIs allow easily:\n\n    - Create commands that can be shared with the community\n\n    - Re-implement and/or expand any functionality\n\n    - Integrate commands created by third parties\n    \n- **Definitions included**\n\n    If you program in Typescript, definitions are included in the package\n    so they are available when you install as dependincie with `npm` without\n    requiring a definitions manager as `typings` or `tsd`\n    \n\n## Usage\n\nCommand implementation\n\n```typescript\n\n    import {\n        Command,\n        CommandInterface,\n        BooleanFlag,\n        Param\n    } from '@2fd/command';\n\n    // Object command implementation\n    class MyCommand extends Command implements CommandInterface {\n\n        description = 'My Command description';\n\n        params = new Param('requireParam [optionalParam] [...optionalParamList]');\n\n        flags = [\n            new BooleanFlag('force', ['--force', '-f'], 'Force flag'),\n        ];\n\n        // action(input, output) { }; in javascript\n        action(input: InputInterface, output: OutputInterface): void {\n\n            // input.params.requireParam: string\n            // input.params.optionalParam?: string\n            // input.params.optionalParamList: Array\u003cstring\u003e\n            // input.flags.force: boolean\n        };\n    }\n\n    export let myCommand = new MyCommand;\n\n    // Function command implementation\n    export function myQuickCommand(input: InputInterface, output: OutputInterface): void {\n        // Do something\n    }\n\n```\n\nMultiple command executor\n\n```javascript\n\n    // cmd.js\n\n    import {\n        ExecutorCommand,\n        ArgvInput,\n        ConsoleOutput\n    } from '@2fd/command';\n\n    import {myCommand} from './path/to/commands';\n\n    let tool = new ExecutorCommand();\n\n    tool.version = '1.0.0';\n    tool.description = 'Command description';\n\n    tool.addCommand('run', myCommand );\n    // or\n    tool.addCommand('run', './path/to/commands#myCommand' );\n\n    tool.addCommands({\n        'command1' : './path/to/commands#myCommand',\n        'command2' : './path/to/commands#myCommand'\n    });\n\n    tool.addCommadsNS('ns', {\n        'command3' : './path/to/commands#myCommand',\n        'command4' : './path/to/commands#myCommand'\n    });\n\n    tool.handle(\n        new ArgvInput(process.argv),\n        new ConsoleOutput()\n    );\n\n```\n\n```bash\n    \u003e node cmd.js\n\n        Command description [v1.0.0]\n\n        Usage: node cmd.js [COMMAND]\n\n        run            My Command description\n        command1       My Command description\n        command2       My Command description\n        ns:command3    My Command description\n        ns:command4    My Command description\n\n```\n\nSimple command in file\n\n```javascript\n\n    // command.js\n\n    import {myCommand} from './path/to/commands';\n\n    myCommand.handle(\n        new ArgvInput(process.argv),\n        new ConsoleOutput()\n    );\n\n```\n\n```bash\n\n    \u003e node command.js --help\n\n        Usage: node command.js [OPTIONS] requireParam [optionalParam] [...optionalParamList]\n\n        My Command description\n\n        --force, -f    Force flag\n        --help, -h     Print this help\n\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2fd%2Fcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2fd%2Fcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2fd%2Fcommand/lists"}