From 19900d088e9e6af7e156aedea95400a3845eac7c Mon Sep 17 00:00:00 2001 From: Philipp Kunz Date: Sun, 14 Apr 2024 01:02:06 +0200 Subject: [PATCH] fix(core): update --- npmextra.json | 18 ++++- package.json | 18 +++-- readme.hints.md | 1 + readme.md | 171 ++++++++++++++++++++++++++------------- ts/00_commitinfo_data.ts | 4 +- 5 files changed, 145 insertions(+), 67 deletions(-) create mode 100644 readme.hints.md diff --git a/npmextra.json b/npmextra.json index 02a13cd..2188877 100644 --- a/npmextra.json +++ b/npmextra.json @@ -9,12 +9,24 @@ "githost": "code.foss.global", "gitscope": "push.rocks", "gitrepo": "smartcli", - "description": "easy observable cli tasks", + "description": "A library for easily creating observable CLI tasks with support for commands, arguments, and options.", "npmPackagename": "@push.rocks/smartcli", - "license": "MIT" + "license": "MIT", + "keywords": [ + "CLI", + "command line", + "observable", + "tasks", + "commands", + "arguments", + "options", + "typescript", + "node.js", + "development tool" + ] } }, - "tsdocs": { + "tsdoc": { "legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n" } } \ No newline at end of file diff --git a/package.json b/package.json index 6534e24..46a17db 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "@push.rocks/smartcli", "private": false, "version": "4.0.9", - "description": "easy observable cli tasks", + "description": "A library for easily creating observable CLI tasks with support for commands, arguments, and options.", "main": "dist_ts/index.js", "typings": "dist_ts/index.d.ts", "type": "module", @@ -16,10 +16,16 @@ "url": "https://gitlab.com/pushrocks/smartcli.git" }, "keywords": [ - "cli", - "promise", - "task", - "push.rocks" + "CLI", + "command line", + "observable", + "tasks", + "commands", + "arguments", + "options", + "typescript", + "node.js", + "development tool" ], "author": "Lossless GmbH (https://lossless.com)", "license": "MIT", @@ -57,4 +63,4 @@ "browserslist": [ "last 1 chrome versions" ] -} +} \ No newline at end of file diff --git a/readme.hints.md b/readme.hints.md new file mode 100644 index 0000000..2d6c3a7 --- /dev/null +++ b/readme.hints.md @@ -0,0 +1 @@ +No specific hints. \ No newline at end of file diff --git a/readme.md b/readme.md index 8108f0b..a66a32d 100644 --- a/readme.md +++ b/readme.md @@ -1,74 +1,133 @@ # @push.rocks/smartcli + easy observable cli tasks -## Availabililty and Links -* [npmjs.org (npm package)](https://www.npmjs.com/package/@push.rocks/smartcli) -* [gitlab.com (source)](https://gitlab.com/push.rocks/smartcli) -* [github.com (source mirror)](https://github.com/push.rocks/smartcli) -* [docs (typedoc)](https://push.rocks.gitlab.io/smartcli/) +## Install -## Status for master +To install `@push.rocks/smartcli`, use the following command in your terminal: -Status Category | Status Badge --- | -- -GitLab Pipelines | [![pipeline status](https://gitlab.com/push.rocks/smartcli/badges/master/pipeline.svg)](https://lossless.cloud) -GitLab Pipline Test Coverage | [![coverage report](https://gitlab.com/push.rocks/smartcli/badges/master/coverage.svg)](https://lossless.cloud) -npm | [![npm downloads per month](https://badgen.net/npm/dy/@push.rocks/smartcli)](https://lossless.cloud) -Snyk | [![Known Vulnerabilities](https://badgen.net/snyk/push.rocks/smartcli)](https://lossless.cloud) -TypeScript Support | [![TypeScript](https://badgen.net/badge/TypeScript/>=%203.x/blue?icon=typescript)](https://lossless.cloud) -node Support | [![node](https://img.shields.io/badge/node->=%2010.x.x-blue.svg)](https://nodejs.org/dist/latest-v10.x/docs/api/) -Code Style | [![Code Style](https://badgen.net/badge/style/prettier/purple)](https://lossless.cloud) -PackagePhobia (total standalone install weight) | [![PackagePhobia](https://badgen.net/packagephobia/install/@push.rocks/smartcli)](https://lossless.cloud) -PackagePhobia (package size on registry) | [![PackagePhobia](https://badgen.net/packagephobia/publish/@push.rocks/smartcli)](https://lossless.cloud) -BundlePhobia (total size when bundled) | [![BundlePhobia](https://badgen.net/bundlephobia/minzip/@push.rocks/smartcli)](https://lossless.cloud) +```sh +npm install @push.rocks/smartcli --save +``` + +This will add `@push.rocks/smartcli` as a dependency to your project's `package.json` file and download it into the `node_modules` folder. ## Usage -this plugin tries to establish some logic in which CLI tools work. +The `@push.rocks/smartcli` module is designed to simplify the creation of command-line interfaces (CLIs) by providing an easy-to-use API for managing CLI commands and options. It combines observables with the parsing power of [yargs-parser](https://www.npmjs.com/package/yargs-parser) to offer a dynamic and flexible way to handle various CLI tasks. -take the following commandline input: +### Getting Started -``` -mytool command argument1 argument2 --option1 -o2 option2Value +First, ensure you have TypeScript and the necessary types for node installed in your project. If not, you can add them by running: + +```sh +npm install typescript @types/node --save-dev ``` -- `mytool` obviously is the tool (like git) -- `command` is the main thing the tool shall do (like commit) -- `argument1` and `argument2` are arguments -- `option1` is a longform option you can add (like --message for message) -- `optionValue` is the referenced option value (like a commit message) +Then, import the `Smartcli` class from the `@push.rocks/smartcli` package. -When there is no command and no option specified the standardTask applied. -When there is a option specified but no command, standardTask applies, -except when of the options is -v, --version or --help. - -```javascript -import { Smartcli } from 'smartcli'; -mySmartcli = new Smartcli(); -mySmartcli.standardTask().then((argvArg) => { - // do something if program is called without an command -}); - -mySmartcli.addCommand({ commandname: 'install' }).then((argvArg) => { - // do something if program is called with command "install" -}); - -mySmartcli.addVersion('1.0.0'); // -v and --version options will display the specified version in the terminal - -mySmartCli.addHelp({ - // is triggered by help command and --help option - helpText: 'some help text to print', // the helpText to display -}); - -mySmartcli.startParse(); // starts the evaluation and fullfills or rejects promises. +```typescript +import { Smartcli } from '@push.rocks/smartcli'; ``` -## Contribution +### Creating an Instance -We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :) +Create an instance of `Smartcli`. This instance will be used to define and manage your CLI commands. -For further information read the linked docs at the top of this readme. +```typescript +const mySmartcli = new Smartcli(); +``` -## Legal -> MIT licensed | **©** [Task Venture Capital GmbH](https://task.vc) -| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy) +### Defining Commands + +With `Smartcli`, you can define commands that your CLI tool can execute. Here's how you can add a new command: + +```typescript +mySmartcli.addCommand('install').subscribe((argv) => { + console.log('Install command was called with arguments:', argv); +}); +``` + +In this example, when the user types `install` after your CLI tool's name in the terminal, the provided function will execute, printing the parsed arguments to the console. + +### Handling Options + +Options can be accessed using the `getOption` method. If you have an option named `--config` or `-c`, you can access its value like this: + +```typescript +const configValue = mySmartcli.getOption('config'); +console.log('Config value:', configValue); +``` + +### Default Task (Standard Command) + +If you want to perform a task when no specific command is provided, you can use the `standardCommand` method: + +```typescript +mySmartcli.standardCommand().subscribe((argv) => { + console.log('No specific command provided. Running default task with arguments:', argv); +}); +``` + +### Version and Help + +To add a version option that prints the version of your CLI tool, use `addVersion`: + +```typescript +mySmartcli.addVersion('1.0.0'); +``` + +For a help option that displays helpful information about your CLI commands and options, use `addHelp`: + +```typescript +mySmartcli.addHelp({ + helpText: 'Here are the commands you can use...' +}); +``` + +### Parsing and Execution + +After defining all your commands and options, call `startParse` to begin parsing the command line input and execute the corresponding actions: + +```typescript +mySmartcli.startParse(); +``` + +### Advanced Usage: Command Aliases + +You can also define aliases for your commands, allowing users to use alternate names for them: + +```typescript +mySmartcli.addCommandAlias('install', 'i'); +``` + +With this setup, both `install` and `i` will trigger the same command action. + +### Observables and Async Operations + +Since commands in `smartcli` are handled using observables, you can easily integrate asynchronous operations within your command actions. This makes it perfect for CLI tasks that involve file operations, network requests, or any other async tasks. + +### Conclusion + +`@push.rocks/smartcli` offers a robust and intuitive way to build CLI tools with TypeScript, leveraging the reactive programming paradigm. By following the examples provided in this guide, you'll be able to create a feature-rich command-line application tailored to your specific needs. + +Remember, this is just the start. The true power of `smartcli` lies in its flexibility and the vast ecosystem of RxJS. Dive into the RxJS documentation to explore more ways to handle data streams and asynchronous events in your CLI app. + +## License and Legal Information + +This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. + +**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file. + +### Trademarks + +This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH. + +### Company Information + +Task Venture Capital GmbH +Registered at District court Bremen HRB 35230 HB, Germany + +For any legal inquiries or if you require further information, please contact us via email at hello@task.vc. + +By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works. diff --git a/ts/00_commitinfo_data.ts b/ts/00_commitinfo_data.ts index 32d93cf..59a7c1e 100644 --- a/ts/00_commitinfo_data.ts +++ b/ts/00_commitinfo_data.ts @@ -3,6 +3,6 @@ */ export const commitinfo = { name: '@push.rocks/smartcli', - version: '4.0.9', - description: 'easy observable cli tasks' + version: '4.0.10', + description: 'A library for easily creating observable CLI tasks with support for commands, arguments, and options.' }