bashly 2.0.0.rc1 → 2.0.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: 6e96439b1894f3097d9c8ea8d49b42254075a41bf02b233aa7d57674030e2d7f
4
- data.tar.gz: 14963288238d456e105ce739fdc076d0bb950f497a234851725ba3f887a4a982
3
+ metadata.gz: 65ab4d9e6acb0f638497f14958c9bebc78219cbb1c677d75b5f9f98506301e4c
4
+ data.tar.gz: fadcbfe0d4dcc48d6081d50f2a76bc57730ebd6e44b7c9a232350e7d072f2d3c
5
5
  SHA512:
6
- metadata.gz: 474e72b43adcba1b0860f123be0584dbf8d7d7d14797f44018603f6f805e6a792b92282201d7930383e40ff48d771094e339e0c279c12940558a17d07dc09f06
7
- data.tar.gz: 343351f0dbcb3d182ef2050e99a22f2ff39a1839ba11b208712c3cb85178f44678628f05ac1d2b2a4370e2dc77055f66972d16e94f5a4122dff409b937d9e956
6
+ metadata.gz: a775101849773351872c8f84ce312ec9d5ebc7a460bfed5858de9edf41d524c319e3dd48c424d3be30379ef79ee3e1d1e4bc4efd4b2b5164f641a3c3e47ee03e
7
+ data.tar.gz: 58ebb9d697a27856f7383d0ad69a5de4c06b21766347c769f241c1dcd947f2703bb932abf0733624e9a3fc7f475891076136d0038734cbe0b346a90b89d6192c
@@ -0,0 +1,37 @@
1
+ module Bashly
2
+ module SettingsCompletions
3
+ COMPLETION_SHELLS = %w[bash zsh].freeze
4
+
5
+ def completions
6
+ @completions ||= get :completions
7
+ end
8
+
9
+ def completions?
10
+ completions == 'minimal' || completion_shells.any?
11
+ end
12
+
13
+ def completion_shells
14
+ case completions
15
+ when nil, false, 'minimal' then []
16
+ when 'full' then COMPLETION_SHELLS
17
+ when String then validate_completion_shells completions
18
+ else invalid_completions
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def validate_completion_shells(value)
25
+ shells = value.split(',', -1).map(&:strip)
26
+ valid = shells.any? && (shells - COMPLETION_SHELLS).empty?
27
+ return shells if valid && shells.uniq == shells
28
+
29
+ invalid_completions
30
+ end
31
+
32
+ def invalid_completions
33
+ raise ConfigurationError,
34
+ "completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
35
+ end
36
+ end
37
+ end
@@ -2,6 +2,8 @@ module Bashly
2
2
  class ConfigValidator
3
3
  include ValidationHelpers
4
4
 
5
+ COMPLETION_OPTIONS = %w[files directories no-space].freeze
6
+
5
7
  attr_reader :data
6
8
 
7
9
  def initialize(data)
@@ -97,7 +99,7 @@ module Bashly
97
99
  assert_array "#{key}.options", value['options'], of: :string
98
100
 
99
101
  Array(value['options']).each do |option|
100
- assert %w[files directories no-space].include?(option),
102
+ assert COMPLETION_OPTIONS.include?(option),
101
103
  "#{key}.options contains an unknown option: #{option}"
102
104
  end
103
105
  end
@@ -177,11 +177,8 @@ completions: ~
177
177
  # DEVELOPER OPTIONS
178
178
  #-------------------------------------------------------------------------------
179
179
 
180
- # When true, use filesystem evented watching instead of polling
181
- watch_evented: false
182
-
183
- # File change detection latency (seconds)
184
- watch_latency: 1.0
180
+ # File change detection polling interval (seconds)
181
+ watch_latency: 2.0
185
182
 
186
183
 
187
184
  #-------------------------------------------------------------------------------
@@ -200,5 +197,6 @@ var_aliases:
200
197
 
201
198
  # Choose different names for some of the internal functions.
202
199
  function_names:
200
+ start: ~
203
201
  run: ~
204
202
  initialize: ~
@@ -35,6 +35,11 @@ module Bashly
35
35
  completions&.fetch('options', []) || []
36
36
  end
37
37
 
38
+ def completion?
39
+ allowed&.any? || completion_static.any? ||
40
+ completion_dynamic.any? || completion_options.any?
41
+ end
42
+
38
43
  def label
39
44
  repeatable ? "#{name.upcase}..." : name.upcase
40
45
  end
@@ -1,9 +1,10 @@
1
1
  module Bashly
2
2
  class Settings
3
- COMPLETION_SHELLS = %w[bash zsh].freeze
3
+ COMPLETION_SHELLS = SettingsCompletions::COMPLETION_SHELLS
4
4
 
