completely 0.5.0 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b9ace97a98b6c4feff7f5b755481317583de3330f2fc7be077d161ace8fa5e2
4
- data.tar.gz: fabc15cb7f3665327ece094530751506febc080c5158282bfee3ab874da8988a
3
+ metadata.gz: 7928212af575e203b41b2b6a1c94a0f6f564c28ae44795ade142b41ed83cbfe7
4
+ data.tar.gz: 541bd497455eedd5b0114edb7913ed1ccb1d2cfc90d78ca6d45298864f210583
5
5
  SHA512:
6
- metadata.gz: 69f420158e1cc0cfae093d9fdd05295467d883c02d0648a1a3caab29787da3f9ad15d599328528910a7282a8518df80b64f1821e128365fdb6c3547a526b55a0
7
- data.tar.gz: 5e978c0f507474f8a8ae3e5c57111de33098b266ea661f659f1b4b4f7c4838b0e4da448bd55987662ae0e645b5ce542c675198624f638cfeb8999161b2625d42
6
+ metadata.gz: cccadd0753d2ba83700f9bdebbd8e29eb3519206bb99992636fdde98cc313107b6475b8c12291dac3be8cbfc9ee235fa59c512dd55b62c2d8027ab871d8d424c
7
+ data.tar.gz: 36997d82e3438909788eb70484aabcaebe7a37534039ce748c1f3257aef05a674a8a9110280b3b324622eea1ff749263ea2a9968e31708be050676549536efcb
data/bin/completely CHANGED
@@ -8,9 +8,8 @@ runner = Completely::CLI.runner
8
8
 
9
9
  begin
10
10
  exit runner.run ARGV
11
-
12
11
  rescue => e
13
12
  puts e.backtrace.reverse if ENV['DEBUG']
14
13
  say! "!undred!#{e.class}!txtrst!\n#{e.message}"
15
14
  exit 1
16
- end
15
+ end
@@ -9,8 +9,8 @@ module Completely
9
9
  class CLI
10
10
  def self.runner
11
11
  runner = MisterBin::Runner.new version: Completely::VERSION,
12
- header: "Completely - Bash Completions Generator",
13
- footer: "Run !txtpur!completely COMMAND --help!txtrst! for more information"
12
+ header: 'Completely - Bash Completions Generator',
13
+ footer: 'Run !txtpur!completely COMMAND --help!txtrst! for more information'
14
14
 
15
15
  runner.route 'init', to: Commands::Init
16
16
  runner.route 'preview', to: Commands::Preview
@@ -3,22 +3,28 @@ require 'mister_bin'
3
3
  module Completely
4
4
  module Commands
5
5
  class Base < MisterBin::Command
6
-
7
6
  class << self
8
7
  def param_config_path
9
- param "CONFIG_PATH", "Path to the YAML configuration file [default: completely.yaml]\nCan also be set by an environment variable"
8
+ param 'CONFIG_PATH', <<~USAGE
9
+ Path to the YAML configuration file [default: completely.yaml].
10
+ Can also be set by an environment variable.
11
+ USAGE
10
12
  end
11
13
 
12
14
  def option_function
13
- option "-f --function NAME", "Modify the name of the function in the generated script"
15
+ option '-f --function NAME',
16
+ 'Modify the name of the function in the generated script.'
14
17
  end
15
18
 
16
19
  def environment_config_path
17
- environment "COMPLETELY_CONFIG_PATH", "Path to a completely configuration file [default: completely.yaml]"
20
+ environment 'COMPLETELY_CONFIG_PATH',
21
+ 'Path to a completely configuration file [default: completely.yaml].'
18
22
  end
19
23
 
20
24
  def environment_debug
21
- environment "COMPLETELY_DEBUG", "It not empty, the generated script will include an additional debugging snippet that outputs the compline and current word to a text file when a completion is requested"
25
+ environment 'COMPLETELY_DEBUG', 'If not empty, the generated script will include ' \
26
+ 'an additional debugging snippet that outputs the compline and current word to ' \
27
+ 'a text file when a completion is requested.'
22
28
  end
23
29
  end
24
30
 
@@ -46,7 +52,7 @@ module Completely
46
52
 
47
53
  def syntax_warning
48
54
  say! "\n!txtred!WARNING:\nYour configuration is invalid."
49
- say! "!txtred!All patterns must start with the same word."
55
+ say! '!txtred!All patterns must start with the same word.'
50
56
  end
51
57
  end
52
58
  end
@@ -3,19 +3,24 @@ require 'completely/commands/base'
3
3
  module Completely
4
4
  module Commands
5
5
  class Generate < Base
6
- help "Generate the bash completion script to a file"
6
+ help 'Generate the bash completion script to a file'
7
7
 
