|
1 | | -# Foji |
| 1 | +# Foji ⚒️ |
2 | 2 |
|
3 | | -Foji is a command-line interface (CLI) tool designed to help you automate and manage your coding tasks. It allows you to run custom codes and handle custom parameters. |
| 3 | +Foji is a powerful command-line interface (CLI) tool designed to streamline and automate long or repetitive commands in your daily workflow. With Foji, you can define and execute custom commands, integrate custom parameters, and simplify complex processes, reducing the need to repeatedly type lengthy commands. |
4 | 4 |
|
5 | | -## Features |
| 5 | +## 🚀 Features |
6 | 6 |
|
7 | | -- [x] Run custom codes |
8 | | -- [x] Handle custom parameters |
9 | | -- [x] Conditional handler for arguments |
10 | | -- [x] Support for default arguments |
11 | | -- [x] Support for optional arguments |
12 | | -- [x] Add commands to configuration file |
13 | | -- [x] Remove commands from the configuration file |
14 | | -- [x] Can run commands directly |
15 | | -- [x] Configuration can be saved on cloud |
16 | | -- [x] Configuration can be downloaded from cloud |
17 | | -- [x] Local configuration can be synced from cloud |
| 7 | +- [x] Run custom commands with flexible argument handling. |
| 8 | +- [x] Supports options, conditional, and spread arguments for advanced customization. |
| 9 | +- [x] Easily add, edit and remove commands in the CLI. |
| 10 | +- [x] Sync configuration to the cloud. |
18 | 11 |
|
19 | | -## Installation |
| 12 | +## 📦 Installation |
20 | 13 |
|
21 | | -Before installing Foji, make sure you have [Node.js](https://nodejs.org/) installed on your machine. |
| 14 | +> [!IMPORTANT] |
| 15 | +> Foji requires [Node.js](https://nodejs.org/) to be installed on your system. Make sure you have it installed before proceeding. |
22 | 16 |
|
23 | | -To install Foji globally, run the following command: |
| 17 | +To install Foji, run the following command: |
24 | 18 |
|
25 | | -```shell |
| 19 | +```bash |
26 | 20 | npm i foji -g |
27 | 21 | ``` |
28 | 22 |
|
29 | | -## Usage |
| 23 | +## 🚦 Usage |
30 | 24 |
|
31 | | -Foji saves your commands and your configuration url at it's configuration file (`~/.config/foji.json`). You can access the `.config` directory using `foji config` or open the file directly using `foji config -f` command. |
| 25 | +Foji stores your commands and configurations in its configuration file (`~/.config/foji.json`). You can access it using: |
| 26 | + |
| 27 | +```bash |
| 28 | +foji config |
| 29 | +``` |
| 30 | + |
| 31 | +Or open it directly: |
| 32 | + |
| 33 | +```bash |
| 34 | +foji config -f |
| 35 | +``` |
32 | 36 |
|
33 | 37 | ### Running a Command |
34 | 38 |
|
35 | | -To run a `command` just use: |
| 39 | +To execute a saved `command`: |
36 | 40 |
|
37 | | -```shell |
| 41 | +```bash |
38 | 42 | foji [command name] [...command args] |
39 | 43 | ``` |
40 | | -Simple as that. |
41 | 44 |
|
42 | | -If you don't provide a valid command name Foji will list all available commands, it includes default commands (eg.: `add`, `remove` and `sync`) and your own commands. |
| 45 | +> [!TIP] |
| 46 | +> If you don’t provide a valid command name, Foji will list all available commands, including default commands like `add`, `remove`, and `sync`, along with any custom commands you've added. |
43 | 47 |
|
44 | | -### Skipping a Argument |
| 48 | +### Skipping an Argument |
45 | 49 |
|
46 | | -You also can skip a (optional) argument using "_": |
| 50 | +If you want to skip an optional argument, use the `_` symbol: |
47 | 51 |
|
48 | | -```shell |
49 | | -foji [command name] [argument one] _ [argument three] |
| 52 | +```bash |
| 53 | +foji [command name] [arg1] _ [arg3] |
50 | 54 | ``` |
51 | 55 |
|
52 | | -## Creating and Updating the Configuration |
| 56 | +## ⚙️ Configuration Management |
53 | 57 |
|
54 | | -Foji provides easy ways to add `commands` to the configuration file (or create it if it does not exist): |
| 58 | +Foji allows you to easily create and update your command configurations. |
55 | 59 |
|
56 | | -### Creating a New Command |
| 60 | +### Adding a New Command |
57 | 61 |
|
58 | | -To add a new `command` to the configuration file you can use the `add` command: |
| 62 | +To add a new command to the configuration: |
59 | 63 |
|
60 | | -```shell |
| 64 | +```bash |
61 | 65 | foji add [command name] [command] |
62 | 66 | ``` |
63 | 67 |
|
64 | | -All `commands` can have four types of `arguments`: |
| 68 | +Supported argument types: |
65 | 69 |
|
66 | | -1. Required arguments: |
| 70 | +1. **Required Arguments**: |
| 71 | + These arguments **must** be provided for the command to run. |
67 | 72 |
|
68 | | -- These arguments **must** be provided for the command to run: |
| 73 | + ```json |
| 74 | + "command": "echo <requiredArgumentOne> <requiredArgumentTwo>" |
| 75 | + ``` |
69 | 76 |
|
70 | | -```json |
71 | | -"command":"echo <requiredArgumentOne> <requiredArgumentTwo>" |
72 | | -``` |
| 77 | +2. **Optional Arguments**: |
| 78 | + These arguments **are not mandatory**. If not provided, they will be skipped. |
73 | 79 |
|
74 | | -2. Optional arguments: |
| 80 | + ```json |
| 81 | + "command": "echo <requiredArgumentOne> <optionalArgumentOne?>" |
| 82 | + ``` |
75 | 83 |
|
76 | | -- These arguments **are not** mandatory. If not provided, they will add nothing to the command. |
| 84 | +3. **Optional Arguments with Default Values**: |
| 85 | + If not provided, a default value will be used. |
77 | 86 |
|
78 | | -```json |
79 | | -"command":"echo <requiredArgumentOne> <optionalArgumentOne?>" |
80 | | -``` |
| 87 | + ```json |
| 88 | + "command": "echo <requiredArgumentOne> <optionalArgumentOne ?? My Default Value>" |
| 89 | + ``` |
81 | 90 |
|
82 | | -3. Optional arguments with default values: |
| 91 | +4. **Ternary Arguments**: |
| 92 | + Works as a boolean argument, only checking whether it was passed. |
83 | 93 |
|
84 | | -- Similar to optional arguments, but if not provided, they will add a default value. `<options??--ts --tailwind --src>` |
| 94 | + ```json |
| 95 | + "command": "echo i want pizza of <requiredArgumentOne> with <hasCheese ? cheese : no cheese>" |
| 96 | + ``` |
85 | 97 |
|
86 | | -```json |
87 | | -"command":"echo <requiredArgumentOne> <optionalArgumentOne??My Default Value>" |
88 | | -``` |
| 98 | +5. **Spread Argument**: |
| 99 | + Catches all the remaining arguments. |
89 | 100 |
|
90 | | -4. Ternaries: |
| 101 | + ```json |
| 102 | + "command": "echo [<argOne>] {<argTwo...>}" |
| 103 | + ``` |
91 | 104 |
|
92 | | -- These arguments function like boolean arguments. Any value passed will be ignored by the CLI; it only checks **whether the argument was passed or not**. |
| 105 | +Example of usage: |
93 | 106 |
|
94 | | -```json |
95 | | -"command":"echo i want pizza of <requiredArgumentOne> with <hasCheese?cheese:no cheese>" |
| 107 | +```bash |
| 108 | +foji command "my arg one" one two three --my --options |
96 | 109 | ``` |
97 | 110 |
|
98 | | -Note that all `Required arguments` must be provided **BEFORE** any of the other arguments |
| 111 | +The resulting final command would be: |
99 | 112 |
|
100 | | -incorrect: |
101 | | - |
102 | | -```json |
103 | | -"command": "do command <argOne?> <argTwo>" |
| 113 | +```bash |
| 114 | +echo [my arg one] {one two three --my --options} |
104 | 115 | ``` |
105 | 116 |
|
106 | | -correct: |
| 117 | +> [!IMPORTANT] |
| 118 | +> **Always** provide required arguments **before** any optional ones. |
107 | 119 |
|
108 | | -```json |
109 | | -"command": "do command <argOne> <argTwo?>" |
110 | | -``` |
| 120 | +### Removing a Command |
111 | 121 |
|
112 | | -### Remove a Command |
| 122 | +To remove a command: |
113 | 123 |
|
114 | | -To remove a `command` you can use the `remove` command |
115 | | - |
116 | | -```shell |
117 | | -foji remove [command name] [command] |
| 124 | +```bash |
| 125 | +foji remove [command name] |
118 | 126 | ``` |
119 | 127 |
|
120 | | -### Configuration File Format |
| 128 | +## 🌐 Cloud Sync |
121 | 129 |
|
122 | | -Foji's configuration manage your `commands` and it's `url`: |
| 130 | +You can easily sync your configurations using cloud services. |
123 | 131 |
|
124 | | -```json |
125 | | -{ |
126 | | - "gistUrl": "https://gist.github.com/.../...", |
127 | | - "commands": { |
128 | | - "next:create": "npx create-next-app@latest <dir ?? . >", |
129 | | - "build": "npm run build:local", |
130 | | - "next:dev": "npm run dev" |
131 | | - } |
132 | | -} |
133 | | -``` |
| 132 | +> [!NOTE] |
| 133 | +> Foji uses [Github CLI](https://cli.github.com/) to create, read and update your configuration gist. |
134 | 134 |
|
135 | | -### Upload Your Configuration File |
| 135 | +### Upload Configuration |
136 | 136 |
|
137 | | -To Upload your configuration to your gist (or create one if your configuration do not have yet) just run: |
| 137 | +To upload your configuration to a gist (or create a new gist if one doesn’t exist): |
138 | 138 |
|
139 | | -```shell |
| 139 | +```bash |
140 | 140 | foji upload |
141 | 141 | ``` |
142 | 142 |
|
143 | | -### Download Your Configuration File |
| 143 | +### Download Configuration |
144 | 144 |
|
145 | | -To download a configuration file from someone else just run this command: |
| 145 | +To download a configuration file from a gist: |
146 | 146 |
|
147 | | -```shell |
| 147 | +```bash |
148 | 148 | foji download [gist url] |
149 | 149 | ``` |
150 | 150 |
|
151 | | -### Sync Your Configuration File |
| 151 | +### Sync Configuration |
152 | 152 |
|
153 | | -Update you configuration file from it's url |
| 153 | +To sync your local configuration with its URL: |
154 | 154 |
|
155 | | -```shell |
| 155 | +```bash |
156 | 156 | foji sync |
157 | 157 | ``` |
158 | 158 |
|
159 | | -## Development |
| 159 | +> [!CAUTION] |
| 160 | +> Be careful when syncing from external sources. Always verify the origin of the gist to avoid overriding your custom commands. |
| 161 | +
|
| 162 | +## 🛠️ Development |
160 | 163 |
|
161 | | -If you want to contribute to Foji or customize it to your needs, you can clone the repository and build it yourself: |
| 164 | +If you want to contribute or customize Foji, follow these steps: |
162 | 165 |
|
163 | 166 | 1. Clone the repository: |
164 | 167 |
|
165 | | -```shell |
166 | | -git clone https://github.com/imLymei/foji.git |
167 | | -cd foji |
168 | | -``` |
| 168 | + ```bash |
| 169 | + git clone https://github.com/imLymei/foji.git |
| 170 | + cd foji |
| 171 | + ``` |
169 | 172 |
|
170 | | -2. Install the dependencies: |
| 173 | +2. Install dependencies: |
171 | 174 |
|
172 | | -```shell |
173 | | -npm install |
174 | | -``` |
| 175 | + ```bash |
| 176 | + npm install |
| 177 | + ``` |
175 | 178 |
|
176 | | -3. Build and install the project: |
| 179 | +3. Build the project: |
177 | 180 |
|
178 | | -```shell |
179 | | -npm run build:local |
180 | | -``` |
| 181 | + ```bash |
| 182 | + npm run build:local |
| 183 | + ``` |
| 184 | + |
| 185 | +## 📜 Credits |
| 186 | + |
| 187 | +This project makes use of several open-source libraries and tools. Special thanks to the following: |
| 188 | + |
| 189 | +- [TypeScript](https://www.typescriptlang.org/) - Type-safe JavaScript. |
| 190 | +- [Commander](https://www.npmjs.com/package/commander) - CLI framework. |
| 191 | +- [@inquirer/prompts](https://www.npmjs.com/package/@inquirer/prompts) - Command-line prompts. |
| 192 | +- [semantic-release](https://www.npmjs.com/package/semantic-release) - Automates versioning and package publishing. |
| 193 | +- [fast-levenshtein](https://www.npmjs.com/package/fast-levenshtein) - Fast string distance algorithm. |
181 | 194 |
|
182 | | -## License |
| 195 | +## 📄 License |
183 | 196 |
|
184 | 197 | Foji is licensed under the MIT License. |
185 | 198 |
|
|
0 commit comments