Skip to content

Commit 7f6c370

Browse files
authored
Merge pull request #29 from imLymei/dev
Dev
2 parents 126e424 + 06e1af0 commit 7f6c370

File tree

4 files changed

+44
-27
lines changed

4 files changed

+44
-27
lines changed

CONTRIBUTING.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,41 @@ Welcome to the project! We're glad you're here and interested in contributing. B
44

55
## How to Contribute
66

7+
### Repository Structure
8+
9+
This repository uses a automated version release using the mains 3 branches:
10+
11+
- **master**: Contains the code on the actual `@latest` package channel.
12+
- **beta**: Contains the code on the actual `@beta` package channel.
13+
- **dev**: Contains the code of actual development, every `BREAKING CHANGE` and `feat` commit must be done on this branch.
14+
15+
### Step by Step
16+
717
1. **Fork the repository:** Click on the "Fork" button on the top right corner of the repository's page, then clone your fork locally.
818

9-
2. **Create a new branch:** Make your changes in a new branch created from the `main` branch. Choose a descriptive name for your branch related to the issue or feature you're working on.
19+
2. **Create a new branch:** Make your changes in a new branch created from the `dev` branch or `main` for `fix` or others specific situations. Choose a descriptive name for your branch related to the issue or feature you're working on.
1020

1121
3. **Make your changes:** Implement the changes or additions you'd like to contribute. Please follow any existing coding style and conventions.
1222

1323
4. **Test your changes:** Ensure that your changes do not break existing functionality. If you're adding new features, include tests to cover your code.
1424