8
- usage "completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]"
9
- usage "completely generate (-h|--help)"
8
+ usage 'completely generate [CONFIG_PATH OUTPUT_PATH --function NAME --wrap NAME]'
9
+ usage 'completely generate (-h|--help)'
10
10
 
11
11
  option_function
12
- option "-w --wrap NAME", "Wrap the completion script inside a function that echos the script. This is useful if you wish to embed it directly in your script"
12
+ option '-w --wrap NAME', 'Wrap the completion script inside a function that echos the ' \
13
+ 'script. This is useful if you wish to embed it directly in your script.'
13
14
 
14
15
  param_config_path
15
- param "OUTPUT_PATH", "Path to the output bash script. When not provided, the name of the input file will be used with a .bash extension\nCan also be set by an environment variable"
16
+ param 'OUTPUT_PATH', <<~USAGE
17
+ Path to the output bash script.
18
+ When not provided, the name of the input file will be used with a .bash extension.
19
+ Can also be set by an environment variable.
20
+ USAGE
16
21
 
17
22
  environment_config_path
18
- environment "COMPLETELY_OUTPUT_PATH", "Path to the output bash script"
23
+ environment 'COMPLETELY_OUTPUT_PATH', 'Path to the output bash script.'
19
24
  environment_debug
20
25
 
21
26
  def run
@@ -31,7 +36,6 @@ module Completely
31
36
  def wrapper_function(wrapper_name)
32
37
  completions.wrapper_function wrapper_name
33
38
  end
34
-
35
39
  end
36
40
  end
37
41
  end
@@ -3,21 +3,19 @@ require 'completely/commands/base'
3
3
  module Completely
4
4
  module Commands
5
5
  class Init < Base
6
- help "Create a new sample YAML configuration file"
6
+ help 'Create a new sample YAML configuration file'
7
7
 
8
- usage "completely init [CONFIG_PATH]"
9
- usage "completely init (-h|--help)"
8
+ usage 'completely init [CONFIG_PATH]'
9
+ usage 'completely init (-h|--help)'
10
10
 
11
11
  param_config_path
12
12
  environment_config_path
13
13
 
14
14
  def run
15
- if File.exist? config_path
16
- raise "File already exists: #{config_path}"
17
- else
18
- File.write config_path, sample
19
- say "Saved !txtpur!#{config_path}"
20
- end
15
+ raise "File already exists: #{config_path}" if File.exist? config_path
16
+
17
+ File.write config_path, sample
18
+ say "Saved !txtpur!#{config_path}"
21
19
  end
22
20
 
23
21
  private
@@ -27,9 +25,8 @@ module Completely
27
25
  end
28
26
 
29
27
  def sample_path
30
- @sample_path ||= File.expand_path "../templates/sample.yaml", __dir__
28
+ @sample_path ||= File.expand_path '../templates/sample.yaml', __dir__
31
29
  end
32
-
33
30
  end
34
31
  end
35
32
  end
@@ -3,10 +3,10 @@ require 'completely/commands/base'
3
3
  module Completely
4
4
  module Commands
5
5
  class Preview < Base
6
- help "Generate the bash completion script to STDOUT"
6
+ help 'Generate the bash completion script to STDOUT'
7
7
 
8
- usage "completely preview [CONFIG_PATH --function NAME]"
9
- usage "completely preview (-h|--help)"
8
+ usage 'completely preview [CONFIG_PATH --function NAME]'
9
+ usage 'completely preview (-h|--help)'
10
10
 
11
11
  option_function
12
12
  param_config_path
@@ -3,35 +3,57 @@ require 'completely/commands/base'
3
3
  module Completely
4
4
  module Commands
5
5
  class Test < Base
6
- summary "Test completions"
6
+ summary 'Test completions'
7
7
 
8
- help "This command can be used to test that your completions script responds with the right completions. It works by reading your completely.yaml file, generating a completions script, and generating a temporary testing script."
8
+ help 'This command can be used to test that your completions script responds with ' \
9
+ 'the right completions. It works by reading your completely.yaml file, generating ' \
10
+ 'a completions script, and generating a temporary testing script.'
9
11
 
10
- usage "completely test [--keep] COMPLINE"
11
- usage "completely test (-h|--help)"
12
+ usage 'completely test [--keep] COMPLINE...'
13
+ usage 'completely test (-h|--help)'
12
14
 
13
- option "-k --keep", "Keep the temporary testing script in the current directory"
15
+ option '-k --keep', 'Keep the temporary testing script in the current directory.'
14
16
 
