bashly 0.8.0 → 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bashly/concerns/command_scopes.rb +15 -0
- data/lib/bashly/concerns/completions.rb +60 -35
- data/lib/bashly/concerns/validation_helpers.rb +9 -3
- data/lib/bashly/config_validator.rb +8 -2
- data/lib/bashly/extensions/array.rb +2 -2
- data/lib/bashly/script/command.rb +7 -1
- data/lib/bashly/script/flag.rb +4 -2
- data/lib/bashly/version.rb +1 -1
- metadata +8 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4be359964fc41fae59f83eae85c594a4e0edec41e0cc5752fec25850b7b7ca43
|
4
|
+
data.tar.gz: 62023932e59ae5b9856a9617f9148a7e28bfab5bca5cebca98d3fefbf401ae21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0e222c6ead53cfef4597653d9ce51b6e9fffd1a3556acd72eff5447b9a203371a0097cd42f4058405cd473e7f0c55f4f9a448d45d3b1af73898b74a79706df4
|
7
|
+
data.tar.gz: 8362eff89fccaad8c9a1f370270e33426d0089bbe131eec4fc55f586413afaa556caa81e62389daefb400941122db96fa1f8b4e04d3780a4d45ea88060dfdc1e
|
@@ -1,6 +1,21 @@
|
|
1
1
|
module Bashly
|
2
2
|
# This is a `Command` concern responsible for providing additional scopes.
|
3
3
|
module CommandScopes
|
4
|
+
# Returns an array of all full names (including aliases and aliases of
|
5
|
+
# parents)
|
6
|
+
def all_full_names
|
7
|
+
if parent_command
|
8
|
+
parent_command.all_full_names.product(aliases).map { |a| a.join ' ' }
|
9
|
+
else
|
10
|
+
aliases
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Returns a full list of the Command names and aliases combined
|
15
|
+
def command_aliases
|
16
|
+
commands.map(&:aliases).flatten
|
17
|
+
end
|
18
|
+
|
4
19
|
# Returns only the names of the Commands
|
5
20
|
def command_names
|
6
21
|
commands.map &:name
|
@@ -1,51 +1,76 @@
|
|
1
1
|
require 'completely'
|
2
2
|
|
3
3
|
module Bashly
|
4
|
-
# This is a `Command` concern responsible for providing bash
|
4
|
+
# This is a `Command` and `Flag` concern responsible for providing bash
|
5
|
+
# completion data
|
5
6
|
module Completions
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
result.merge! command.completion_data(with_version: false)
|
11
|
-
end
|
7
|
+
module Flag
|
8
|
+
def completion_data(command_full_name)
|
9
|
+
result = {}
|
10
|
+
comps = allowed || completions
|
12
11
|
|
13
|
-
|
14
|
-
|
12
|
+
if comps
|
13
|
+
aliases.each do |name|
|
14
|
+
result["#{command_full_name}*#{name}"] = comps
|
15
|
+
end
|
16
|
+
end
|
15
17
|
|
16
|
-
|
17
|
-
|
18
|
+
result
|
19
|
+
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
module Command
|
23
|
+
def completion_data(with_version: true)
|
24
|
+
result = {}
|
23
25
|
|
24
|
-
|
26
|
+
all_full_names.each do |name|
|
27
|
+
result[name] = completion_words(with_version: with_version)
|
28
|
+
flags.each do |flag|
|
29
|
+
result.merge! flag.completion_data(name)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
commands.each do |command|
|
34
|
+
result.merge! command.completion_data(with_version: false)
|
35
|
+
end
|
25
36
|
|
26
|
-
|
27
|
-
|
28
|
-
end
|
37
|
+
result
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
40
|
+
def completion_script
|
41
|
+
completion_generator.script
|
42
|
+
end
|
33
43
|
|
34
|
-
|
35
|
-
|
36
|
-
|
44
|
+
def completion_function(name = nil)
|
45
|
+
completion_generator.wrapper_function(name)
|
46
|
+
end
|
37
47
|
|
38
|
-
|
39
|
-
trivial_flags = %w[--help -h]
|
40
|
-
trivial_flags += %w[--version -v] if with_version
|
41
|
-
all = (
|
42
|
-
command_names + trivial_flags +
|
43
|
-
completion_flag_names + completion_allowed_args
|
44
|
-
)
|
48
|
+
private
|
45
49
|
|
46
|
-
|
47
|
-
|
48
|
-
|
50
|
+
def completion_generator
|
51
|
+
Completely::Completions.new(completion_data)
|
52
|
+
end
|
53
|
+
|
54
|
+
def completion_flag_names
|
55
|
+
flags.map(&:name) + flags.map(&:short)
|
56
|
+
end
|
57
|
+
|
58
|
+
def completion_allowed_args
|
59
|
+
args.map(&:allowed).flatten
|
60
|
+
end
|
61
|
+
|
62
|
+
def completion_words(with_version: false)
|
63
|
+
trivial_flags = %w[--help -h]
|
64
|
+
trivial_flags += %w[--version -v] if with_version
|
65
|
+
all = (
|
66
|
+
command_aliases + trivial_flags +
|
67
|
+
completion_flag_names + completion_allowed_args
|
68
|
+
)
|
49
69
|
|
70
|
+
all += completions if completions
|
71
|
+
all.compact.uniq.sort
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
50
75
|
end
|
51
|
-
end
|
76
|
+
end
|
@@ -52,10 +52,16 @@ module Bashly
|
|
52
52
|
end
|
53
53
|
end
|
54
54
|
|
55
|
-
def assert_uniq(key, value,
|
55
|
+
def assert_uniq(key, value, array_keys)
|
56
56
|
return unless value
|
57
|
-
|
58
|
-
|
57
|
+
array_keys = [array_keys] unless array_keys.is_a? Array
|
58
|
+
list = []
|
59
|
+
array_keys.each do |array_key|
|
60
|
+
list += value.map { |c| c[array_key] }.compact.flatten
|
61
|
+
end
|
62
|
+
|
63
|
+
nonuniqs = list.nonuniq
|
64
|
+
assert nonuniqs.empty?, "#{key} contains non-unique elements (#{nonuniqs.join ', '}) in #{array_keys.join ' or '}"
|
59
65
|
end
|
60
66
|
|
61
67
|
def assert_string_or_array(key, value)
|
@@ -61,6 +61,8 @@ module Bashly
|
|
61
61
|
assert_hash key, value, Script::Flag.option_keys
|
62
62
|
assert value['short'] || value['long'], "#{key} must have at least one of long or short name"
|
63
63
|
|
64
|
+
refute value['allowed'] && value['completions'], "#{key} cannot have both allowed and completions"
|
65
|
+
|
64
66
|
assert_optional_string "#{key}.long", value['long']
|
65
67
|
assert_optional_string "#{key}.short", value['short']
|
66
68
|
assert_optional_string "#{key}.help", value['help']
|
@@ -72,6 +74,7 @@ module Bashly
|
|
72
74
|
assert_boolean "#{key}.required", value['required']
|
73
75
|
assert_array "#{key}.allowed", value['allowed'], of: :string
|
74
76
|
assert_array "#{key}.conflicts", value['conflicts'], of: :string
|
77
|
+
assert_array "#{key}.completions", value['completions'], of: :string
|
75
78
|
|
76
79
|
assert value['long'].match(/^--[a-zA-Z0-9_\-]+$/), "#{key}.long must be in the form of '--name'" if value['long']
|
77
80
|
assert value['short'].match(/^-[a-zA-Z0-9]$/), "#{key}.short must be in the form of '-n'" if value['short']
|
@@ -86,6 +89,10 @@ module Bashly
|
|
86
89
|
if value['allowed']
|
87
90
|
assert value['arg'], "#{key}.allowed does not make sense without arg"
|
88
91
|
end
|
92
|
+
|
93
|
+
if value['completions']
|
94
|
+
assert value['arg'], "#{key}.completions does not make sense without arg"
|
95
|
+
end
|
89
96
|
end
|
90
97
|
|
91
98
|
def assert_env_var(key, value)
|
@@ -124,8 +131,7 @@ module Bashly
|
|
124
131
|
assert_array "#{key}.environment_variables", value['environment_variables'], of: :env_var
|
125
132
|
assert_array "#{key}.examples", value['examples'], of: :string
|
126
133
|
|
127
|
-
assert_uniq "#{key}.commands", value['commands'], 'name'
|
128
|
-
assert_uniq "#{key}.commands", value['commands'], 'alias'
|
134
|
+
assert_uniq "#{key}.commands", value['commands'], ['name', 'alias']
|
129
135
|
assert_uniq "#{key}.flags", value['flags'], 'long'
|
130
136
|
assert_uniq "#{key}.flags", value['flags'], 'short'
|
131
137
|
assert_uniq "#{key}.args", value['args'], 'name'
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Script
|
3
3
|
class Command < Base
|
4
|
-
include Completions
|
4
|
+
include Completions::Command
|
5
5
|
include CommandScopes
|
6
6
|
|
7
7
|
class << self
|
@@ -62,6 +62,7 @@ module Bashly
|
|
62
62
|
return [] unless options["commands"]
|
63
63
|
options["commands"].map do |options|
|
64
64
|
options['parents'] = parents + [name]
|
65
|
+
options['parent_command'] = self
|
65
66
|
Command.new options
|
66
67
|
end
|
67
68
|
end
|
@@ -116,6 +117,11 @@ module Bashly
|
|
116
117
|
Settings.production? ? content : "#{view_marker path}\n#{content}"
|
117
118
|
end
|
118
119
|
|
120
|
+
# Returns the Command instance of the direct parent
|
121
|
+
def parent_command
|
122
|
+
options['parent_command']
|
123
|
+
end
|
124
|
+
|
119
125
|
# Returns an array of all parents. For example, the command
|
120
126
|
# "docker container run" will have [docker, container] as its parents
|
121
127
|
def parents
|
data/lib/bashly/script/flag.rb
CHANGED
@@ -1,11 +1,13 @@
|
|
1
1
|
module Bashly
|
2
2
|
module Script
|
3
3
|
class Flag < Base
|
4
|
+
include Completions::Flag
|
5
|
+
|
4
6
|
class << self
|
5
7
|
def option_keys
|
6
8
|
@option_keys ||= %i[
|
7
|
-
allowed arg conflicts default help long repeatable
|
8
|
-
short validate
|
9
|
+
allowed arg completions conflicts default help long repeatable
|
10
|
+
required short validate
|
9
11
|
]
|
10
12
|
end
|
11
13
|
end
|
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.8.
|
4
|
+
version: 0.8.1
|
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: 2022-05-
|
11
|
+
date: 2022-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colsole
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.7'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.7'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: completely
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.4.1
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.4.1
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: mister_bin
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '0.
|
61
|
+
version: '0.2'
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '0.
|
68
|
+
version: '0.2'
|
69
69
|
description: Generate bash command line tools using YAML configuration
|
70
70
|
email: db@dannyben.com
|
71
71
|
executables:
|