15-
5. **Commit your changes:** Make meaningful and atomic commits. Please provide a clear and descriptive commit message for each commit.
25+
5. **Commit your changes:** Make meaningful and atomic commits. Please provide a [clear and descriptive commit message](https://www.conventionalcommits.org/en/v1.0.0/#summary) for each commit.
1626

1727
6. **Push your changes:** Once your changes are ready, push your branch to your fork of the repository.
1828

1929
7. **Create a Pull Request (PR):** Go back to the original repository and navigate to the Pull Requests tab. Click on "New Pull Request" and choose your branch as the compare branch. Fill out the PR template with relevant information and details about your changes.
2030

2131
8. **Review and address feedback:** Be open to feedback and iterate on your changes if necessary. Respond promptly to any comments or requests for changes from the maintainers.
2232

23-
9. **Merge your PR:** Once your PR has been approved and all checks have passed, a maintainer will merge your changes into the main branch. Congratulations on your contribution!
33+
9. **Merge your PR:** Once your PR has been approved and all checks have passed, a maintainer will merge your changes into the respective branch. Congratulations on your contribution!
2434

2535
## Code of Conduct
2636

2737
Please note that this project is governed by our [Code of Conduct](CODE_OF_CONDUCT.md). By participating in this project, you agree to abide by its terms.
2838

2939
## Contributor License Agreement (CLA)
3040

31-
By contributing to this project, you agree to license your contributions under the [project's license](LICENSE.md).
41+
By contributing to this project, you agree to license your contributions under the [project's license](LICENSE).
3242

3343
## Help and Support
3444

README.md

Lines changed: 12 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Foji
1+
# Foji ⚒️
22

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 crafted 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.
44

55
## Features
66

@@ -16,19 +16,21 @@ Foji is a command-line interface (CLI) tool designed to help you automate and ma
1616
- [x] Configuration can be downloaded from cloud
1717
- [x] Local configuration can be synced from cloud
1818

19-
## Installation
19+
## System Dependencies
20+
21+
Foji makes use of [Node.js](https://nodejs.org/) package manager to be installed.
2022

21-
Before installing Foji, make sure you have [Node.js](https://nodejs.org/) installed on your machine.
23+
## Installation
2224

23-
To install Foji globally, run the following command:
25+
To install Foji run the following command:
2426

2527
```shell
2628
npm i foji -g
2729
```
2830

2931
## Usage
3032

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.
33+
Foji saves your commands and your configurations 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.
3234

3335
### Running a Command
3436

@@ -37,13 +39,14 @@ To run a `command` just use:
3739
```shell
3840
foji [command name] [...command args]
3941
```
42+
4043
Simple as that.
4144

4245
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.
4346

4447
### Skipping a Argument
4548

46-
You also can skip a (optional) argument using "_":
49+
You also can skip a (optional) argument using "\_":
4750

4851
```shell
4952
foji [command name] [argument one] _ [argument three]
@@ -81,10 +84,10 @@ All `commands` can have four types of `arguments`:
8184

8285
3. Optional arguments with default values:
8386

84-
- Similar to optional arguments, but if not provided, they will add a default value. `<options??--ts --tailwind --src>`
87+
- Similar to optional arguments, but if not provided, they will add a default value. `<options ?? --ts --tailwind --src>`
8588

8689
```json
87-
"command":"echo <requiredArgumentOne> <optionalArgumentOne??My Default Value>"
90+
"command":"echo <requiredArgumentOne> <optionalArgumentOne ?? My Default Value>"
8891
```
8992

9093
4. Ternaries:
@@ -97,18 +100,6 @@ All `commands` can have four types of `arguments`:
97100

98101
Note that all `Required arguments` must be provided **BEFORE** any of the other arguments
99102

100-
incorrect:
101-
102-
```json
103-
"command": "do command <argOne?> <argTwo>"
104-
```
105-
106-
correct:
107-
108-
```json
109-
"command": "do command <argOne> <argTwo?>"
110-
```
111-
112103
### Remove a Command
113104

114105
To remove a `command` you can use the `remove` command

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ const program = new Command()
2323
.argument('[command]', 'Command that you want to run')
2424
.argument('[args...]', 'Arguments for the command')
2525
.option('-d, --debug', 'Enable debugging features', false)
26+
.passThroughOptions(true)
2627
.action(async (commandName?: string, args?: string[]) => {
2728
const userConfig = getConfig();
2829
const configCommands = userConfig.commands;

src/lib/utils.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type CommandArg = {
1515
isOptional?: boolean;
1616
defaultValue?: string;
1717
alternativeValue?: string;
18+
isSpread?: boolean;
1819
};
1920

2021
export const USER_DIRECTORY = os.homedir();
@@ -111,13 +112,14 @@ export function formatCommand(
111112

112113
let allowRequired = true;
113114

114-
const commandArguments: CommandArg[] = commandArgs.map((arg) => {
115+
const commandArguments: CommandArg[] = commandArgs.map((arg, index) => {
115116
const object: CommandArg = { name: '' };
116117

117118
const hasDefaultValue = arg.includes('??');
118119
const hasElse = !hasDefaultValue && arg.includes(':');
119120
const isTernary = !hasDefaultValue && hasElse && arg.includes('?');
120121
const isOptional = !hasDefaultValue && !hasElse && arg.includes('?');
122+
const isSpread = arg.includes('...');
121123

122124
// TODO - make linting function
123125

@@ -141,6 +143,16 @@ export function formatCommand(
141143
object.name = name;
142144
object.isOptional = true;
143145

146+
allowRequired = false;
147+
} else if (isSpread) {
148+
if (index !== commandArgs.length - 1)
149+
error('You can only use a spread argument at the last position');
150+
151+
const name = arg.replace('...', '').trim();
152+
object.name = name;
153+
object.isOptional = true;
154+
object.isSpread = true;
155+
144156
allowRequired = false;
145157
} else {
146158
if (!allowRequired)
@@ -164,7 +176,10 @@ export function formatCommand(
164176

165177
for (let index = 0; index < commandArguments.length; index++) {
166178
const arg = commandArguments[index];
167-
let argValue = arg.alternativeValue
179+
180+
let argValue = arg.isSpread
181+
? args.slice(index).join(' ')
182+
: arg.alternativeValue
168183
? args[index]
169184
? arg.defaultValue
170185
: arg.alternativeValue

0 commit comments

Comments
 (0)