bashly 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +53 -64
- data/lib/bashly/cli.rb +1 -0
- data/lib/bashly/commands/add.rb +62 -0
- data/lib/bashly/commands/base.rb +10 -0
- data/lib/bashly/commands/generate.rb +1 -4
- data/lib/bashly/commands/init.rb +3 -13
- data/lib/bashly/commands/preview.rb +1 -3
- data/lib/bashly/concerns/asset_helper.rb +7 -0
- data/lib/bashly/concerns/renderable.rb +4 -0
- data/lib/bashly/message_strings.rb +36 -0
- data/lib/bashly/models/base.rb +2 -0
- data/lib/bashly/models/command.rb +21 -8
- data/lib/bashly/templates/bashly.yml +10 -0
- data/lib/bashly/templates/lib/colors.sh +32 -0
- data/lib/bashly/templates/lib/config.sh +93 -0
- data/lib/bashly/templates/lib/sample_function.sh +13 -0
- data/lib/bashly/templates/minimal.yml +3 -0
- data/lib/bashly/templates/strings.yml +19 -0
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/master_script.erb +1 -0
- data/lib/bashly/views/command/parse_args_case.erb +2 -2
- data/lib/bashly/views/command/parse_args_while.erb +1 -1
- data/lib/bashly/views/command/required_args_filter.erb +1 -2
- data/lib/bashly/views/command/required_flags_filter.erb +1 -1
- data/lib/bashly/views/command/usage.erb +6 -4
- data/lib/bashly/views/command/usage_args.erb +1 -1
- data/lib/bashly/views/command/usage_commands.erb +2 -2
- data/lib/bashly/views/command/usage_environment_variables.erb +7 -0
- data/lib/bashly/views/command/usage_examples.erb +6 -0
- data/lib/bashly/views/command/usage_fixed_flags.erb +2 -2
- data/lib/bashly/views/command/user_lib.erb +6 -0
- data/lib/bashly/views/flag/case.erb +1 -1
- data/lib/bashly.rb +3 -1
- metadata +13 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 728137708fa1cabea46440dcc99eaded654fbf3f522d86f4bea6b47cb10ce823
|
4
|
+
data.tar.gz: eccdb7dc7bb05af0780a16f2f15f8fff7748127946c7243df720cd8d347bfe68
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 261c3c410b87b9b0693d60dddad9f88aeeaa55160c8ef624366783a76771227c0076fc0aad4f9357220f50a53ab0902323e78287eb3222b40ebe5cafe871a088
|
7
|
+
data.tar.gz: 7164422d5e1027abc69b77b57380ffefb574575f5eaf6362ba8bc5fcad8894135cd7a382b444b3c54cabc6f05ba519d8fa06bcfa503a714feb85bcac031f12f7
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
|
-
|
1
|
+
<div align='center'>
|
2
|
+
<img src='bashly-logo.svg' width=300>
|
3
|
+
|
4
|
+
Bashly - Bash CLI Framework and Generator
|
2
5
|
==================================================
|
3
6
|
|
4
|
-
Create beautiful bash scripts from simple YAML configuration
|
7
|
+
Create beautiful bash scripts from simple YAML configuration
|
5
8
|
|
6
9
|
[![Gem Version](https://badge.fury.io/rb/bashly.svg)](https://badge.fury.io/rb/bashly)
|
7
10
|
[![Build Status](https://travis-ci.com/DannyBen/bashly.svg?branch=master)](https://travis-ci.com/DannyBen/bashly)
|
@@ -11,6 +14,8 @@ Create beautiful bash scripts from simple YAML configuration.
|
|
11
14
|
|
12
15
|
![demo](demo/cast.svg)
|
13
16
|
|
17
|
+
</div>
|
18
|
+
|
14
19
|
---
|
15
20
|
|
16
21
|
Installation
|
@@ -19,6 +24,33 @@ Installation
|
|
19
24
|
$ gem install bashly
|
20
25
|
|
21
26
|
|
27
|
+
What is Bashly
|
28
|
+
--------------------------------------------------
|
29
|
+
|
30
|
+
Bashly is a command line application (written in Ruby) that lets you generate
|
31
|
+
feature-rich bash command line tools.
|
32
|
+
|
33
|
+
The design intention is to let you focus on your specific code, without
|
34
|
+
worrying about command line argument parsing, usage texts, error messages
|
35
|
+
and other functions that are usually handled by a framework in any other
|
36
|
+
programming language.
|
37
|
+
|
38
|
+
Bahsly is responsible for:
|
39
|
+
|
40
|
+
- Generating **usage texts** and help screens, showing your tool's arguments,
|
41
|
+
flags and subcommands (works for subcommands also).
|
42
|
+
- Parsing the user's command line and extracting:
|
43
|
+
- Optional or required **positional arguments**.
|
44
|
+
- Optional or required **option flags** (with or without flag arguments).
|
45
|
+
- **Subcommands**.
|
46
|
+
- Standard flags (like **--help** and **--version**).
|
47
|
+
- Providing you with a place to input your code for each of the functions
|
48
|
+
your tool performs, and merging it back to the final script.
|
49
|
+
- Providing you with additional (optional) framework-style, standard
|
50
|
+
library functions:
|
51
|
+
- **Color output**.
|
52
|
+
- **Config file management** (INI format).
|
53
|
+
|
22
54
|
Usage
|
23
55
|
--------------------------------------------------
|
24
56
|
|
@@ -61,72 +93,19 @@ contains a `commands` definition, it will generate a script with subcommands.
|
|
61
93
|
|
62
94
|
### Sample configuraiton for a script without subcommands
|
63
95
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
name: download
|
68
|
-
help: Sample minimal application without subcommands
|
69
|
-
version: 0.1.0
|
70
|
-
|
71
|
-
args:
|
72
|
-
- name: source
|
73
|
-
required: true
|
74
|
-
help: URL to download from
|
75
|
-
- name: target
|
76
|
-
help: "Target filename (default: same as source)"
|
77
|
-
|
78
|
-
flags:
|
79
|
-
- long: --force
|
80
|
-
short: -f
|
81
|
-
help: Overwrite existing files
|
82
|
-
```
|
83
|
-
|
96
|
+
- Generate this script by running `bashly generate --minimal`
|
97
|
+
- [See the initial sample bashly.yml file](examples/minimal/src/bashly.yml)
|
98
|
+
- [See the generated bash script](examples/minimal/download)
|
84
99
|
|
85
100
|
### Sample configuraiton for a script with subcommands
|
86
101
|
|
87
|
-
|
102
|
+
- Generate this script by running `bashly generate`
|
103
|
+
- [See the initial sample bashly.yml file](examples/subcommands/src/bashly.yml)
|
104
|
+
- [See the generated bash script](examples/subcommands/cli)
|
88
105
|
|
89
|
-
```yaml
|
90
|
-
name: cli
|
91
|
-
help: Sample application
|
92
|
-
version: 0.1.0
|
93
106
|
|
94
|
-
|
95
|
-
|
96
|
-
short: d
|
97
|
-
help: Download a file
|
98
|
-
|
99
|
-
args:
|
100
|
-
- name: source
|
101
|
-
required: true
|
102
|
-
help: URL to download from
|
103
|
-
- name: target
|
104
|
-
help: "Target filename (default: same as source)"
|
105
|
-
|
106
|
-
flags:
|
107
|
-
- long: --force
|
108
|
-
short: -f
|
109
|
-
help: Overwrite existing files
|
110
|
-
|
111
|
-
- name: upload
|
112
|
-
short: u
|
113
|
-
help: Upload a file
|
114
|
-
args:
|
115
|
-
- name: source
|
116
|
-
required: true
|
117
|
-
help: File to upload
|
118
|
-
|
119
|
-
flags:
|
120
|
-
- long: --user
|
121
|
-
short: -u
|
122
|
-
arg: user
|
123
|
-
help: Username to use for logging in
|
124
|
-
required: true
|
125
|
-
- long: --password
|
126
|
-
short: -p
|
127
|
-
arg: password
|
128
|
-
help: Password to use for logging in
|
129
|
-
```
|
107
|
+
See the [examples](examples) folder for more examples.
|
108
|
+
|
130
109
|
|
131
110
|
|
132
111
|
Configuration Reference
|
@@ -134,7 +113,7 @@ Configuration Reference
|
|
134
113
|
|
135
114
|
### Command options
|
136
115
|
|
137
|
-
With the exception of `version` and `commands` (
|
116
|
+
With the exception of `version` and `commands` (which define subcommands),
|
138
117
|
everything else in this section is suitable both for the main script, and for
|
139
118
|
any subcommand you define using `commands`.
|
140
119
|
|
@@ -150,6 +129,16 @@ help: a sample script generated with bashly
|
|
150
129
|
# The string to display when using --version
|
151
130
|
version: 0.1.0
|
152
131
|
|
132
|
+
# Specify an array of examples to show when using --help
|
133
|
+
examples:
|
134
|
+
- myscript download
|
135
|
+
- myscript download --force
|
136
|
+
|
137
|
+
# Specify an array of environment variables needed by your script
|
138
|
+
# This is used purely for displaying in the help text (when using --help)
|
139
|
+
environment_variable:
|
140
|
+
VARIABLE_NAME: Variable help text
|
141
|
+
|
153
142
|
# Specify the array of subcommands to generate.
|
154
143
|
# Each subcommand will have its own args and flags.
|
155
144
|
# If this is provided, then you cannot provide flags or args for the main
|
data/lib/bashly/cli.rb
CHANGED
@@ -0,0 +1,62 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Commands
|
3
|
+
class Add < Base
|
4
|
+
help "Add extra features and customization to your script"
|
5
|
+
|
6
|
+
usage "bashly add strings [--force]"
|
7
|
+
usage "bashly add lib [--force]"
|
8
|
+
usage "bashly add config [--force]"
|
9
|
+
usage "bashly add colors [--force]"
|
10
|
+
usage "bashly add (-h|--help)"
|
11
|
+
|
12
|
+
option "-f --force", "Overwrite existing files"
|
13
|
+
|
14
|
+
command "strings", "Copy an additional configuration file to your project, allowing you to customize all the tips and error strings."
|
15
|
+
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
|
+
command "config", "Add standard functions for handling INI files to the lib directory."
|
17
|
+
command "colors", "Add standard functions for printing colorful and formatted text to the lib directory."
|
18
|
+
|
19
|
+
environment "BASHLY_SOURCE_DIR", "The path to use for creating the configuration file [default: src]"
|
20
|
+
|
21
|
+
def strings_command
|
22
|
+
safe_copy asset("templates/strings.yml"), "#{Settings.source_dir}/bashly-strings.yml"
|
23
|
+
end
|
24
|
+
|
25
|
+
def lib_command
|
26
|
+
safe_copy_lib "sample_function.sh"
|
27
|
+
end
|
28
|
+
|
29
|
+
def config_command
|
30
|
+
safe_copy_lib "config.sh"
|
31
|
+
end
|
32
|
+
|
33
|
+
def colors_command
|
34
|
+
safe_copy_lib "colors.sh"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
def safe_copy_lib(libfile)
|
39
|
+
safe_copy asset("templates/lib/#{libfile}"), "#{Settings.source_dir}/lib/#{libfile}"
|
40
|
+
end
|
41
|
+
|
42
|
+
def safe_copy(source, target)
|
43
|
+
if !Dir.exist? Settings.source_dir
|
44
|
+
raise InitError, "Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist\nRun !txtpur!bashly init!txtrst! first"
|
45
|
+
end
|
46
|
+
|
47
|
+
if File.exist? target and !args['--force']
|
48
|
+
say "skipped !txtgrn!#{target}!txtrst! (exists)"
|
49
|
+
else
|
50
|
+
deep_copy source, target
|
51
|
+
say "created !txtgrn!#{target}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def deep_copy(source, target)
|
56
|
+
target_dir = File.dirname target
|
57
|
+
FileUtils.mkdir_p target_dir unless Dir.exist? target_dir
|
58
|
+
FileUtils.cp source, target
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/bashly/commands/init.rb
CHANGED
@@ -1,8 +1,6 @@
|
|
1
|
-
require 'mister_bin'
|
2
|
-
|
3
1
|
module Bashly
|
4
2
|
module Commands
|
5
|
-
class Init <
|
3
|
+
class Init < Base
|
6
4
|
summary "Initialize a new workspace"
|
7
5
|
help "This command will create the source folder, and place a template configuration file in it."
|
8
6
|
|
@@ -31,20 +29,12 @@ module Bashly
|
|
31
29
|
|
32
30
|
def yaml_content!
|
33
31
|
if args['--minimal']
|
34
|
-
File.read
|
32
|
+
File.read asset('templates/minimal.yml')
|
35
33
|
else
|
36
|
-
File.read
|
34
|
+
File.read asset('templates/bashly.yml')
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
def template_file
|
41
|
-
File.expand_path '../templates/bashly.yml', __dir__
|
42
|
-
end
|
43
|
-
|
44
|
-
def minimal_template_file
|
45
|
-
File.expand_path '../templates/minimal.yml', __dir__
|
46
|
-
end
|
47
|
-
|
48
38
|
def target_dir
|
49
39
|
@target_dir ||= Settings.source_dir
|
50
40
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Bashly
|
2
|
+
class MessageStrings
|
3
|
+
include AssetHelper
|
4
|
+
|
5
|
+
def [](key)
|
6
|
+
values[key.to_s]
|
7
|
+
end
|
8
|
+
|
9
|
+
def values
|
10
|
+
@values ||= values!
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def values!
|
16
|
+
defaults = YAML.load_file asset("templates/strings.yml")
|
17
|
+
defaults.merge project_strings
|
18
|
+
end
|
19
|
+
|
20
|
+
def project_strings
|
21
|
+
@project_strings ||= project_strings!
|
22
|
+
end
|
23
|
+
|
24
|
+
def project_strings!
|
25
|
+
if File.exist? project_strings_path
|
26
|
+
YAML.load_file project_strings_path
|
27
|
+
else
|
28
|
+
{}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def project_strings_path
|
33
|
+
@project_strings_path ||= "#{Settings.source_dir}/bashly-strings.yml"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/bashly/models/base.rb
CHANGED
@@ -87,15 +87,28 @@ module Bashly
|
|
87
87
|
result.join " "
|
88
88
|
end
|
89
89
|
|
90
|
+
# Returns an array of files to include as is inside the script
|
91
|
+
# This is meant to provide the user with the ability to add custom
|
92
|
+
# functions
|
93
|
+
def user_lib
|
94
|
+
@user_lib ||= Dir["#{Settings.source_dir}/lib/**/*.sh"]
|
95
|
+
end
|
96
|
+
|
97
|
+
# Raise an exception if there are some serious issues with the command
|
98
|
+
# definition.
|
90
99
|
def verify
|
91
|
-
if commands.any?
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
100
|
+
verify_commands if commands.any?
|
101
|
+
end
|
102
|
+
|
103
|
+
private
|
104
|
+
|
105
|
+
def verify_commands
|
106
|
+
if args.any? or flags.any?
|
107
|
+
raise ConfigurationError, "Error in the !txtgrn!#{full_name}!txtrst! command.\nThe !txtgrn!commands!txtrst! key cannot be at the same level as the !txtgrn!args!txtrst! or !txtgrn!flags!txtrst! keys."
|
108
|
+
end
|
109
|
+
|
110
|
+
if parent_name
|
111
|
+
raise ConfigurationError, "Error in the !txtgrn!#{full_name}!txtrst! command.\nNested commands are not supported."
|
99
112
|
end
|
100
113
|
end
|
101
114
|
|
@@ -2,6 +2,9 @@ name: cli
|
|
2
2
|
help: Sample application
|
3
3
|
version: 0.1.0
|
4
4
|
|
5
|
+
environment_variables:
|
6
|
+
API_KEY: Set your API key
|
7
|
+
|
5
8
|
commands:
|
6
9
|
- name: download
|
7
10
|
short: d
|
@@ -19,6 +22,13 @@ commands:
|
|
19
22
|
short: -f
|
20
23
|
help: Overwrite existing files
|
21
24
|
|
25
|
+
examples:
|
26
|
+
- cli download example.com
|
27
|
+
- cli download example.com ./output -f
|
28
|
+
|
29
|
+
environment_variables:
|
30
|
+
DEFAULT_TARGET_LOCATION: Set the default location to download to
|
31
|
+
|
22
32
|
- name: upload
|
23
33
|
short: u
|
24
34
|
help: Upload a file
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# ---
|
2
|
+
# Color functions
|
3
|
+
# This file is a part of Bashly standard library
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# Use any of the functions below to color or format a portion of a string.
|
7
|
+
#
|
8
|
+
# echo "before $(red this is red) after"
|
9
|
+
# echo "before $(green_bold this is green_bold) after"
|
10
|
+
#
|
11
|
+
# ---
|
12
|
+
|
13
|
+
red() { echo -e "\e[31m$*\e[0m" ; }
|
14
|
+
green() { echo -e "\e[32m$*\e[0m" ; }
|
15
|
+
yellow() { echo -e "\e[33m$*\e[0m" ; }
|
16
|
+
blue() { echo -e "\e[34m$*\e[0m" ; }
|
17
|
+
magenta() { echo -e "\e[35m$*\e[0m" ; }
|
18
|
+
cyan() { echo -e "\e[36m$*\e[0m" ; }
|
19
|
+
bold() { echo -e "\e[1m$*\e[0m" ; }
|
20
|
+
underlined() { echo -e "\e[4m$*\e[0m" ; }
|
21
|
+
red_bold() { echo -e "\e[1;31m$*\e[0m" ; }
|
22
|
+
green_bold() { echo -e "\e[1;32m$*\e[0m" ; }
|
23
|
+
yellow_bold() { echo -e "\e[1;33m$*\e[0m" ; }
|
24
|
+
blue_bold() { echo -e "\e[1;34m$*\e[0m" ; }
|
25
|
+
magenta_bold() { echo -e "\e[1;35m$*\e[0m" ; }
|
26
|
+
cyan_bold() { echo -e "\e[1;36m$*\e[0m" ; }
|
27
|
+
red_underlined() { echo -e "\e[4;31m$*\e[0m" ; }
|
28
|
+
green_underlined() { echo -e "\e[4;32m$*\e[0m" ; }
|
29
|
+
yellow_underlined() { echo -e "\e[4;33m$*\e[0m" ; }
|
30
|
+
blue_underlined() { echo -e "\e[4;34m$*\e[0m" ; }
|
31
|
+
magenta_underlined() { echo -e "\e[4;35m$*\e[0m" ; }
|
32
|
+
cyan_underlined() { echo -e "\e[4;36m$*\e[0m" ; }
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# ---
|
2
|
+
# Config functions
|
3
|
+
# This file is a part of Bashly standard library
|
4
|
+
#
|
5
|
+
# Usage:
|
6
|
+
# - In your script, set the CONFIG_FILE variable. For rxample:
|
7
|
+
# CONFIG_FILE=settings.ini.
|
8
|
+
# If it is unset, it will default to 'config.ini'.
|
9
|
+
# - Use any of the functions below to access the config file.
|
10
|
+
# ---
|
11
|
+
|
12
|
+
# Create a new config file.
|
13
|
+
# There is normally no need to use this fucntion, it is used by othe rfunctions
|
14
|
+
# as needed.
|
15
|
+
config_init() {
|
16
|
+
CONFIG_FILE=${CONFIG_FILE:=config.ini}
|
17
|
+
[[ -f "$CONFIG_FILE" ]] || touch "$CONFIG_FILE"
|
18
|
+
}
|
19
|
+
|
20
|
+
# Get a value from the config
|
21
|
+
# Usage: result=$(config_get hello)
|
22
|
+
config_get() {
|
23
|
+
key=$1
|
24
|
+
regex="^$key\s*=\s*(.+)$"
|
25
|
+
|
26
|
+
config_init
|
27
|
+
|
28
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
29
|
+
if [[ $line =~ $regex ]]; then
|
30
|
+
value="${BASH_REMATCH[1]}"
|
31
|
+
break
|
32
|
+
fi
|
33
|
+
done < "$CONFIG_FILE"
|
34
|
+
|
35
|
+
echo "$value"
|
36
|
+
}
|
37
|
+
|
38
|
+
# Add or update a key=value pair in the config.
|
39
|
+
# Usage: config_set key value
|
40
|
+
config_set() {
|
41
|
+
key=$1
|
42
|
+
shift
|
43
|
+
value="$*"
|
44
|
+
|
45
|
+
config_init
|
46
|
+
|
47
|
+
regex="^($key)\s*=\s*.+$"
|
48
|
+
output=""
|
49
|
+
found_key=""
|
50
|
+
|
51
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
52
|
+
newline=$line
|
53
|
+
if [[ $line =~ $regex ]]; then
|
54
|
+
found_key="${BASH_REMATCH[1]}"
|
55
|
+
newline="$key = $value"
|
56
|
+
output="$output$newline\n"
|
57
|
+
elif [[ $line ]]; then
|
58
|
+
output="$output$line\n"
|
59
|
+
fi
|
60
|
+
done < "$CONFIG_FILE"
|
61
|
+
|
62
|
+
if [[ -z $found_key ]]; then
|
63
|
+
output="$output$key = $value\n"
|
64
|
+
fi
|
65
|
+
|
66
|
+
echo -e "$output" > "$CONFIG_FILE"
|
67
|
+
}
|
68
|
+
|
69
|
+
# Delete a key from teh config.
|
70
|
+
# Usage: config_del key
|
71
|
+
config_del() {
|
72
|
+
key=$1
|
73
|
+
|
74
|
+
regex="^($key)\s*="
|
75
|
+
output=""
|
76
|
+
|
77
|
+
config_init
|
78
|
+
|
79
|
+
while IFS= read -r line || [ -n "$line" ]; do
|
80
|
+
newline=$line
|
81
|
+
if [[ $line ]] && [[ ! $line =~ $regex ]]; then
|
82
|
+
output="$output$line\n"
|
83
|
+
fi
|
84
|
+
done < "$CONFIG_FILE"
|
85
|
+
|
86
|
+
echo -e "$output" > "$CONFIG_FILE"
|
87
|
+
}
|
88
|
+
|
89
|
+
# Show the config file
|
90
|
+
config_show() {
|
91
|
+
config_init
|
92
|
+
cat "$CONFIG_FILE"
|
93
|
+
}
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# Add any function here that is needed in more than one parts of your
|
2
|
+
# application, or that you otherwise wish to extract from the main function
|
3
|
+
# scripts.
|
4
|
+
#
|
5
|
+
# Note that code here should be wrapped inside bash functions, and it is
|
6
|
+
# recommended to have a separate file for each function.
|
7
|
+
#
|
8
|
+
# Subdirectories will also be scanned for *.sh, so you have no reason not
|
9
|
+
# to organize your code nearly.
|
10
|
+
#
|
11
|
+
sample_function() {
|
12
|
+
echo "it works"
|
13
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# Usage captions
|
2
|
+
usage: "Usage:"
|
3
|
+
options: "Options:"
|
4
|
+
arguments: "Arguments:"
|
5
|
+
commands: "Commands:"
|
6
|
+
examples: "Examples:"
|
7
|
+
environment_variables: "Environment Variables:"
|
8
|
+
|
9
|
+
# Fixed flags help text
|
10
|
+
show_this_help: Show this help
|
11
|
+
show_version_number: Show version number
|
12
|
+
|
13
|
+
# Error messages
|
14
|
+
flag_requires_an_argument: "%{long} requires an argument: %{usage}"
|
15
|
+
invalid_argument: "invalid argument: %{arg}"
|
16
|
+
invalid_flag: "invalid option: %{flag}"
|
17
|
+
missing_required_argument: "missing required argument: %{arg}\\nusage: %{usage}"
|
18
|
+
missing_required_flag: "missing required flag: %{usage}"
|
19
|
+
|
data/lib/bashly/version.rb
CHANGED
@@ -8,10 +8,10 @@
|
|
8
8
|
<%- condition = "elif" -%>
|
9
9
|
<%- end -%>
|
10
10
|
else
|
11
|
-
echo "
|
11
|
+
echo -e "<%= strings[:invalid_argument] % { arg: "$key" } %>"
|
12
12
|
exit 1
|
13
13
|
fi
|
14
14
|
<%- else -%>
|
15
|
-
echo "
|
15
|
+
echo -e "<%= strings[:invalid_argument] % { arg: "$key" } %>"
|
16
16
|
exit 1
|
17
17
|
<%- end -%>
|
@@ -4,8 +4,7 @@ if [[ $1 && $1 != -* ]]; then
|
|
4
4
|
args[<%= arg.name %>]=$1
|
5
5
|
shift
|
6
6
|
else
|
7
|
-
echo "
|
8
|
-
echo "Usage: <%= usage_string %>"
|
7
|
+
echo -e "<%= strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } %>"
|
9
8
|
exit 1
|
10
9
|
fi
|
11
10
|
|
@@ -4,7 +4,7 @@ argstring="$*"
|
|
4
4
|
<%- end -%>
|
5
5
|
<%- required_flags.each do |flag| -%>
|
6
6
|
if [[ <%= flag.aliases.map { |a| %Q["$argstring" != *#{a}*] }.join " && " %> ]]; then
|
7
|
-
echo "
|
7
|
+
echo -e "<%= strings[:missing_required_flag] % { usage: flag.usage_string } %>"
|
8
8
|
exit 1
|
9
9
|
fi
|
10
10
|
<%- end %>
|
@@ -1,17 +1,19 @@
|
|
1
1
|
# :command.usage
|
2
2
|
<%= full_name.to_underscore %>_usage() {
|
3
|
-
echo "<%= caption_string %>"
|
3
|
+
echo -e "<%= caption_string %>"
|
4
4
|
echo
|
5
|
-
echo "
|
6
|
-
echo " <%= usage_string %>"
|
5
|
+
echo -e "<%= strings[:usage] %>"
|
6
|
+
echo -e " <%= usage_string %>"
|
7
7
|
echo
|
8
8
|
<%= render(:usage_commands).indent 2 if commands.any? %>
|
9
9
|
|
10
10
|
if [[ -n $long_usage ]]; then
|
11
|
-
echo "
|
11
|
+
echo -e "<%= strings[:options] %>"
|
12
12
|
<%= render(:usage_fixed_flags).indent 4 %>
|
13
13
|
<%= render(:usage_flags).indent 4 if flags.any? %>
|
14
14
|
<%= render(:usage_args).indent 4 if args.any? %>
|
15
|
+
<%= render(:usage_environment_variables).indent 4 if environment_variables %>
|
16
|
+
<%= render(:usage_examples).indent 4 if examples %>
|
15
17
|
|
16
18
|
fi
|
17
19
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# :command.usage_commands
|
2
|
-
echo "
|
2
|
+
echo -e "<%= strings[:commands] %>"
|
3
3
|
<%- maxlen = command_names.map(&:size).max -%>
|
4
4
|
<%- commands.each do |command| -%>
|
5
|
-
echo " <%= command.name.ljust maxlen %> <%= command.summary
|
5
|
+
echo " <%= command.name.ljust maxlen %> <%= command.summary %>"
|
6
6
|
<%- end -%>
|
7
7
|
echo
|
data/lib/bashly.rb
CHANGED
@@ -6,8 +6,10 @@ if ENV['BYEBUG']
|
|
6
6
|
end
|
7
7
|
|
8
8
|
requires 'bashly/polyfills'
|
9
|
+
requires 'bashly/concerns'
|
10
|
+
|
9
11
|
requires 'bashly/settings'
|
10
12
|
requires 'bashly/exceptions'
|
11
|
-
requires 'bashly/concerns'
|
12
13
|
requires 'bashly/models/base'
|
14
|
+
requires 'bashly/commands/base'
|
13
15
|
requires 'bashly'
|
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.
|
4
|
+
version: 0.2.0
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -63,14 +63,18 @@ files:
|
|
63
63
|
- bin/bashly
|
64
64
|
- lib/bashly.rb
|
65
65
|
- lib/bashly/cli.rb
|
66
|
+
- lib/bashly/commands/add.rb
|
67
|
+
- lib/bashly/commands/base.rb
|
66
68
|
- lib/bashly/commands/generate.rb
|
67
69
|
- lib/bashly/commands/init.rb
|
68
70
|
- lib/bashly/commands/preview.rb
|
71
|
+
- lib/bashly/concerns/asset_helper.rb
|
69
72
|
- lib/bashly/concerns/renderable.rb
|
70
73
|
- lib/bashly/config.rb
|
71
74
|
- lib/bashly/exceptions.rb
|
72
75
|
- lib/bashly/extensions/array.rb
|
73
76
|
- lib/bashly/extensions/string.rb
|
77
|
+
- lib/bashly/message_strings.rb
|
74
78
|
- lib/bashly/models/argument.rb
|
75
79
|
- lib/bashly/models/base.rb
|
76
80
|
- lib/bashly/models/command.rb
|
@@ -78,7 +82,11 @@ files:
|
|
78
82
|
- lib/bashly/polyfills/hash.rb
|
79
83
|
- lib/bashly/settings.rb
|
80
84
|
- lib/bashly/templates/bashly.yml
|
85
|
+
- lib/bashly/templates/lib/colors.sh
|
86
|
+
- lib/bashly/templates/lib/config.sh
|
87
|
+
- lib/bashly/templates/lib/sample_function.sh
|
81
88
|
- lib/bashly/templates/minimal.yml
|
89
|
+
- lib/bashly/templates/strings.yml
|
82
90
|
- lib/bashly/version.rb
|
83
91
|
- lib/bashly/views/argument/usage.erb
|
84
92
|
- lib/bashly/views/command/command_filter.erb
|
@@ -101,8 +109,11 @@ files:
|
|
101
109
|
- lib/bashly/views/command/usage.erb
|
102
110
|
- lib/bashly/views/command/usage_args.erb
|
103
111
|
- lib/bashly/views/command/usage_commands.erb
|
112
|
+
- lib/bashly/views/command/usage_environment_variables.erb
|
113
|
+
- lib/bashly/views/command/usage_examples.erb
|
104
114
|
- lib/bashly/views/command/usage_fixed_flags.erb
|
105
115
|
- lib/bashly/views/command/usage_flags.erb
|
116
|
+
- lib/bashly/views/command/user_lib.erb
|
106
117
|
- lib/bashly/views/command/version_command.erb
|
107
118
|
- lib/bashly/views/flag/case.erb
|
108
119
|
- lib/bashly/views/flag/usage.erb
|