Skip to content

Commit

Permalink
refacto(cli): update the cli
Browse files Browse the repository at this point in the history
  • Loading branch information
bwnyasse committed Feb 8, 2021
1 parent 0f5c4e5 commit baf594b
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 52 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,11 @@ lefthook install
To ensure that your environment is ready for contribution, please run the following command at the root of the project:

```sh
./tezart.sh --run-setup
./tezart.sh doctor
```

You can add an alias like this `alias tezart='./tezart'` to avoid calling the command line with `./`

Following is a sample of a correct setup :

![a-sample-setup](./doc/setup/a-sample-correct-setup.png)
Expand Down
Binary file modified doc/setup/a-current-usage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/setup/a-sample-correct-setup.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion tezart.sh → tezart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash

# utility functions
/bin/bash ./tool/tezart.sh $@
/bin/bash ./tool/tezart $@
8 changes: 6 additions & 2 deletions tool/logger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#
###################################################################

readonly BOLD=$(tput bold)
export NORMAL=$(tput sgr0)
readonly BLUE="\\033[1;34m"
readonly RED="\\033[1;31m"
readonly GREEN="\\033[1;32m"
Expand Down Expand Up @@ -69,10 +71,12 @@ log::title() {
}

log::title_success() {
echo -e "\n $* $GREEN $CHECK_MARK $END"
echo -e "\n $GREEN [✓] $END $* "
}


log::title_warning() {
echo -e "\n $YELLOW [!] $END $* "
}

log::message() {
echo -e " $* "
Expand Down
98 changes: 50 additions & 48 deletions tool/tezart.sh → tool/tezart
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ source $BASEDIR/../tool/logger.sh
# ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝ ╚══════╝

USAGE_HELP='Display this message'
USAGE_RUN_DOCTOR='Process to run the setup of the project'
USAGE_RUN_TESTS='Process to run tests'
USAGE_RUN_SETUP='Process to run the setup of the project'
USAGE_RUN_COVERAGE_DEV='Process to run the code coverage in dev environment'
USAGE_RUN_COVERAGE='Process to run the code coverage in dev environment'

usage() {

Expand All @@ -34,10 +34,10 @@ usage() {
OPTIONS:
========
--run-setup $USAGE_RUN_SETUP
--run-tests $USAGE_RUN_TESTS
--run-coverage-dev $USAGE_RUN_COVERAGE_DEV
-h $USAGE_HELP
doctor $USAGE_RUN_DOCTOR
tests $USAGE_RUN_TESTS
coverage $USAGE_RUN_COVERAGE
-h $USAGE_HELP
EOF
}
Expand All @@ -59,7 +59,7 @@ tezart::_check_localhost_chain() {

if [[ isSanboxRunning -eq 0 ]]
then
log::title_success " - a tezos sandbox is running locally"
log::title_success "a tezos sandbox is running locally"
else
log::error_and_exit "Please read the README.md to run a tezos sandbox locally."
fi
Expand All @@ -71,23 +71,23 @@ tezart::_check_requirements() {
## check for docker
if docker --version &>/dev/null
then
log::title_success " - docker is present on your system"
log::title_success "docker is present on your system"
else
log::error_and_exit 'The docker is missing on your system. Please read the README.md to install it'
fi

## check for dart
if dart --version &>/dev/null
then
log::title_success " - dart sdk is present on your system"
log::title_success "dart sdk is present on your system"
else
log::error_and_exit 'The dart sdk is missing on your system. Please read the README.md to install it'
fi

## check for lefthook
if lefthook &>/dev/null
then
log::title_success " - lefthook is present on your system"
log::title_success "lefthook is present on your system"
else
log::error_and_exit 'The Lefthook plugin is missing on your system. Please read the README.md to install it'
fi
Expand All @@ -98,9 +98,9 @@ tezart::_init_env_var() {

if [[ -f .env.test ]]
then
log::warn "A .env.test file is already found. the script won't generate a new one"
log::title_warning ".env.test file is already found. The script won't generate a new one"
else
log::title_success " - a new .env.test file is generated for your tests"
log::title_success "a new .env.test file is generated for your tests"
cp .env.dist .env.test
fi
}
Expand All @@ -109,8 +109,8 @@ tezart::_init_env_var() {
### PUBLIC
###########

tezart::run_coverage_dev() {
log::info "$USAGE_RUN_COVERAGE_DEV :"
tezart::run_coverage() {
log::info "$USAGE_RUN_COVERAGE :"

pub get

Expand All @@ -124,8 +124,8 @@ tezart::run_coverage_dev() {
open coverage/index.html
}

tezart::run_setup() {
log::info "$USAGE_RUN_SETUP :"
tezart::run_doctor() {
log::info "$USAGE_RUN_DOCTOR :"

tezart::_check_requirements
tezart::_check_localhost_chain
Expand Down Expand Up @@ -154,14 +154,14 @@ tezart::run_tests() {

#
## Optional parameters
RUN_DOCTOR=
RUN_TESTS=
RUN_SETUP=
RUN_COVERAGE_DEV=
RUN_COVERAGE=

main() {
[[ -n $RUN_DOCTOR ]] && tezart::run_doctor
[[ -n $RUN_TESTS ]] && tezart::run_tests
[[ -n $RUN_SETUP ]] && tezart::run_setup
[[ -n $RUN_COVERAGE_DEV ]] && tezart::run_coverage_dev
[[ -n $RUN_COVERAGE ]] && tezart::run_coverage

exit 0
}
Expand All @@ -173,35 +173,37 @@ main() {
# ╚██████╔╝███████╗ ██║ ╚██████╔╝██║ ███████║
# ╚═════╝ ╚══════╝ ╚═╝ ╚═════╝ ╚═╝ ╚══════╝


while getopts :-:h option
do
case $option in
-)
case $OPTARG in
run-setup)
RUN_SETUP=1
;;
run-tests)
RUN_TESTS=1
;;
run-coverage-dev)
RUN_COVERAGE_DEV=1
;;
*)
log::error "Unknow parameter '--$OPTARG' !"
usage
exit 2
;;
esac
;;
:|?|h)
[[ $option == \? ]] && log::error "The parameter -$OPTARG can't be used !"
[[ $option == : ]] && log::error "The parameter -$OPTARG needs an argument !"
# Parse options to the `tezart` command
while getopts ":h" opt; do
case ${opt} in
h )
usage
exit $([[ $option == h ]] && echo 0 || echo 2)
;;
exit 0
;;
\? )
log::error "Invalid Option: -$OPTARG "
usage
exit 1
;;
esac
done

shift $((OPTIND -1))

subcommand=$1; shift # Remove 'tezart' from the argument list
case "$subcommand" in
doctor)
RUN_DOCTOR=1
;;
tests)
RUN_TESTS=1
;;
coverage)
RUN_COVERAGE=1
;;
*)
log::error "Unknow parameter '$subcommand' !"
usage
exit 2
;;
esac
main

0 comments on commit baf594b

Please sign in to comment.