5
5
  class << self
6
6
  include AssetHelper
7
+ include SettingsCompletions
7
8
 
8
9
  attr_writer(
9
10
  :argfile_var,
@@ -32,7 +33,6 @@ module Bashly
32
33
  :target_dir,
33
34
  :usage_colors,
34
35
  :var_aliases,
35
- :watch_evented,
36
36
  :watch_latency,
37
37
  :word_wrap
38
38
  )
@@ -53,28 +53,6 @@ module Bashly
53
53
  @compact_short_flags ||= get :compact_short_flags
54
54
  end
55
55
 
56
- def completions
57
- @completions ||= get :completions
58
- end
59
-
60
- def completions?
61
- completions == 'minimal' || completion_shells.any?
62
- end
63
-
64
- def completion_shells
65
- value = completions
66
- return [] if value.nil? || value == false || value == 'minimal'
67
- return COMPLETION_SHELLS if value == 'full'
68
-
69
- shells = value.split(',', -1).map(&:strip) if value.is_a? String
70
- valid = shells&.any? && shells.all? { |shell| COMPLETION_SHELLS.include? shell }
71
- unique = shells&.uniq == shells
72
- return shells if valid && unique
73
-
74
- raise ConfigurationError,
75
- "completions must be false, minimal, full, or a comma-separated list of: #{COMPLETION_SHELLS.join ', '}"
76
- end
77
-
78
56
  def conjoined_flag_args
79
57
  @conjoined_flag_args ||= get :conjoined_flag_args
80
58
  end
@@ -206,10 +184,6 @@ module Bashly
206
184
  @var_aliases ||= get :var_aliases
207
185
  end
208
186
 
209
- def watch_evented
210
- @watch_evented ||= get :watch_evented
211
- end
212
-
213
187
  def watch_latency
214
188
  @watch_latency ||= get :watch_latency
215
189
  end
@@ -1,3 +1,3 @@
1
1
  module Bashly
2
- VERSION = '2.0.0.rc1'
2
+ VERSION = '2.0.0.rc2'
3
3
  end
@@ -1,9 +1,10 @@
1
- if args.any?
1
+ completion_args = args.each_with_index.select { |arg, _index| arg.completion? }
2
+ if completion_args.any?
2
3
  > if [[ $completion_current != -* ]]; then
3
4
  > case "$completion_arg_index" in
4
- args.each_with_index do |arg, index|
5
+ completion_args.each do |arg, index|
5
6
  > {{ index }})
6
- = arg.render(:completion).indent 6
7
+ = arg.render(:completion).strip.indent 6
7
8
  > ;;
8
9
  end
9
10
  > esac
@@ -13,12 +13,14 @@
13
13
  = render :initialize
14
14
  = render :run
15
15
 
16
- >
16
+ >
17
+ = render :start
18
+ >
17
19
  if Settings.enabled? :sourcing
18
20
  > if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then
19
- = render(:start).indent 2
21
+ > {{ Settings.function_name :start }} "$@"
20
22
  > fi
21
23
  else
22
- = render :start
24
+ > {{ Settings.function_name :start }} "$@"
23
25
  end
24
- >
26
+ >
@@ -1,14 +1,14 @@
1
1
  = view_marker
2
2
 
3
- > command_line_args=("$@")
3
+ > {{ Settings.function_name :start }}() {
4
4
  if Settings.completions?
5
- > if [[ "${command_line_args[0]:-}" == "__complete" ]]; then
6
- > completion_run "${command_line_args[@]:1}"
7
- > else
5
+ > if [[ ${1:-} == "__complete" ]]; then
6
+ > completion_run "${@:2}"
7
+ > return
8
+ > fi
9
+ >
10
+ end
11
+ > command_line_args=("$@")
8
12
  > {{ Settings.function_name :initialize }}
9
13
  > {{ Settings.function_name :run }} "${command_line_args[@]}"
10
- > fi
11
- else
12
- > {{ Settings.function_name :initialize }}
13
- > {{ Settings.function_name :run }} "${command_line_args[@]}"
14
- end
14
+ > }
data/lib/bashly/watch.rb CHANGED
@@ -1,68 +1,40 @@
1
- require 'listen'
1
+ require 'watchly'
2
2
 
3
3
  module Bashly
4
- # File system watcher - an ergonomic wrapper around the Listen gem
4
+ # File system watcher - an ergonomic wrapper around the Watchly gem
5
5
  class Watch
6
- attr_reader :dirs, :options
6
+ attr_reader :interval, :targets
7
7
 
