Skip to content

Commit

Permalink
Merge branch 'main' into fix/user
Browse files Browse the repository at this point in the history
  • Loading branch information
leocavalcante authored Oct 24, 2023
2 parents bf03aeb + b8df3f8 commit 94cb0c0
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
on:
- pull_request
pull_request:
push:
branches:
- main

jobs:
test:
Expand Down
37 changes: 22 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,30 @@ cd ~/.hfctl
git pull
```

### Usage
## Usage
```shell
hfctl <command> [arguments]
```

| Command | Description |
### Commands
| Name | Description |
| --- | --- |

| `hfctl help` | Shows this help message |
| `hfctl version` | Displays hfctl and image version |
| `hfctl self-update` | Updates hfctl to the latest version |
| `hfctl create` | Creates a new Hyperf project |
| `hfctl composer` | Runs composer commands |
| `hfctl start` | Starts the Hyperf server |
| `hfctl stop` | Stops the Hyperf server |
| `hfctl restart` | Restart the Hyperf server |
| `hfctl watch` | Starts the Hyperf server with hyperf/watcher |
| `hfctl bin` (`cmd` or `command`) | Runs Hyperf commands (i.e.: `php bin/hyperf.php`) |
| `hfctl logs` | Shows the Hyperf container logs |
| `help` | Shows this help message |
| `version` | Displays `hfctl` and image version |
| `self-update` | Updates `hfctl` to the latest version |
| `create <project-name>` | Creates a new Hyperf project |
| `composer <subcommand>` | Runs composer commands |
| `console <command>` | Runs Hyperf console commands (`php bin/hyperf.php <command>`) |
| `start [port]` | Starts the Hyperf server (default port `9501`) |
| `stop` | Stops the Hyperf server |
| `restart` | Restart the Hyperf server |
| `watch [port]` | Starts the Hyperf watcher (default port `9501`) |
| `up` | Runs Docker Compose up |
| `down` | Runs Docker Compose down |
| `logs [-f\|--follow]` | Shows the Hyperf container logs (use `-f` or `--follow` to follow logs) |
| `test` | Runs PHPUnit tests |
| `lint` | Runs PHP Coding Standards Fixer |
| `analyse [-l<level>]` | Runs PHPStan analyses (default level `5`) |

## Contributing

Please visit [CONTRIBUTING.md](CONTRIBUTING.md).
62 changes: 48 additions & 14 deletions hfctl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash

HFCTL=v0.3.0
HFCTL=v0.4.0
IMAGE=hyperf/hyperf:8.2-alpine-v3.18-swoole-v5.1
HFCID=runtime/hfctl.cid

Expand All @@ -14,17 +14,22 @@ help() {
echo -e " hfctl <command> [arguments]"
echo -e ""
echo -e "\033[1;33mCommands:\033[0m"
echo -e " \033[1;32mhelp\033[0m Shows this help message"
echo -e " \033[1;32mversion\033[0m Displays hfctl and image version"
echo -e " \033[1;32mself-update\033[0m Updates hfctl to the latest version"
echo -e " \033[1;32mcreate <project-name> [-it]\033[0m Creates a new Hyperf project \033[1;37m(use -it for interactive mode)\033[0m"
echo -e " \033[1;32mcomposer <subcommand>\033[0m Runs composer commands"
echo -e " \033[1;32mstart [port]\033[0m Starts the Hyperf server \033[1;37m(default port 9501)\033[0m"
echo -e " \033[1;32mstop\033[0m Stops the Hyperf server"
echo -e " \033[1;32mrestart\033[0m Restart the Hyperf server"
echo -e " \033[1;32mwatch [port]\033[0m Starts the Hyperf watcher \033[1;37m(default port 9501)\033[0m"
echo -e " \033[1;32mconsole <command>\033[0m Runs Hyperf console commands \033[1;37m(php bin/hyperf.php <command>)\033[0m"
echo -e " \033[1;32mlogs [-f|--follow]\033[0m Shows the Hyperf container logs \033[1;37m(use -f or --follow to follow logs)\033[0m"
echo -e " \033[1;32mhelp\033[0m Shows this help message"
echo -e " \033[1;32mversion\033[0m Displays hfctl and image version"
echo -e " \033[1;32mself-update\033[0m Updates hfctl to the latest version"
echo -e " \033[1;32mcreate <project-name> Creates a new Hyperf project"
echo -e " \033[1;32mcomposer <subcommand>\033[0m Runs composer commands"
echo -e " \033[1;32mconsole <command>\033[0m Runs Hyperf console commands \033[1;37m(php bin/hyperf.php <command>)\033[0m"
echo -e " \033[1;32mstart [port]\033[0m Starts the Hyperf server \033[1;37m(default port 9501)\033[0m"
echo -e " \033[1;32mstop\033[0m Stops the Hyperf server"
echo -e " \033[1;32mrestart\033[0m Restart the Hyperf server"
echo -e " \033[1;32mwatch [port]\033[0m Starts the Hyperf watcher \033[1;37m(default port 9501)\033[0m"
echo -e " \033[1;32mup\033[0m Runs Docker Compose up"
echo -e " \033[1;32mdown\033[0m Runs Docker Compose down"
echo -e " \033[1;32mlogs [-f|--follow]\033[0m Shows the Hyperf container logs \033[1;37m(use -f or --follow to follow logs)\033[0m"
echo -e " \033[1;32mtest\033[0m Runs PHPUnit tests"
echo -e " \033[1;32mlint\033[0m Runs PHP Coding Standards Fixer"
echo -e " \033[1;32manalyse [-l<level>]\033[0m Runs PHPStan analyses \033[1;37m(default level 5)\033[0m"
echo -e ""
}

Expand Down Expand Up @@ -88,14 +93,43 @@ console() {
}

logs() {
pre-check cid
docker logs $@ $(cat $HFCID)
DC=$(docker compose ps --format 'json {{.Name}}')
if [[ -n $DC ]]; then
docker compose logs $@
else
pre-check cid
docker logs $@ $(cat $HFCID)
fi
}

up() {
docker compose up -d
}

down() {
docker compose down --remove-orphans
}

test() {
docker-run ${HFTTY:--it} php vendor/bin/co-phpunit --prepend test/bootstrap.php $@
}

lint() {
docker-run ${HFTTY:--it} php vendor/bin/php-cs-fixer fix $@
}

analyse() {
docker-run ${HFTTY:--it} php vendor/bin/phpstan analyse ${@:--l5} app
}

docker-run() {
docker run --user $UID --rm -w /opt -v ./:/opt $1 --entrypoint $2 $IMAGE ${@:3}
}

ps() {
docker ps
}

pre-check() {
if ! [ -f bin/hyperf.php ]; then
echo -e "\033[0;31mAre you in a Hyperf project?\033[0m"
Expand Down
15 changes: 15 additions & 0 deletions hfctl_test
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ function test_should_run_hyperf_console_commands() {
assert_contains "Console Tool" "$($HFCTL console)"
}

function test_should_run_test_command() {
cd $HFDIR
assert_contains "OK (1 test, 2 assertions)" "$($HFCTL test)"
}

function test_should_run_lint_command() {
cd $HFDIR
assert_contains "Fixed 8 of 27 files" "$($HFCTL lint 2> /dev/null)"
}

function test_should_run_analyse_command() {
cd $HFDIR
assert_contains "No errors" "$($HFCTL analyse 2> /dev/null)"
}

if [[ $0 == "./hfctl_test" ]]; then
export HFTTY="-lno-tty"
./bashunit ./hfctl_test $@
Expand Down

0 comments on commit 94cb0c0

Please sign in to comment.