15
- param "COMPLINE", "The command to test completions for. This will be handled as if a TAB was pressed immediately at the end of it, so the last word is considered the active cursor. If you wish to complete for the next word instead, end your command with a space."
17
+ param 'COMPLINE', 'One or more commands to test completions for. ' \
18
+ 'This will be handled as if a TAB was pressed immediately at the end of it, ' \
19
+ 'so the last word is considered the active cursor. ' \
20
+ 'If you wish to complete for the next word instead, end your command with a space.'
16
21
 
17
22
  environment_config_path
18
23
  environment_debug
19
24
 
20
- example %q[completely test "mygit pu"]
21
- example %q[completely test "mygit pull "]
25
+ example 'completely test "mygit "'
26
+ example 'completely test --keep "mygit status "'
27
+ example 'completely test "mygit status --" "mygit init "'
22
28
 
23
29
  def run
24
- puts tester.test(compline).join "\n"
25
- if args['--keep']
26
- File.write 'completely-tester.sh', tester_script
27
- puts 'saved completely-tester.sh'
30
+ complines.each_with_index do |compline, i|
31
+ show_compline compline, filename: "completely-tester-#{i + 1}.sh"
28
32
  end
33
+
34
+ syntax_warning unless completions.valid?
29
35
  end
30
36
 
31
37
  private
32
38
 
33
- def compline
34
- args['COMPLINE']
39
+ def show_compline(compline, filename: nil)
40
+ filename ||= 'completely-tester.sh'
41
+ say "!txtblu!$ !txtgrn!#{compline}!txtrst!<tab>"
42
+ puts tester.test(compline).join "\n"
43
+ puts
44
+
45
+ return unless keep
46
+
47
+ File.write filename, tester_script(compline)
48
+ say "Saved !txtpur!#{filename}"
49
+ end
50
+
51
+ def complines
52
+ @complines ||= args['COMPLINE']
53
+ end
54
+
55
+ def keep
56
+ @keep ||= args['--keep']
35
57
  end
36
58
 
37
59
  def completions
@@ -42,10 +64,9 @@ module Completely
42
64
  @tester ||= completions.tester
43
65
  end
44
66
 
45
- def tester_script
46
- @tester_script ||= tester.tester_script compline
67
+ def tester_script(compline)
68
+ tester.tester_script compline
47
69
  end
48
-
49
70
  end
50
71
  end
51
72
  end
@@ -3,7 +3,7 @@ require 'erb'
3
3
 
4
4
  module Completely
5
5
  class Completions
6
- attr_reader :config, :function_name
6
+ attr_reader :config
7
7
 
8
8
  class << self
9
9
  def load(config_path, function_name: nil)
@@ -14,13 +14,14 @@ module Completely
14
14
  data = YAML.load_file config_path
15
15
  # :nocov:
16
16
  end
17
-
17
+
18
18
  new data, function_name: function_name
19
19
  end
20
20
  end
21
21
 
22
22
  def initialize(config, function_name: nil)
23
- @config, @function_name = config, function_name
23
+ @config = config
24
+ @function_name = function_name
24
25
  end
25
26
 
26
27
  def patterns
@@ -36,11 +37,11 @@ module Completely
36
37
  end
37
38
 
38
39
  def wrapper_function(name = nil)
39
- name ||= "send_completions"
40
+ name ||= 'send_completions'
40
41
 
41
42
  script_lines = script.split("\n").map do |line|
42
43
  clean_line = line.gsub("'") { "\\'" }
43
- %Q[ echo $'#{clean_line}']
44
+ " echo $'#{clean_line}'"
44
45
  end.join("\n")
45
46
 
46
47
  "#{name}() {\n#{script_lines}\n}"
@@ -53,13 +54,15 @@ module Completely
53
54
  private
54
55
 
55
56
  def patterns!
56
- config.map do |text, completions|
57
+ result = config.map do |text, completions|
57
58
  Pattern.new text, completions, pattern_function_name
58
- end.sort_by { |pattern| -pattern.length }
59
+ end
60
+
61
+ result.sort_by { |pattern| -pattern.length }
59
62
  end
60
63
 
61
64
  def template_path
62
- @template_path ||= File.expand_path("templates/template.erb", __dir__)
65
+ @template_path ||= File.expand_path('templates/template.erb', __dir__)
63
66
  end
64
67
 
65
68
  def template
@@ -67,7 +70,7 @@ module Completely
67
70
  end
68
71
 
69
72
  def command
70
- @command ||= config.keys.first.split(' ').first
73
+ @command ||= config.keys.first.split.first
71
74
  end
72
75
 
73
76
  def function_name
@@ -79,8 +82,7 @@ module Completely
79
82
  end
80
83
 
81
84
  def pattern_prefixes
82
- patterns.map &:prefix
85
+ patterns.map(&:prefix)
83
86
  end
84
-
85
87
  end
