bashly 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +10 -7
- data/lib/bashly/commands/add.rb +6 -0
- data/lib/bashly/commands/generate.rb +1 -1
- data/lib/bashly/extensions/string.rb +4 -0
- data/lib/bashly/templates/lib/colors.sh +2 -2
- data/lib/bashly/templates/lib/config.sh +2 -2
- data/lib/bashly/templates/lib/yaml.sh +35 -0
- data/lib/bashly/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30efdcbeb1d466ddb9a273e1faee68a2f2a2d4290d75e6ea405e594c60cf029d
|
4
|
+
data.tar.gz: 637e95e22f679ade3483129a473c3cb912c16db6c976a6eb49d47921ab2fd4c9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6bfd470d14131da08363c8b2f65412c09487927213a1ce2afdef0d1ebf06f3c655718d55275baed2502bd6a4f7f9c5ed723f1970e56d196b5d42585d0e84dd63
|
7
|
+
data.tar.gz: b203ffe70e063a58f0e0fd3a0bfd4d5fff42ac4a9e23aaaa18ea68a89c2fd204a4aafb06fc13b23bf21084283b487fb207c84f46610242056be582e456283f41
|
data/README.md
CHANGED
@@ -39,12 +39,13 @@ programming language.
|
|
39
39
|
|
40
40
|
Bahsly is responsible for:
|
41
41
|
|
42
|
+
- Generating a **single, standalone bash script**.
|
42
43
|
- Generating **usage texts** and help screens, showing your tool's arguments,
|
43
44
|
flags and subcommands (works for subcommands also).
|
44
45
|
- Parsing the user's command line and extracting:
|
45
46
|
- Optional or required **positional arguments**.
|
46
47
|
- Optional or required **option flags** (with or without flag arguments).
|
47
|
-
- **Subcommands
|
48
|
+
- **Subcommands** (and sub-subcommands).
|
48
49
|
- Standard flags (like **--help** and **--version**).
|
49
50
|
- Providing you with a place to input your code for each of the functions
|
50
51
|
your tool performs, and merging it back to the final script.
|
@@ -52,6 +53,7 @@ Bahsly is responsible for:
|
|
52
53
|
library functions:
|
53
54
|
- **Color output**.
|
54
55
|
- **Config file management** (INI format).
|
56
|
+
- **YAML parsing**.
|
55
57
|
|
56
58
|
Usage
|
57
59
|
--------------------------------------------------
|
@@ -126,10 +128,11 @@ command and subcommands (under the `commands` definition).
|
|
126
128
|
# The name of the script or subcommand
|
127
129
|
name: myscript
|
128
130
|
|
129
|
-
# An additional, optional
|
130
|
-
# variation of the command name
|
131
|
+
# An additional, optional pattern - usually used to denote a one letter
|
132
|
+
# variation of the command name.
|
133
|
+
# You can add '*' as suffix, to denote a "starts with" pattern.
|
131
134
|
# Applicable only in subcommands
|
132
|
-
short: m
|
135
|
+
short: m*
|
133
136
|
|
134
137
|
# The header text to display when using --help
|
135
138
|
# This can have multiple lines. In this case, the first line will be used as
|
@@ -154,17 +157,17 @@ environment_variable:
|
|
154
157
|
|
155
158
|
# Specify the array of subcommands to generate.
|
156
159
|
# Each subcommand will have its own args and flags.
|
157
|
-
# If this is provided, you cannot
|
160
|
+
# If this is provided, you cannot specify flags or args.
|
158
161
|
commands:
|
159
162
|
- ...
|
160
163
|
|
161
164
|
# Specify the array of positional arguments this script needs.
|
162
|
-
# If this is provided, then you cannot
|
165
|
+
# If this is provided, then you cannot specify commands.
|
163
166
|
args:
|
164
167
|
- ...
|
165
168
|
|
166
169
|
# Specify the array of option flags this script needs.
|
167
|
-
# If this is provided, then you cannot
|
170
|
+
# If this is provided, then you cannot specify commands.
|
168
171
|
flags:
|
169
172
|
- ...
|
170
173
|
```
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -7,6 +7,7 @@ module Bashly
|
|
7
7
|
usage "bashly add lib [--force]"
|
8
8
|
usage "bashly add config [--force]"
|
9
9
|
usage "bashly add colors [--force]"
|
10
|
+
usage "bashly add yaml [--force]"
|
10
11
|
usage "bashly add (-h|--help)"
|
11
12
|
|
12
13
|
option "-f --force", "Overwrite existing files"
|
@@ -15,6 +16,7 @@ module Bashly
|
|
15
16
|
command "lib", "Create the additional lib directory for additional user scripts. All *.sh scripts in this folder will be included in the final bash script."
|
16
17
|
command "config", "Add standard functions for handling INI files to the lib directory."
|
17
18
|
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
19
|
+
command "yaml", "Add standard functions for reading YAML files to the lib directory."
|
18
20
|
|
19
21
|
environment "BASHLY_SOURCE_DIR", "The path to use for creating the configuration file [default: src]"
|
20
22
|
|
@@ -34,6 +36,10 @@ module Bashly
|
|
34
36
|
safe_copy_lib "colors.sh"
|
35
37
|
end
|
36
38
|
|
39
|
+
def yaml_command
|
40
|
+
safe_copy_lib "yaml.sh"
|
41
|
+
end
|
42
|
+
|
37
43
|
private
|
38
44
|
def safe_copy_lib(libfile)
|
39
45
|
safe_copy asset("templates/lib/#{libfile}"), "#{Settings.source_dir}/lib/#{libfile}"
|
@@ -54,7 +54,7 @@ module Bashly
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def create_master_script
|
57
|
-
master_script = command.render
|
57
|
+
master_script = command.render('master_script').lint
|
58
58
|
File.write master_script_path, master_script
|
59
59
|
FileUtils.chmod "+x", master_script_path
|
60
60
|
say "created !txtgrn!#{master_script_path}"
|
@@ -5,8 +5,8 @@
|
|
5
5
|
# Usage:
|
6
6
|
# Use any of the functions below to color or format a portion of a string.
|
7
7
|
#
|
8
|
-
#
|
9
|
-
#
|
8
|
+
# echo "before $(red this is red) after"
|
9
|
+
# echo "before $(green_bold this is green_bold) after"
|
10
10
|
#
|
11
11
|
# ---
|
12
12
|
|
@@ -10,8 +10,8 @@
|
|
10
10
|
# ---
|
11
11
|
|
12
12
|
# Create a new config file.
|
13
|
-
# There is normally no need to use this fucntion, it is used by
|
14
|
-
# as needed.
|
13
|
+
# There is normally no need to use this fucntion, it is used by other
|
14
|
+
# functions as needed.
|
15
15
|
config_init() {
|
16
16
|
CONFIG_FILE=${CONFIG_FILE:=config.ini}
|
17
17
|
[[ -f "$CONFIG_FILE" ]] || touch "$CONFIG_FILE"
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# ---
|
2
|
+
# YAML parser
|
3
|
+
# This file is a part of Bashly standard library
|
4
|
+
# Does not support arrays, only hashes
|
5
|
+
#
|
6
|
+
# Source: https://stackoverflow.com/a/21189044/413924
|
7
|
+
#
|
8
|
+
# Usage:
|
9
|
+
#
|
10
|
+
# yaml_load "settings.yml" # print variables
|
11
|
+
# yaml_load "settings.yml" "config_" # use prefix
|
12
|
+
# eval $(yaml_load "settings.yml") # create variables in scope
|
13
|
+
#
|
14
|
+
# ---
|
15
|
+
|
16
|
+
yaml_load() {
|
17
|
+
local prefix=$2
|
18
|
+
local s='[[:space:]]*' w='[a-zA-Z0-9_]*'
|
19
|
+
local fs
|
20
|
+
|
21
|
+
fs=$(echo @|tr @ '\034')
|
22
|
+
|
23
|
+
sed -ne "s|^\($s\):|\1|" \
|
24
|
+
-e "s|^\($s\)\($w\)$s:${s}[\"']\(.*\)[\"']$s\$|\1$fs\2$fs\3|p" \
|
25
|
+
-e "s|^\($s\)\($w\)$s:$s\(.*\)$s\$|\1$fs\2$fs\3|p" "$1" |
|
26
|
+
awk -F"$fs" '{
|
27
|
+
indent = length($1)/2;
|
28
|
+
vname[indent] = $2;
|
29
|
+
for (i in vname) {if (i > indent) {delete vname[i]}}
|
30
|
+
if (length($3) > 0) {
|
31
|
+
vn=""; for (i=0; i<indent; i++) {vn=(vn)(vname[i])("_")}
|
32
|
+
printf("%s%s%s=\"%s\"\n", "'"$prefix"'",vn, $2, $3);
|
33
|
+
}
|
34
|
+
}'
|
35
|
+
}
|
data/lib/bashly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bashly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -85,6 +85,7 @@ files:
|
|
85
85
|
- lib/bashly/templates/lib/colors.sh
|
86
86
|
- lib/bashly/templates/lib/config.sh
|
87
87
|
- lib/bashly/templates/lib/sample_function.sh
|
88
|
+
- lib/bashly/templates/lib/yaml.sh
|
88
89
|
- lib/bashly/templates/minimal.yml
|
89
90
|
- lib/bashly/templates/strings.yml
|
90
91
|
- lib/bashly/version.rb
|