completely 0.5.0 → 0.5.1

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: 133a4cb7fec5b868e4c98e594bc6ffc228c25eee4b85a58801f03fc78d9b1cbf
4
+ data.tar.gz: 5073efb37aba0c9601875d05a9b9acce469d71d182f91c8729f18052bdcfc915
5
5
  SHA512:
6
- metadata.gz: 69f420158e1cc0cfae093d9fdd05295467d883c02d0648a1a3caab29787da3f9ad15d599328528910a7282a8518df80b64f1821e128365fdb6c3547a526b55a0
7
- data.tar.gz: 5e978c0f507474f8a8ae3e5c57111de33098b266ea661f659f1b4b4f7c4838b0e4da448bd55987662ae0e645b5ce542c675198624f638cfeb8999161b2625d42
6
+ metadata.gz: 63029b5f2cfd9362a7daa0e0d940e5f296d42962c2d0e9b2bda2297fe0c95b5abd3e6c9029f6c3781932b7fa2d2e122b0672ca6708774c375bcb277db48e5cf3
7
+ data.tar.gz: 9ec01adf53afe6d2aaa14ca6a369754adb76ef0043a51663183807eee3d0266c74c18bfd2518ff2d5bf1a5ba04216e0ac9fe0af3a3435b3ee2816115570cc568
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,21 @@ 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', "Path to the YAML configuration file [default: completely.yaml]\nCan also be set by an environment variable"
10
9
  end
11
10
 
12
11
  def option_function
13
- option "-f --function NAME", "Modify the name of the function in the generated script"
12
+ option '-f --function NAME', 'Modify the name of the function in the generated script'
14
13
  end
15
14
 
16
15
  def environment_config_path
17
- environment "COMPLETELY_CONFIG_PATH", "Path to a completely configuration file [default: completely.yaml]"
16
+ environment 'COMPLETELY_CONFIG_PATH', 'Path to a completely configuration file [default: completely.yaml]'
18
17
  end
19
18
 
20
19
  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"
20
+ 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'
22
21
  end
23
22
  end
24
23
 
@@ -46,7 +45,7 @@ module Completely
46
45
 
47
46
  def syntax_warning
48
47
  say! "\n!txtred!WARNING:\nYour configuration is invalid."
49
- say! "!txtred!All patterns must start with the same word."
48
+ say! '!txtred!All patterns must start with the same word.'
50
49
  end
51
50
  end
52
51
  end
@@ -3,19 +3,19 @@ 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 script. This is useful if you wish to embed it directly in your script'
13
13
 
14
14
  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"
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
16
 
17
17
  environment_config_path
18
- environment "COMPLETELY_OUTPUT_PATH", "Path to the output bash script"
18
+ environment 'COMPLETELY_OUTPUT_PATH', 'Path to the output bash script'
19
19
  environment_debug
20
20
 
21
21
  def run
@@ -31,7 +31,6 @@ module Completely
31
31
  def wrapper_function(wrapper_name)
32
32
  completions.wrapper_function wrapper_name
33
33
  end
34
-
35
34
  end
36
35
  end
37
36
  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,29 +3,32 @@ 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 the right completions. It works by reading your completely.yaml file, generating a completions script, and generating a temporary testing script.'
9
9
 
10
- usage "completely test [--keep] COMPLINE"
11
- usage "completely test (-h|--help)"
10
+ usage 'completely test [--keep] COMPLINE'
11
+ usage 'completely test (-h|--help)'
12
12
 
13
- option "-k --keep", "Keep the temporary testing script in the current directory"
13
+ option '-k --keep', 'Keep the temporary testing script in the current directory'
14
14
 
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."
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.'
16
16
 
17
17
  environment_config_path
18
18
  environment_debug
19
19
 
20
- example %q[completely test "mygit pu"]
21
- example %q[completely test "mygit pull "]
20
+ example 'completely test "mygit pu"'
21
+ example 'completely test "mygit pull "'
22
22
 
23
23
  def run
24
24
  puts tester.test(compline).join "\n"
25
+
25
26
  if args['--keep']
26
27
  File.write 'completely-tester.sh', tester_script
27
28
  puts 'saved completely-tester.sh'
28
29
  end
30
+
31
+ syntax_warning unless completions.valid?
29
32
  end
30
33
 
31
34
  private
@@ -45,7 +48,6 @@ module Completely
45
48
  def tester_script
46
49
  @tester_script ||= tester.tester_script compline
47
50
  end
48
-
49
51
  end
50
52
  end
51
53
  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.1'
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.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-09-04 00:00:00.000000000 Z
11
+ date: 2022-11-28 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