Skip to content

Commit 146d046

Browse files
authored
Merge pull request #298 from DannyBen/add/dependencies-as-hash
Allow command.dependencies to be a hash for custom 'how to install' messages
2 parents 289360e + f83da28 commit 146d046

File tree

21 files changed

+158
-55
lines changed

21 files changed

+158
-55
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
/doc
66
/Gemfile.lock
77
/gems
8+
/spec/status.txt
89
/spec/tmp
910
/tmp
1011
/toc.txt

examples/command-examples/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ commands:
6666
# over how the examples are displayed. Note the use of the '|-' marker
6767
# that tells YAML to use the string as is, including the newlines it contains.
6868
examples: |-
69-
Upload a file
69+
Upload a file
7070
$ cli upload profile.png -u admin -p s3cr3t
7171
7272
Upload a file (you will be prompted to provide a password)
@@ -137,10 +137,10 @@ Arguments:
137137
138138
Examples:
139139
Upload a file
140-
$ cli upload profile.png --user admin
140+
$ cli upload profile.png -u admin -p s3cr3t
141141
142-
Upload a file and prompt for password
143-
$ cli upload profile.png -u admin -p
142+
Upload a file (you will be prompted to provide a password)
143+
$ cli upload profile.png --user admin
144144
145145
146146

examples/command-examples/src/bashly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ commands:
4949
# over how the examples are displayed. Note the use of the '|-' marker
5050
# that tells YAML to use the string as is, including the newlines it contains.
5151
examples: |-
52-
Upload a file
52+
Upload a file
5353
$ cli upload profile.png -u admin -p s3cr3t
5454
5555
Upload a file (you will be prompted to provide a password)

examples/dependencies/.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
cli
1+
cli
2+
src/*.sh
3+
src/lib

examples/dependencies/README.md

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ This example was generated with:
77

88
```bash
99
$ bashly init
10+
$ bashly add colors
1011
# ... now edit src/bashly.yml to match the example ...
1112
$ bashly generate
1213
```
@@ -34,6 +35,12 @@ commands:
3435

3536
- name: upload
3637
help: Upload something
38+
39+
# Dependencies can also be defined as a hash of 'command: message' pairs.
40+
# The message can use colors from the colors library (bashly add colors).
41+
dependencies:
42+
mini-docker: install with $(green gem install mini-docker)
43+
docker: visit https://docker.com for more information
3744
```
3845
3946
@@ -51,10 +58,8 @@ missing dependency: shmurl
5158
### `$ ./cli upload`
5259

5360
```shell
54-
# this file is located in 'src/upload_command.sh'
55-
# code for 'cli upload' goes here
56-
# you can edit it freely and regenerate (it will not be overwritten)
57-
args: none
61+
missing dependency: mini-docker
62+
install with gem install mini-docker
5863
5964
6065
```

examples/dependencies/src/bashly.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,9 @@ commands:
1616

1717
- name: upload
1818
help: Upload something
19+
20+
# Dependencies can also be defined as a hash of 'command: message' pairs.
21+
# The message can use colors from the colors library (bashly add colors).
22+
dependencies:
23+
mini-docker: install with $(green gem install mini-docker)
24+
docker: visit https://docker.com for more information
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Code here runs inside the initialize() function
2-
# Use it for anything that you need to run before any other function, like
3-
# setting environment variables:
4-
# CONFIG_FILE=settings.ini
5-
#
6-
# Feel free to empty (but not delete) this file.
1+
## Code here runs inside the initialize() function
2+
## Use it for anything that you need to run before any other function, like
3+
## setting environment variables:
4+
## CONFIG_FILE=settings.ini
5+
##
6+
## Feel free to empty (but not delete) this file.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
## Color functions [@bashly-upgrade colors]
2+
## This file is a part of Bashly standard library
3+
##
4+
## Usage:
5+
## Use any of the functions below to color or format a portion of a string.
6+
##
7+
## echo "before $(red this is red) after"
8+
## echo "before $(green_bold this is green_bold) after"
9+
##
10+
## Color output will be disabled if `NO_COLOR` environment variable is set
11+
## in compliance with https://no-color.org/
12+
##
13+
print_in_color() {
14+
local color="$1"
15+
shift
16+
if [[ -z ${NO_COLOR+x} ]]; then
17+
printf "$color%b\e[0m\n" "$*";
18+
else
19+
printf "%b\n" "$*";
20+
fi
21+
}
22+
23+
red() { print_in_color "\e[31m" "$*"; }
24+
green() { print_in_color "\e[32m" "$*"; }
25+
yellow() { print_in_color "\e[33m" "$*"; }
26+
blue() { print_in_color "\e[34m" "$*"; }
27+
magenta() { print_in_color "\e[35m" "$*"; }
28+
cyan() { print_in_color "\e[36m" "$*"; }
29+
bold() { print_in_color "\e[1m" "$*"; }
30+
underlined() { print_in_color "\e[4m" "$*"; }
31+
red_bold() { print_in_color "\e[1;31m" "$*"; }
32+
green_bold() { print_in_color "\e[1;32m" "$*"; }
33+
yellow_bold() { print_in_color "\e[1;33m" "$*"; }
34+
blue_bold() { print_in_color "\e[1;34m" "$*"; }
35+
magenta_bold() { print_in_color "\e[1;35m" "$*"; }
36+
cyan_bold() { print_in_color "\e[1;36m" "$*"; }
37+
red_underlined() { print_in_color "\e[4;31m" "$*"; }
38+
green_underlined() { print_in_color "\e[4;32m" "$*"; }
39+
yellow_underlined() { print_in_color "\e[4;33m" "$*"; }
40+
blue_underlined() { print_in_color "\e[4;34m" "$*"; }
41+
magenta_underlined() { print_in_color "\e[4;35m" "$*"; }
42+
cyan_underlined() { print_in_color "\e[4;36m" "$*"; }

examples/dependencies/src/verify_command.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

examples/dependencies/test.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/usr/bin/env bash
22

3+
rm -f src/lib/colors.sh
4+
rm -f src/*.sh
5+
36
set -x
47

8+
bashly add colors
59
bashly generate
610

711
### Try Me ###

0 commit comments

Comments
 (0)