8
- def initialize(*dirs, **options)
9
- @options = default_options.merge(options).freeze
10
- @dirs = dirs.empty? ? ['.'] : dirs
8
+ def initialize(*targets, interval: nil)
9
+ @targets = targets.empty? ? ['.'] : targets
10
+ @interval = interval || default_interval
11
11
  end
12
12
 
13
- def on_change(&)
14
- start(&)
15
- wait
16
- ensure
17
- stop
18
- end
19
-
20
- private
13
+ def on_change
14
+ raise ArgumentError, 'block required' unless block_given?
21
15
 
22
- def default_options
23
- {
24
- force_polling: force_polling?,
25
- latency: latency,
26
- }
16
+ watcher.on_change do |changes|
17
+ yield normalize(changes)
18
+ end
19
+ rescue ::Interrupt => e
20
+ raise Bashly::Interrupt, cause: e
27
21
  end
28
22
 
29
- def force_polling?
30
- !Settings.watch_evented
31
- end
23
+ private
32
24
 
33
- def latency
25
+ def default_interval
34
26
  value = Settings.watch_latency.to_f
35
27
  value.positive? ? value : 0.1
36
28
  end
37
29
 
38
- def start(&block)
39
- raise ArgumentError, 'block required' unless block
40
-
41
- @listener = build_listener(&block)
42
- @listener.start
43
- end
44
-
45
- def stop
46
- @listener&.stop
47
- @listener = nil
48
- end
49
-
50
- def wait
51
- sleep
52
- rescue ::Interrupt => e
53
- raise Bashly::Interrupt, cause: e
54
- end
55
-
56
- def build_listener
57
- listen.to(*dirs, **options) do |modified, added, removed|
58
- yield changes(modified, added, removed)
59
- end
60
- end
61
-
62
- def changes(modified, added, removed)
63
- { modified:, added:, removed: }
30
+ def normalize(changes)
31
+ {
32
+ modified: changes.modified,
33
+ added: changes.added,
34
+ removed: changes.removed,
35
+ }
64
36
  end
65
37
 
66
- def listen = Listen
38
+ def watcher = @watcher ||= Watchly::Watcher.new(*targets, interval:)
67
39
  end
68
40
  end
data/lib/bashly.rb CHANGED
@@ -12,7 +12,7 @@ module Bashly
12
12
  ]
13
13
 
14
14
  autoloads 'bashly/concerns', %i[
15
- AssetHelper Renderable ValidationHelpers
15
+ AssetHelper Renderable SettingsCompletions ValidationHelpers
16
16
  ]
17
17
 
18
18
  module Script
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: 2.0.0.rc1
4
+ version: 2.0.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Danny Ben Shitrit
@@ -37,20 +37,6 @@ dependencies:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: 0.1.1
40
- - !ruby/object:Gem::Dependency
41
- name: listen
42
- requirement: !ruby/object:Gem::Requirement
43
- requirements:
44
- - - "~>"
45
- - !ruby/object:Gem::Version
46
- version: '3.9'
47
- type: :runtime
48
- prerelease: false
49
- version_requirements: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '3.9'
54
40
  - !ruby/object:Gem::Dependency
55
41
  name: lp
56
42
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +93,20 @@ dependencies:
107
93
  - - "~>"
108
94
  - !ruby/object:Gem::Version
109
95
  version: 0.7.2
96
+ - !ruby/object:Gem::Dependency
97
+ name: watchly
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: 0.2.0
103
+ type: :runtime
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: 0.2.0
110
110
  description: Generate bash command line tools using YAML configuration
111
111
  email: db@dannyben.com
112
112
  executables:
@@ -135,6 +135,7 @@ files:
135
135
  - lib/bashly/concerns/asset_helper.rb
136
136
  - lib/bashly/concerns/indentation_helper.rb
137
137
  - lib/bashly/concerns/renderable.rb
138
+ - lib/bashly/concerns/settings_completions.rb
138
139
  - lib/bashly/concerns/validation_helpers.rb
139
140
  - lib/bashly/config.rb
140
141
  - lib/bashly/config_validator.rb
@@ -299,7 +300,7 @@ files:
299
300
  - lib/bashly/views/wrapper/header.gtx
300
301
  - lib/bashly/views/wrapper/wrapper.gtx
301
302
  - lib/bashly/watch.rb
302
- homepage: https://github.com/bashly-framework/bashly
303
+ homepage: https://bashly.dev
303
304
  licenses:
304
305
  - MIT
305
306
  metadata:
@@ -324,5 +325,5 @@ required_rubygems_version: !ruby/object:Gem::Requirement
324
325
  requirements: []
325
326
  rubygems_version: 4.0.17
326
327
  specification_version: 4
327
- summary: Bash Command Line Tool Generator
328
+ summary: Bash command-line framework and CLI generator
328
329
  test_files: []