86
- end
88
+ end
@@ -17,7 +17,7 @@ module Completely
17
17
  end
18
18
 
19
19
  def words
20
- @words ||= completions.reject { |w| w =~ /^<.*>$/ }
20
+ @words ||= completions.grep_v(/^<.*>$/)
21
21
  end
22
22
 
23
23
  def actions
@@ -28,21 +28,21 @@ module Completely
28
28
  end
29
29
 
30
30
  def prefix
31
- text.split(' ')[0]
31
+ text.split(/ |\*/).first
32
32
  end
33
33
 
34
34
  def case_string
35
35
  if text_without_prefix.empty?
36
- "*"
37
- elsif text_without_prefix.include? "*"
38
- %Q['#{text_without_prefix.gsub "*", "'*'"}']
36
+ '*'
37
+ elsif text_without_prefix.include? '*'
38
+ text_without_prefix.gsub(/([^*]+)/, "'\\1'")
39
39
  else
40
- %Q['#{text_without_prefix}'*]
40
+ "'#{text_without_prefix}'*"
41
41
  end
42
42
  end
43
43
 
44
44
  def text_without_prefix
45
- @text_without_prefix ||= text.split(' ')[1..-1].join ' '
45
+ @text_without_prefix ||= text[/^#{prefix}\s*(.*)/, 1]
46
46
  end
47
47
 
48
48
  def compgen
@@ -53,9 +53,9 @@ module Completely
53
53
 
54
54
  def compgen!
55
55
  result = []
56
- result << %Q[#{actions.join ' '}] if actions.any?
57
- result << %Q[-W "$(#{function_name} "#{words.join ' '}")"] if words.any?
56
+ result << actions.join(' ').to_s if actions.any?
57
+ result << %[-W "$(#{function_name} "#{words.join ' '}")"] if words.any?
58
58
  result.any? ? result.join(' ') : nil
59
59
  end
60
60
  end
61
- end
61
+ end
@@ -5,12 +5,14 @@ module Completely
5
5
  class Tester
6
6
  attr_reader :script, :script_path, :function_name, :cword, :compline
7
7
 
8
- def initialize(script: nil, script_path: nil, function_name: )
9
- @script, @script_path, @function_name = script, script_path, function_name
8
+ def initialize(function_name:, script: nil, script_path: nil)
9
+ @script = script
10
+ @script_path = script_path
11
+ @function_name = function_name
10
12
  end
11
13
 
12
14
  def test(compline)
13
- Tempfile.create "completely-tester" do |f|
15
+ Tempfile.create 'completely-tester' do |f|
14
16
  f << tester_script(compline)
15
17
  f.flush
16
18
  `bash #{f.path}`
@@ -26,23 +28,20 @@ module Completely
26
28
 
27
29
  def set_compline_vars(compline)
28
30
  @compline = compline
29
- @cword = compline.split(' ').size - 1
31
+ @cword = compline.split.size - 1
30
32
  @cword += 1 if compline.end_with? ' '
31
33
  end
32
34
 
33
35
  def absolute_script_path
34
- @absolute_script_path ||= begin
35
- script_path ? File.expand_path(script_path) : nil
36
- end
36
+ @absolute_script_path ||= script_path ? File.expand_path(script_path) : nil
37
37
  end
38
38
 
39
39
  def template_path
40
- @template_path ||= File.expand_path "templates/tester-template.erb", __dir__
40
+ @template_path ||= File.expand_path 'templates/tester-template.erb', __dir__
41
41
  end
42
42
 
43
43
  def template
44
44
  @template ||= File.read template_path
45
45
  end
46
-
47
46
  end
48
- end
47
+ end
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = "0.5.0"
3
- end
2
+ VERSION = '0.5.2'
3
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: completely
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
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-09-04 00:00:00.000000000 Z
11
+ date: 2022-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0.7'
33
+ version: 0.7.2
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: '0.7'
40
+ version: 0.7.2
41
41
  description: Generate bash completion scripts using simple YAML configuration
42
42
  email: db@dannyben.com
43
43
  executables:
@@ -64,7 +64,8 @@ files:
64
64
  homepage: https://github.com/dannyben/completely
65
65
  licenses:
66
66
  - MIT
67
- metadata: {}
67
+ metadata:
68
+ rubygems_mfa_required: 'true'
68
69
  post_install_message:
69
70
  rdoc_options: []
70
71
  require_paths:
@@ -80,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
80
81
  - !ruby/object:Gem::Version
81
82
  version: '0'
82
83
  requirements: []
83
- rubygems_version: 3.3.14
84
+ rubygems_version: 3.3.26
84
85
  signing_key:
85
86
  specification_version: 4
86
87
  summary: Bash Completions Generator