bashly 0.6.9 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/commands/add.rb +36 -84
- data/lib/bashly/commands/generate.rb +47 -7
- data/lib/bashly/commands/init.rb +1 -1
- data/lib/bashly/commands/preview.rb +2 -2
- data/lib/bashly/concerns/asset_helper.rb +4 -0
- data/lib/bashly/extensions/file.rb +13 -0
- data/lib/bashly/extensions/string.rb +1 -1
- data/lib/bashly/library/base.rb +57 -0
- data/lib/bashly/library/colors.rb +9 -0
- data/lib/bashly/library/completions.rb +28 -0
- data/lib/bashly/library/completions_function.rb +26 -0
- data/lib/bashly/library/completions_script.rb +17 -0
- data/lib/bashly/library/completions_yaml.rb +15 -0
- data/lib/bashly/library/config.rb +9 -0
- data/lib/bashly/library/sample.rb +9 -0
- data/lib/bashly/library/strings.rb +12 -0
- data/lib/bashly/library/validations.rb +9 -0
- data/lib/bashly/library/yaml.rb +9 -0
- data/lib/bashly/{models → script}/argument.rb +1 -1
- data/lib/bashly/{models → script}/base.rb +1 -1
- data/lib/bashly/{models → script}/command.rb +1 -1
- data/lib/bashly/{models → script}/environment_variable.rb +1 -1
- data/lib/bashly/{models → script}/flag.rb +1 -1
- data/lib/bashly/{models/script.rb → script/wrapper.rb} +2 -2
- data/lib/bashly/templates/lib/colors.sh +12 -15
- data/lib/bashly/templates/lib/config.sh +34 -35
- data/lib/bashly/templates/lib/sample_function.sh +10 -10
- data/lib/bashly/templates/lib/validations/validate_dir_exists.sh +1 -0
- data/lib/bashly/templates/lib/validations/validate_file_exists.sh +1 -0
- data/lib/bashly/templates/lib/validations/validate_integer.sh +1 -0
- data/lib/bashly/templates/lib/validations/validate_not_empty.sh +1 -0
- data/lib/bashly/templates/lib/yaml.sh +12 -15
- data/lib/bashly/version.rb +1 -1
- data/lib/bashly/views/command/parse_requirements.erb +1 -1
- data/lib/bashly/views/command/required_args_filter.erb +1 -6
- data/lib/bashly/views/command/required_flags_filter.erb +1 -4
- data/lib/bashly/views/{script → wrapper}/bash3_bouncer.erb +0 -0
- data/lib/bashly/views/{script → wrapper}/header.erb +0 -0
- data/lib/bashly/views/{script → wrapper}/wrapper.erb +0 -0
- data/lib/bashly.rb +2 -1
- metadata +23 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 13bbac52a39c2f6afb768d043911861a31f8e6abc8ff1472340a13c2834d5944
|
4
|
+
data.tar.gz: 54c4fea2c664dcd0c6aace3360004d715d87b5d4ed98ffd7d3ccdc6c0a120406
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f1c273771d9048c074fb9551ba4521e9cb38c98a819f53647186822155898f767b7dd95093642e01464788378833d4dd9e408efecf304a9feb1ba09ebf2edef3
|
7
|
+
data.tar.gz: efbdad6c22cfe1b7fbb46533db42f4c14b828259efeb5ede1099e20980ad505773af36897e27f8c6c7b25538a523427e63c1a5dac7ff958d753ae3810caf5eb9
|
data/lib/bashly/commands/add.rb
CHANGED
@@ -9,7 +9,7 @@ module Bashly
|
|
9
9
|
usage "bashly add colors [--force]"
|
10
10
|
usage "bashly add yaml [--force]"
|
11
11
|
usage "bashly add validations [--force]"
|
12
|
-
usage "bashly add comp FORMAT [OUTPUT]"
|
12
|
+
usage "bashly add comp FORMAT [OUTPUT --force]"
|
13
13
|
usage "bashly add (-h|--help)"
|
14
14
|
|
15
15
|
option "-f --force", "Overwrite existing files"
|
@@ -32,129 +32,81 @@ module Bashly
|
|
32
32
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
33
33
|
|
34
34
|
def strings_command
|
35
|
-
|
35
|
+
add_lib Library::Strings.new
|
36
36
|
end
|
37
37
|
|
38
38
|
def lib_command
|
39
|
-
|
39
|
+
add_lib Library::Sample.new
|
40
40
|
end
|
41
41
|
|
42
42
|
def config_command
|
43
|
-
|
43
|
+
add_lib Library::Config.new
|
44
44
|
end
|
45
45
|
|
46
46
|
def colors_command
|
47
|
-
|
47
|
+
add_lib Library::Colors.new
|
48
48
|
end
|
49
49
|
|
50
50
|
def yaml_command
|
51
|
-
|
51
|
+
add_lib Library::YAML.new
|
52
52
|
end
|
53
53
|
|
54
54
|
def validations_command
|
55
|
-
|
55
|
+
add_lib Library::Validations.new
|
56
56
|
end
|
57
57
|
|
58
58
|
def comp_command
|
59
59
|
format = args['FORMAT']
|
60
60
|
output = args['OUTPUT']
|
61
|
-
|
61
|
+
|
62
62
|
case format
|
63
|
+
when "script"
|
64
|
+
path = output || "#{Settings.target_dir}/completions.bash"
|
65
|
+
add_lib Library::CompletionsScript.new(path)
|
66
|
+
|
63
67
|
when "function"
|
64
|
-
|
68
|
+
function = output || "send_completions"
|
69
|
+
path = "#{Settings.source_dir}/lib/#{function}.sh"
|
70
|
+
add_lib Library::CompletionsFunction.new(path, function: function)
|
71
|
+
|
65
72
|
when "yaml"
|
66
|
-
|
67
|
-
|
68
|
-
|
73
|
+
path = output || "#{Settings.target_dir}/completions.yml"
|
74
|
+
add_lib Library::CompletionsYAML.new(path)
|
75
|
+
|
69
76
|
else
|
70
77
|
raise Error, "Unrecognized format: #{format}"
|
78
|
+
|
71
79
|
end
|
72
80
|
|
73
81
|
end
|
74
82
|
|
75
83
|
private
|
76
84
|
|
77
|
-
def
|
78
|
-
|
79
|
-
|
85
|
+
def add_lib(handler)
|
86
|
+
files_created = 0
|
87
|
+
handler.files.each do |file|
|
88
|
+
created = safe_write file[:path], file[:content]
|
89
|
+
files_created += 1 if created
|
80
90
|
end
|
91
|
+
message = handler.post_install_message
|
92
|
+
say "\n#{message}" if message and files_created > 0
|
81
93
|
end
|
82
94
|
|
83
|
-
def
|
84
|
-
safe_copy asset("templates/lib/#{file}"), "#{Settings.source_dir}/lib/#{file}"
|
85
|
-
end
|
86
|
-
|
87
|
-
def safe_copy(source, target)
|
95
|
+
def safe_write(path, content)
|
88
96
|
if !Dir.exist? Settings.source_dir
|
89
97
|
raise InitError, "Directory !txtgrn!#{Settings.source_dir}!txtrst! does not exist\nRun !txtpur!bashly init!txtrst! first"
|
90
98
|
end
|
91
99
|
|
92
|
-
if File.exist?
|
93
|
-
say "skipped
|
100
|
+
if File.exist? path and !args['--force']
|
101
|
+
say "!txtblu!skipped!txtrst! #{path} (exists)"
|
102
|
+
false
|
103
|
+
|
94
104
|
else
|
95
|
-
|
96
|
-
say "created
|
97
|
-
|
98
|
-
end
|
99
|
-
|
100
|
-
def deep_copy(source, target)
|
101
|
-
target_dir = File.dirname target
|
102
|
-
FileUtils.mkdir_p target_dir unless Dir.exist? target_dir
|
103
|
-
FileUtils.cp source, target
|
104
|
-
end
|
105
|
-
|
106
|
-
def config
|
107
|
-
@config ||= Config.new "#{Settings.source_dir}/bashly.yml"
|
108
|
-
end
|
109
|
-
|
110
|
-
def command
|
111
|
-
@command ||= Models::Command.new config
|
112
|
-
end
|
113
|
-
|
114
|
-
def completions
|
115
|
-
@completions ||= command.completion_data
|
116
|
-
end
|
117
|
-
|
118
|
-
def completions_script
|
119
|
-
@completions_script ||= command.completion_script
|
120
|
-
end
|
121
|
-
|
122
|
-
def completions_function
|
123
|
-
@completions_function ||= command.completion_function
|
124
|
-
end
|
125
|
-
|
126
|
-
def save_comp_yaml(filename = nil)
|
127
|
-
filename ||= "#{Settings.target_dir}/completions.yml"
|
128
|
-
File.write filename, completions.to_yaml
|
129
|
-
say "created !txtgrn!#{filename}"
|
130
|
-
say ""
|
131
|
-
say "This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem."
|
132
|
-
end
|
133
|
-
|
134
|
-
def save_comp_script(filename = nil)
|
135
|
-
filename ||= "#{Settings.target_dir}/completions.bash"
|
136
|
-
File.write filename, completions_script
|
137
|
-
say "created !txtgrn!#{filename}"
|
138
|
-
say ""
|
139
|
-
say "In order to enable completions, run:"
|
140
|
-
say ""
|
141
|
-
say " !txtpur!$ source #{filename}"
|
142
|
-
end
|
143
|
-
|
144
|
-
def save_comp_function(name = nil)
|
145
|
-
name ||= "send_completions"
|
146
|
-
target_dir = "#{Settings.source_dir}/lib"
|
147
|
-
filename = "#{target_dir}/#{name}.sh"
|
105
|
+
File.deep_write path, content
|
106
|
+
say "!txtgrn!created!txtrst! #{path}"
|
107
|
+
true
|
148
108
|
|
149
|
-
|
150
|
-
File.write filename, completions_function
|
151
|
-
|
152
|
-
say "created !txtgrn!#{filename}"
|
153
|
-
say ""
|
154
|
-
say "In order to use it in your script, create a command or a flag (for example: !txtgrn!#{command.name} completions!txtrst! or !txtgrn!#{command.name} --completions!txtrst!) that calls the !txtgrn!#{name}!txtrst! function."
|
155
|
-
say "Your users can then run something like this to enable completions:"
|
156
|
-
say ""
|
157
|
-
say " !txtpur!$ eval \"$(#{command.name} completions)\""
|
109
|
+
end
|
158
110
|
end
|
159
111
|
|
160
112
|
end
|
@@ -3,12 +3,13 @@ module Bashly
|
|
3
3
|
class Generate < Base
|
4
4
|
help "Generate the bash script and required files"
|
5
5
|
|
6
|
-
usage "bashly generate [--force --quiet --wrap FUNCTION]"
|
6
|
+
usage "bashly generate [--force --quiet --upgrade --wrap FUNCTION]"
|
7
7
|
usage "bashly generate (-h|--help)"
|
8
8
|
|
9
9
|
option "-f --force", "Overwrite existing files"
|
10
|
-
option "-w --wrap FUNCTION", "Wrap the entire script in a function so it can also be sourced"
|
11
10
|
option "-q --quiet", "Disable on-screen progress report"
|
11
|
+
option "-u --upgrade", "Upgrade all added library functions"
|
12
|
+
option "-w --wrap FUNCTION", "Wrap the entire script in a function so it can also be sourced"
|
12
13
|
|
13
14
|
environment "BASHLY_SOURCE_DIR", "The path containing the bashly configuration and source files [default: src]"
|
14
15
|
environment "BASHLY_TARGET_DIR", "The path to use for creating the bash script [default: .]"
|
@@ -18,6 +19,7 @@ module Bashly
|
|
18
19
|
|
19
20
|
def run
|
20
21
|
create_user_files
|
22
|
+
upgrade_libs if args['--upgrade']
|
21
23
|
create_master_script
|
22
24
|
quiet_say "run !txtpur!#{master_script_path} --help!txtrst! to test your bash script"
|
23
25
|
end
|
@@ -28,6 +30,44 @@ module Bashly
|
|
28
30
|
say message unless args['--quiet']
|
29
31
|
end
|
30
32
|
|
33
|
+
def upgrade_libs
|
34
|
+
generated_files.each do |file|
|
35
|
+
content = File.read file
|
36
|
+
|
37
|
+
if content =~ /\[@bashly-upgrade (.+)\]/
|
38
|
+
lib = $1
|
39
|
+
|
40
|
+
case lib
|
41
|
+
when "colors"
|
42
|
+
upgrade file, Library::Colors.new
|
43
|
+
when "config"
|
44
|
+
upgrade file, Library::Config.new
|
45
|
+
when "yaml"
|
46
|
+
upgrade file, Library::YAML.new
|
47
|
+
when "validations"
|
48
|
+
upgrade file, Library::Validations.new
|
49
|
+
when /completions (.+)/
|
50
|
+
upgrade file, Library::CompletionsFunction.new(file, function: $1)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def generated_files
|
57
|
+
Dir["#{Settings.source_dir}/**/*.*"].sort
|
58
|
+
end
|
59
|
+
|
60
|
+
def upgrade(existing_file, handler)
|
61
|
+
file = handler.files.select { |f| f[:path] == existing_file }.first
|
62
|
+
|
63
|
+
if file
|
64
|
+
File.deep_write file[:path], file[:content]
|
65
|
+
quiet_say "!txtcyn!updated!txtrst! #{file[:path]}"
|
66
|
+
else
|
67
|
+
quiet_say "!txtred!warning!txtrst! not upgrading !txtcyn!#{existing_file}!txtrst!, path mismatch"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
31
71
|
def create_user_files
|
32
72
|
quiet_say "creating user files in !txtgrn!#{Settings.source_dir}"
|
33
73
|
|
@@ -55,21 +95,21 @@ module Bashly
|
|
55
95
|
|
56
96
|
def create_file(file, content)
|
57
97
|
if File.exist? file and !args['--force']
|
58
|
-
quiet_say "skipped
|
98
|
+
quiet_say "!txtblu!skipped!txtrst! #{file} (exists)"
|
59
99
|
else
|
60
100
|
File.write file, content
|
61
|
-
quiet_say "created
|
101
|
+
quiet_say "!txtgrn!created!txtrst! #{file}"
|
62
102
|
end
|
63
103
|
end
|
64
104
|
|
65
105
|
def create_master_script
|
66
106
|
File.write master_script_path, script.code
|
67
107
|
FileUtils.chmod "+x", master_script_path
|
68
|
-
quiet_say "created
|
108
|
+
quiet_say "!txtgrn!created!txtrst! #{master_script_path}"
|
69
109
|
end
|
70
110
|
|
71
111
|
def script
|
72
|
-
@script ||=
|
112
|
+
@script ||= Script::Wrapper.new(command, args['--wrap'])
|
73
113
|
end
|
74
114
|
|
75
115
|
def master_script_path
|
@@ -81,7 +121,7 @@ module Bashly
|
|
81
121
|
end
|
82
122
|
|
83
123
|
def command
|
84
|
-
@command ||=
|
124
|
+
@command ||= Script::Command.new config
|
85
125
|
end
|
86
126
|
|
87
127
|
end
|
data/lib/bashly/commands/init.rb
CHANGED
@@ -17,7 +17,7 @@ module Bashly
|
|
17
17
|
end
|
18
18
|
Dir.mkdir target_dir unless Dir.exist? target_dir
|
19
19
|
File.write "#{target_dir}/bashly.yml", yaml_content
|
20
|
-
say "created
|
20
|
+
say "!txtgrn!created!txtrst! #{target_dir}/bashly.yml"
|
21
21
|
say "run !txtpur!bashly generate!txtrst! to create the bash script"
|
22
22
|
end
|
23
23
|
|
@@ -10,8 +10,8 @@ module Bashly
|
|
10
10
|
|
11
11
|
def run
|
12
12
|
config = Config.new "#{Settings.source_dir}/bashly.yml"
|
13
|
-
command =
|
14
|
-
script =
|
13
|
+
command = Script::Command.new(config)
|
14
|
+
script = Script::Wrapper.new command
|
15
15
|
puts script.code
|
16
16
|
end
|
17
17
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
class File
|
4
|
+
def self.deep_write(file, content)
|
5
|
+
dir = File.dirname file
|
6
|
+
FileUtils.mkdir_p dir unless Dir.exist? dir
|
7
|
+
File.write file, content
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.append(path, content)
|
11
|
+
File.open(path, "a") { |f| f << content }
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Library
|
3
|
+
class Base
|
4
|
+
include AssetHelper
|
5
|
+
|
6
|
+
attr_reader :target_path, :options
|
7
|
+
|
8
|
+
def initialize(target_path = nil, options = nil)
|
9
|
+
@target_path = target_path || Settings.source_dir
|
10
|
+
@options = options || {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def files
|
14
|
+
case content
|
15
|
+
when String then content_from_string content
|
16
|
+
when Hash then [content]
|
17
|
+
else content
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def post_install_message
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def content
|
26
|
+
raise NotImplementedError, "Please implement either #content"
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def content_from_string(string)
|
32
|
+
if File.directory? asset("templates/lib/#{string}")
|
33
|
+
content_for_dir string
|
34
|
+
else
|
35
|
+
[content_for_file(string)]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def content_for_file(file)
|
40
|
+
{
|
41
|
+
path: "#{target_path}/lib/#{file}",
|
42
|
+
content: asset_content("templates/lib/#{file}")
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
def content_for_dir(dir)
|
47
|
+
Dir[asset("templates/lib/#{dir}/*.sh")].sort.map do |file|
|
48
|
+
{
|
49
|
+
path: "#{target_path}/lib/#{dir}/#{File.basename file}",
|
50
|
+
content: File.read(file)
|
51
|
+
}
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Library
|
3
|
+
class Completions < Base
|
4
|
+
def content
|
5
|
+
{ path: target_path, content: file_content }
|
6
|
+
end
|
7
|
+
|
8
|
+
def file_content
|
9
|
+
raise NotImplementedError, "Please implement #file_content"
|
10
|
+
end
|
11
|
+
|
12
|
+
protected
|
13
|
+
|
14
|
+
def completions
|
15
|
+
@completions ||= command.completion_data
|
16
|
+
end
|
17
|
+
|
18
|
+
def config
|
19
|
+
@config ||= Bashly::Config.new "#{Settings.source_dir}/bashly.yml"
|
20
|
+
end
|
21
|
+
|
22
|
+
def command
|
23
|
+
@command ||= Script::Command.new config
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Library
|
3
|
+
class CompletionsFunction < Completions
|
4
|
+
def file_content
|
5
|
+
[
|
6
|
+
"# [@bashly-upgrade completions #{function_name}]",
|
7
|
+
command.completion_function(function_name)
|
8
|
+
].join "\n"
|
9
|
+
end
|
10
|
+
|
11
|
+
def post_install_message
|
12
|
+
<<~EOF
|
13
|
+
In order to enable completions in your script, create a command or a flag (for example: !txtgrn!#{command.name} completions!txtrst! or !txtgrn!#{command.name} --completions!txtrst!) that calls the !txtgrn!#{function_name}!txtrst! function.
|
14
|
+
|
15
|
+
Your users can then run something like this to enable completions:
|
16
|
+
|
17
|
+
!txtpur!$ eval \"$(#{command.name} completions)\"
|
18
|
+
EOF
|
19
|
+
end
|
20
|
+
|
21
|
+
def function_name
|
22
|
+
options[:function]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Library
|
3
|
+
class CompletionsScript < Completions
|
4
|
+
def file_content
|
5
|
+
command.completion_script
|
6
|
+
end
|
7
|
+
|
8
|
+
def post_install_message
|
9
|
+
<<~EOF
|
10
|
+
In order to enable completions, run:
|
11
|
+
|
12
|
+
!txtpur!$ source #{target_path}
|
13
|
+
EOF
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Bashly
|
2
|
+
module Library
|
3
|
+
class CompletionsYAML < Completions
|
4
|
+
def file_content
|
5
|
+
completions.to_yaml
|
6
|
+
end
|
7
|
+
|
8
|
+
def post_install_message
|
9
|
+
<<~EOF
|
10
|
+
This file can be converted to a completions script using the !txtgrn!completely!txtrst! gem.
|
11
|
+
EOF
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -1,18 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
# ---
|
15
|
-
|
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
|
+
##
|
16
13
|
print_in_color() {
|
17
14
|
local color="$1"
|
18
15
|
shift
|
@@ -1,24 +1,23 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
# functions as needed.
|
1
|
+
## Config functions [@bashly-upgrade config]
|
2
|
+
## This file is a part of Bashly standard library
|
3
|
+
##
|
4
|
+
## Usage:
|
5
|
+
## - In your script, set the CONFIG_FILE variable. For rxample:
|
6
|
+
## CONFIG_FILE=settings.ini.
|
7
|
+
## If it is unset, it will default to 'config.ini'.
|
8
|
+
## - Use any of the functions below to access the config file.
|
9
|
+
##
|
10
|
+
## Create a new config file.
|
11
|
+
## There is normally no need to use this function, it is used by other
|
12
|
+
## functions as needed.
|
13
|
+
##
|
15
14
|
config_init() {
|
16
15
|
CONFIG_FILE=${CONFIG_FILE:=config.ini}
|
17
16
|
[[ -f "$CONFIG_FILE" ]] || touch "$CONFIG_FILE"
|
18
17
|
}
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
## Get a value from the config.
|
20
|
+
## Usage: result=$(config_get hello)
|
22
21
|
config_get() {
|
23
22
|
local key=$1
|
24
23
|
local regex="^$key *= *(.+)$"
|
@@ -36,8 +35,8 @@ config_get() {
|
|
36
35
|
echo "$value"
|
37
36
|
}
|
38
37
|
|
39
|
-
|
40
|
-
|
38
|
+
## Add or update a key=value pair in the config.
|
39
|
+
## Usage: config_set key value
|
41
40
|
config_set() {
|
42
41
|
local key=$1
|
43
42
|
shift
|
@@ -68,8 +67,8 @@ config_set() {
|
|
68
67
|
printf "%b\n" "$output" > "$CONFIG_FILE"
|
69
68
|
}
|
70
69
|
|
71
|
-
|
72
|
-
|
70
|
+
## Delete a key from the config.
|
71
|
+
## Usage: config_del key
|
73
72
|
config_del() {
|
74
73
|
local key=$1
|
75
74
|
|
@@ -87,19 +86,19 @@ config_del() {
|
|
87
86
|
printf "%b\n" "$output" > "$CONFIG_FILE"
|
88
87
|
}
|
89
88
|
|
90
|
-
|
89
|
+
## Show the config file
|
91
90
|
config_show() {
|
92
91
|
config_init
|
93
92
|
cat "$CONFIG_FILE"
|
94
93
|
}
|
95
94
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
95
|
+
## Return an array of the keys in the config file.
|
96
|
+
## Usage:
|
97
|
+
##
|
98
|
+
## for k in $(config_keys); do
|
99
|
+
## echo "- $k = $(config_get "$k")";
|
100
|
+
## done
|
101
|
+
##
|
103
102
|
config_keys() {
|
104
103
|
local regex="^([a-zA-Z0-9_\-\/\.]+) *="
|
105
104
|
|
@@ -117,13 +116,13 @@ config_keys() {
|
|
117
116
|
echo "${keys[@]}"
|
118
117
|
}
|
119
118
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
119
|
+
## Returns true if the specified key exists in the config file.
|
120
|
+
## Usage:
|
121
|
+
##
|
122
|
+
## if config_has_key "key" ; then
|
123
|
+
## echo "key exists"
|
124
|
+
## fi
|
125
|
+
##
|
127
126
|
config_has_key() {
|
128
127
|
[[ $(config_get "$1") ]]
|
129
128
|
}
|
@@ -1,13 +1,13 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
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 neatly.
|
10
|
+
##
|
11
11
|
sample_function() {
|
12
12
|
echo "it works"
|
13
13
|
}
|
@@ -1,18 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
#
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
#
|
14
|
-
# ---
|
15
|
-
|
1
|
+
## YAML parser [@bashly-upgrade yaml]
|
2
|
+
## This file is a part of Bashly standard library
|
3
|
+
## Does not support arrays, only hashes
|
4
|
+
##
|
5
|
+
## Source: https://stackoverflow.com/a/21189044/413924
|
6
|
+
##
|
7
|
+
## Usage:
|
8
|
+
##
|
9
|
+
## yaml_load "settings.yml" # print variables
|
10
|
+
## yaml_load "settings.yml" "config_" # use prefix
|
11
|
+
## eval $(yaml_load "settings.yml") # create variables in scope
|
12
|
+
##
|
16
13
|
yaml_load() {
|
17
14
|
local prefix=$2
|
18
15
|
local s='[[:space:]]*' w='[a-zA-Z0-9_]*'
|
data/lib/bashly/version.rb
CHANGED
@@ -8,9 +8,9 @@ parse_requirements() {
|
|
8
8
|
<%= render(:environment_variables_filter).indent 2 %>
|
9
9
|
<%= render(:dependencies_filter).indent 2 %>
|
10
10
|
<%= render(:command_filter).indent 2 %>
|
11
|
+
<%= render(:parse_requirements_while).indent 2 %>
|
11
12
|
<%= render(:required_args_filter).indent 2 %>
|
12
13
|
<%= render(:required_flags_filter).indent 2 %>
|
13
|
-
<%= render(:parse_requirements_while).indent 2 %>
|
14
14
|
<%= render(:catch_all_filter).indent 2 %>
|
15
15
|
<%= render(:default_assignments).indent 2 %>
|
16
16
|
<%= render(:whitelist_filter).indent 2 %>
|
@@ -1,12 +1,7 @@
|
|
1
1
|
# :command.required_args_filter
|
2
2
|
% required_args.each do |arg|
|
3
|
-
if [[ -
|
4
|
-
<%= arg.render(:validations).indent 2 %>
|
5
|
-
args[<%= arg.name %>]=$1
|
6
|
-
shift
|
7
|
-
else
|
3
|
+
if [[ -z ${args[<%= arg.name %>]+x} ]]; then
|
8
4
|
printf "<%= strings[:missing_required_argument] % { arg: arg.name.upcase, usage: usage_string } %>\n"
|
9
5
|
exit 1
|
10
6
|
fi
|
11
|
-
|
12
7
|
% end
|
@@ -1,9 +1,6 @@
|
|
1
1
|
# :command.required_flags_filter
|
2
|
-
% if required_flags.any?
|
3
|
-
argstring="$*"
|
4
|
-
% end
|
5
2
|
% required_flags.each do |flag|
|
6
|
-
if [[ <%= flag.
|
3
|
+
if [[ -z ${args[<%= flag.long %>]+x} ]]; then
|
7
4
|
printf "<%= strings[:missing_required_flag] % { usage: flag.usage_string } %>\n"
|
8
5
|
exit 1
|
9
6
|
fi
|
File without changes
|
File without changes
|
File without changes
|
data/lib/bashly.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.
|
4
|
+
version: 0.7.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: 2021-10-
|
11
|
+
date: 2021-10-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -88,14 +88,26 @@ files:
|
|
88
88
|
- lib/bashly/config.rb
|
89
89
|
- lib/bashly/exceptions.rb
|
90
90
|
- lib/bashly/extensions/array.rb
|
91
|
+
- lib/bashly/extensions/file.rb
|
91
92
|
- lib/bashly/extensions/string.rb
|
93
|
+
- lib/bashly/library/base.rb
|
94
|
+
- lib/bashly/library/colors.rb
|
95
|
+
- lib/bashly/library/completions.rb
|
96
|
+
- lib/bashly/library/completions_function.rb
|
97
|
+
- lib/bashly/library/completions_script.rb
|
98
|
+
- lib/bashly/library/completions_yaml.rb
|
99
|
+
- lib/bashly/library/config.rb
|
100
|
+
- lib/bashly/library/sample.rb
|
101
|
+
- lib/bashly/library/strings.rb
|
102
|
+
- lib/bashly/library/validations.rb
|
103
|
+
- lib/bashly/library/yaml.rb
|
92
104
|
- lib/bashly/message_strings.rb
|
93
|
-
- lib/bashly/
|
94
|
-
- lib/bashly/
|
95
|
-
- lib/bashly/
|
96
|
-
- lib/bashly/
|
97
|
-
- lib/bashly/
|
98
|
-
- lib/bashly/
|
105
|
+
- lib/bashly/script/argument.rb
|
106
|
+
- lib/bashly/script/base.rb
|
107
|
+
- lib/bashly/script/command.rb
|
108
|
+
- lib/bashly/script/environment_variable.rb
|
109
|
+
- lib/bashly/script/flag.rb
|
110
|
+
- lib/bashly/script/wrapper.rb
|
99
111
|
- lib/bashly/settings.rb
|
100
112
|
- lib/bashly/templates/bashly.yml
|
101
113
|
- lib/bashly/templates/lib/colors.sh
|
@@ -149,9 +161,9 @@ files:
|
|
149
161
|
- lib/bashly/views/flag/case.erb
|
150
162
|
- lib/bashly/views/flag/usage.erb
|
151
163
|
- lib/bashly/views/flag/validations.erb
|
152
|
-
- lib/bashly/views/
|
153
|
-
- lib/bashly/views/
|
154
|
-
- lib/bashly/views/
|
164
|
+
- lib/bashly/views/wrapper/bash3_bouncer.erb
|
165
|
+
- lib/bashly/views/wrapper/header.erb
|
166
|
+
- lib/bashly/views/wrapper/wrapper.erb
|
155
167
|
homepage: https://github.com/dannyben/bashly
|
156
168
|
licenses:
|
157
169
|
- MIT
|