UNPKG

codesnippets-cli

Version:

A CLI tool for importing and exporting code snippets via https://codesnippets.dev

193 lines (123 loc) 5.06 kB
# CodeSnippets.dev CLI (BETA) CodeSnippets.dev is a service that allows you to publish code snippets for easy reuse across projects and teams. Gone are the days of hunting through folders and projects looking for that one snippet of code to copy and paste. ## Basic Example Imagine you created a nice little utility function, `getQueryStringParam.js` inside of **ProjectA**. You can do "future you" a favor and `export` it as code snippet. ```text snippets export src/utils/getQueryStringParam.js ``` Then two months later, when the same need arises while working on **ProjectB**, you can quickly `import` it. ```text snippets import getQueryStringParam.js --out src/shared ``` ## Getting Started Install the CLI via NPM ```text npm install -g codesnippets-cli ``` Then login: ```text snippets login ``` ## Available Commands - **[list](#list)** - Display a list of your (or a specified user's) code snippets - **[export \<filepath\>](#export)** - Export a local file to create a new CodeSnippet - **[import \<snippetPath\>](#import)** - Import a remote CodeSnippet to be saved as a local file. - **[remove \<snippetPath\>](#remove)** - Remove a CodeSnippet you have created - **[settings](#settings)** - Display your CodeSnippets.dev CLI settings - **[login](#login--logout)** - Log into the CodeSnippets.dev CLI - **[logout](#login--logout)** - Log out of the CodeSnippets.dev CLI ## List Display the available code snippets. By default your own, but you can specify a CodeSnippets.dev user. ```sh snippets list [--user <value>] [--collection <value>] ``` ### List Examples #### Show all of your own snippets ```sh snippets list ``` #### Show all your snippets from a specified collection ```sh snippets list --collection utils ``` #### Show all of another user's snippets ```sh snippets list --user droopytersen ``` ## Export Export a local file to be available as a CodeSnippets.dev snippet. ```sh snippets export <filepath> [--title <value>] [--collection <value>] [--details <value>] [--overwrite] ``` - If already have a snippet with a matching `filename` and `collection`, you must pass the `--overwrite` flag. - When you run the export command without any options you will be prompted for the required parmeters. ### Export Examples #### Export a file ```sh snippets export src/components/Slider.jsx ``` #### Export a file to a specific collection ```sh snippets export src/components/Slider.jsx --collection components ``` ## Import Save available CodeSnippets.dev snippets as local files. ```sh snippets import <snippet> [--path <value>] [--overwrite] ``` - If a local file already exists, you will need to pass the `--overwrite` flag - If the given `--path` doesn't exist, you will receive an error ### Import Examples #### Import a snippet file to the current folder _Get your snippet that has a filename of `Slider.tsx` and save it locally to the current directory_ ```sh snippets import Slider.tsx ``` #### Import a snippet file to a specific folder > If the destination folder doesn't exist, it will automatically be created _Get your snippet that has a filename of `Slider.tsx` and save it locally to `src/components/Slider`_ ```sh snippets import Slider.tsx --out src/components/Slider ``` #### Import a snippet to a specific folder with a different filename If you include a filename in the `--out` path, then that filename will be used instead of the Snippet's filename. ```sh snippets import Slider.tsx --out src/components/AnimatedSlider/AnimatedSlider.tsx ``` #### Import a snippet file from a specific collection _Look in your `utils` collection for a snippet named `debounce.js` and save it to the current folder_ ```sh snippets import utils/debounce.js ``` #### Import an entire collection You can import an entire collection with the `COLLECTION/` syntax _Import every snippet file that exists in your `utils` collection and save them locally in the `src/utils` folder._ ```sh snippets import utils/ --out src/utils ``` #### Import another user's entire collection You can import an entire collection of another user with the `USERNAME/COLLECTION/` syntax _Import every snippet file that exists in DroopyTersen's `utils` collection and save them locally in the `src/utils` folder._ ```sh snippets import droopytersen/utils/ --out src/utils ``` ## Login / Logout Log in and out of the CodeSnippets.dev CLI ```sh snippets login snippets logout ``` ## Settings For development only. Allows you to see your env configuration as well as switch from `local` to `dev` to `prod`. ```sh snippets settings [--env <value>] ``` ### Display current environment settings ```sh snippets settings ``` ### Switch to a different environment _Switch to the `dev` environment. You might have to login again if it is your first time using the targeted env._ ```sh snippets settings --env dev ```