bashly 1.4.0.rc1 → 1.4.0.rc2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4417e2acaa7177450ab206c368039c46db5e2e3839b015c7dac235d23d3899a
4
- data.tar.gz: e62782cd28d229c36adcc4be6d09243b693f8c1536fadcfb98ceaddb203fbc49
3
+ metadata.gz: 77fc095074710d1003657f7ee7360e06e6864c9142d283d8bab88a9776fc737f
4
+ data.tar.gz: fae57e0c6bdf23a09d83bb280a4161b2e4b0de0e46518a44a1c36f902f9993cb
5
5
  SHA512:
6
- metadata.gz: f2827e99a65bbfc2cdaa77b2533400d6a85d7af72cbb35471654bb2ce840cef897f76e19c51504027559405a410cb46d150c2b2680d9b471526a94ee29dc4083
7
- data.tar.gz: 1cbe9b74014155e5cbd920fa29249a4102afea7738334b811583d5bdc1ef9064a1595d87d238bc350dd46b4dbe32926546a341956b1f417b521f5d459947ba1c
6
+ metadata.gz: a23dd4c92491a97aef54990418b930ae38ce826ede3bf1352c18f99ac8c53d5391e613eef113f5996c2757a60d5c9ebf96fe7e277e69a6a07456d02df35c2b28
7
+ data.tar.gz: 369a787f5851da5ac1b07afe6f7ddb985ebd64fc3ffe08aa5379376b3f8ddbc53e313dc31ba832096361a15ebf5aa973d6fd4dabfe64d7f8c6249799a9a7e1f9
@@ -27,7 +27,7 @@ module Bashly
27
27
  pattern_groups = inherited_global_groups.dup
28
28
  pattern_groups << local_group if local_group
29
29
 
30
- @patterns << pattern_for(command, pattern_groups)
30
+ @patterns << pattern_for(command, pattern_groups) unless visible_default_command(command)
31
31
 
32
32
  child_global_groups = inherited_global_groups.dup
33
33
  if command.global_flags?
@@ -36,6 +36,7 @@ module Bashly
36
36
  end
37
37
 
38
38
  command.visible_commands.each do |child|
39
+ add_default_command_pattern command, child, pattern_groups
39
40
  add_command child, inherited_global_groups: child_global_groups
40
41
  end
41
42
  end
@@ -47,6 +48,38 @@ module Bashly
47
48
  parts.join ' '
48
49
  end
49
50
 
51
+ def add_default_command_pattern(parent, command, parent_option_groups)
52
+ return unless command.default
53
+
54
+ default_group = add_default_options parent, command, parent_option_groups
55
+ option_groups = default_group ? [default_group] : []
56
+
57
+ @patterns << pattern_for_default_command(parent, command, option_groups)
58
+ end
59
+
60
+ def add_default_options(parent, command, parent_option_groups)
61
+ local_group = add_local_options command
62
+ group_names = parent_option_groups.dup
63
+ group_names << local_group if local_group
64
+
65
+ entries = group_names.flat_map { |name| @options[name] || [] }.uniq
66
+ return if entries.empty?
67
+
68
+ name = token_name "#{group_name(parent)}_#{group_name(command)}_default"
69
+ @options[name] = entries
70
+ name
71
+ end
72
+
73
+ def pattern_for_default_command(parent, command, option_groups)
74
+ parts = [command_path(parent)]
75
+ parts.concat(option_groups.map { |group| "[#{group} options]" })
76
+ parts.concat positional_tokens(
77
+ command,
78
+ first_source_extra: static_source(parent.visible_command_aliases)
79
+ )
80
+ parts.join ' '
81
+ end
82
+
50
83
  def command_path(command)
51
84
  command_chain(command).map.with_index do |item, index|
52
85
  index.zero? ? item.name : item.aliases.join('|')
@@ -102,14 +135,20 @@ module Bashly
102
135
  register_token flag.arg || flag.name, command, flag_source(flag)
103
136
  end
104
137
 
105
- def positional_tokens(command)
106
- command.args.map do |arg|
107
- token_name = register_token arg.name, command, arg_source(arg, command)
138
+ def positional_tokens(command, first_source_extra: nil)
139
+ command.args.map.with_index do |arg, index|
140
+ source = arg_source arg, command
141
+ source = merge_sources(first_source_extra, source) if index.zero? && first_source_extra
142
+ token_name = register_token arg.name, command, source
108
143
  suffix = arg.repeatable ? '...' : nil
109
144
  "<#{token_name}>#{suffix}"
110
145
  end
111
146
  end
112
147
 
148
+ def merge_sources(*sources)
149
+ sources.compact.flatten.uniq
150
+ end
151
+
113
152
  def flag_source(flag)
114
153
  return static_source(flag.allowed) if flag.allowed
115
154
  return completion_source(flag.completions) if flag.completions
@@ -178,6 +217,10 @@ module Bashly
178
217
  token_name command.root_command? ? 'root' : command.action_name
179
218
  end
180
219
 
220
+ def visible_default_command(command)
221
+ command.visible_commands.find(&:default)
222
+ end
223
+
181
224
  def token_name(value)
182
225
  value.to_s
183
226
  .gsub(/[^a-zA-Z0-9]+/, '_')
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '1.4.0.rc1'
2
+ VERSION = '1.4.0.rc2'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bashly
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.rc1
4
+ version: 1.4.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit