completely 0.5.4 → 0.6.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: e4fbe4bb19567637239bac887b5e785caeac6c0dbf38f82e7d775a994db58a29
4
- data.tar.gz: d7449fd83d8e1b6e5ce723deb457e6e8eab4254a92818f739fd6002b939385c8
3
+ metadata.gz: 96373b5a76365d9d8dd59e017dec1c32159520ac92f4d2abaed7dd807843a847
4
+ data.tar.gz: fea9ce43a598c7f52ddb59971f895ebdb8eb9bb4f9a1d6918e5c15c52eb583e9
5
5
  SHA512:
6
- metadata.gz: e5e3c3985ac71d2db26ce7f321e1717af80ef760def41820b86e505ee884a3921d43618093c94ee41b3f9ed2291d35f9eac49fd6c4c6d4a376e1e981198d3ce9
7
- data.tar.gz: 19719cecb29e21e1a226fd45d815a02baf9579c75e0f88ed0876a4ece8c3dee587feb88e71657d9d362cf9a2de5d0222b1423ecff4af759d32906daee0ba42a7
6
+ metadata.gz: c2b06ef048b16ddc565534b7934c421bc9dde18bf7706071972f64d406563be6044308cd4a38497f96f78208ba5916bc29d5aa4c1228f30fdfb0e6cad638f61b
7
+ data.tar.gz: ae92c96a9d51cf4574868257432f348494e16c8bbcfa10a3a6703ae6ca3de110a008c443bc1da25807a815792e7e9d7e3cc6df5530a32ee21c5653524662b93d
data/README.md CHANGED
@@ -109,7 +109,7 @@ $ completely generate
109
109
  $ completely preview
110
110
  ```
111
111
 
112
- For more options (like setting input/output path), run
112
+ For more options (like setting input/output path), run:
113
113
 
114
114
  ```bash
115
115
  $ completely --help
@@ -215,9 +215,15 @@ In order to enable the completions, simply source the generated script:
215
215
  $ source completely.bash
216
216
  ```
217
217
 
218
- In order to load these completions on startup, you may want to place them in
219
- the completions directory of your operating system, which can be either of
220
- these (whichever exists):
218
+ If you are satisfied with the result, and wish to copy the script to your bash
219
+ completions directory, simply run:
220
+
221
+ ```bash
222
+ $ completely install
223
+ ```
224
+
225
+ Alternatively, you can copy the script manually to one of these directories
226
+ (whichever exists):
221
227
 
222
228
  - `/usr/share/bash-completion/completions`
223
229
  - `/usr/local/etc/bash_completion.d`
@@ -1,10 +1,11 @@
1
1
  require 'mister_bin'
2
- require 'completely/version'
3
2
  require 'completely/commands/generate'
4
3
  require 'completely/commands/init'
5
4
  require 'completely/commands/install'
6
5
  require 'completely/commands/preview'
7
6
  require 'completely/commands/test'
7
+ require 'completely/commands/uninstall'
8
+ require 'completely/version'
8
9
 
9
10
  module Completely
10
11
  class CLI
@@ -18,6 +19,7 @@ module Completely
18
19
  runner.route 'generate', to: Commands::Generate
19
20
  runner.route 'test', to: Commands::Test
20
21
  runner.route 'install', to: Commands::Install
22
+ runner.route 'uninstall', to: Commands::Uninstall
21
23
 
22
24
  runner
23
25
  end
@@ -12,7 +12,7 @@ module Completely
12
12
  environment_config_path
13
13
 
14
14
  def run
15
- raise "File already exists: #{config_path}" if File.exist? config_path
15
+ raise Error, "File already exists: #{config_path}" if File.exist? config_path
16
16
 
17
17
  File.write config_path, sample
18
18
  say "Saved m`#{config_path}`"
@@ -3,19 +3,10 @@ require 'completely/commands/base'
3
3
  module Completely
4
4
  module Commands
5
5
  class Install < Base
6
- TARGETS = %W[
7
- /usr/share/bash-completion/completions
8
- /usr/local/etc/bash_completion.d
9
- #{Dir.home}/.bash_completion.d
10
- ]
11
-
12
6
  summary 'Install a bash completion script'
13
7
 
14
8
  help <<~HELP
15
- This command will copy the specified file to one of the following directories:
16
-
17
- #{TARGETS.map { |c| " - #{c}" }.join "\n"}
18
-
9
+ This command will copy the specified file to one of the bash completion directories.
19
10
  The target filename will be the program name, and sudo will be used if necessary.
20
11
  HELP
21
12
 
@@ -29,68 +20,27 @@ module Completely
29
20
  param 'SCRIPT_PATH', 'Path to the source bash script [default: completely.bash].'
30
21
 
31
22
  def run
32
- bounce
33
-
34
23
  if args['--dry']
35
- puts command.join ' '
24
+ puts installer.install_command_string
36
25
  return
37
26
  end
38
27
 
39
- success = system(*command)
40
- raise "Failed running command:\nnb`#{command.join ' '}`" unless success
28
+ success = installer.install force: args['--force']
29
+ raise InstallError, "Failed running command:\nnb`#{installer.install_command_string}`" unless success
41
30
 
42
- say "Saved m`#{target_path}`"
31
+ say "Saved m`#{installer.target_path}`"
43
32
  say 'You may need to restart your session to test it'
44
33
  end
45
34
 
46
35
  private
47
36
 
48
- def bounce
49
- unless completions_path
50
- raise 'Cannot determine system completions directory'
51
- end
52
-
53
- unless File.exist? script_path
54
- raise "Cannot find script: m`#{script_path}`"
55
- end
56
-
57
- if target_exist? && !args['--force']
58
- raise "File exists: m`#{target_path}`\nUse nb`--force` to overwrite"
59
- end
60
- end
61
-
62
- def target_exist?
63
- File.exist? target_path
64
- end
65
-
66
- def command
67
- result = root? ? [] : %w[sudo]
68
- result + %W[cp #{script_path} #{target_path}]
37
+ def installer
38
+ Installer.new program: args['PROGRAM'], script_path: script_path
69
39
  end
70
40
 
71
41
  def script_path
72
42
  args['SCRIPT_PATH'] || 'completely.bash'
73
43
  end
74
-
75
- def target_path
76
- "#{completions_path}/#{args['PROGRAM']}"
77
- end
78
-
79
- def root?
80
- Process.uid.zero?
81
- end
82
-
83
- def completions_path
84
- @completions_path ||= completions_path!
85
- end
86
-
87
- def completions_path!
88
- TARGETS.each do |tarnet|
89
- return tarnet if Dir.exist? tarnet
90
- end
91
-
92
- nil
93
- end
94
44
  end
95
45
  end
96
46
  end
@@ -0,0 +1,39 @@
1
+ require 'completely/commands/base'
2
+
3
+ module Completely
4
+ module Commands
5
+ class Uninstall < Base
6
+ summary 'Uninstall a bash completion script'
7
+
8
+ help <<~HELP
9
+ This command will remove the completion script for the specified program from all the bash completion directories.
10
+ HELP
11
+
12
+ usage 'completely uninstall PROGRAM [--dry]'
13
+ usage 'completely uninstall (-h|--help)'
14
+
15
+ option '-d --dry', 'Show the uninstallation command but do not run it'
16
+
17
+ param 'PROGRAM', 'Name of the program the completions are for.'
18
+
19
+ def run
20
+ if args['--dry']
21
+ puts installer.uninstall_command_string
22
+ return
23
+ end
24
+
25
+ success = installer.uninstall
26
+ raise InstallError, "Failed running command:\nnb`#{installer.uninstall_command_string}`" unless success
27
+
28
+ say 'Done'
29
+ say 'You may need to restart your session to test it'
30
+ end
31
+
32
+ private
33
+
34
+ def installer
35
+ Installer.new program: args['PROGRAM']
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,4 @@
1
+ module Completely
2
+ class Error < StandardError; end
3
+ class InstallError < Error; end
4
+ end
@@ -0,0 +1,86 @@
1
+ module Completely
2
+ class Installer
3
+ attr_reader :program, :script_path
4
+
5
+ def initialize(program:, script_path: nil)
6
+ @program = program
7
+ @script_path = script_path
8
+ end
9
+
10
+ def target_directories
11
+ @target_directories ||= %W[
12
+ /usr/share/bash-completion/completions
13
+ /usr/local/etc/bash_completion.d
14
+ #{Dir.home}/.bash_completion.d
15
+ ]
16
+ end
17
+
18
+ def install_command
19
+ result = root_user? ? [] : %w[sudo]
20
+ result + %W[cp #{script_path} #{target_path}]
21
+ end
22
+
23
+ def install_command_string
24
+ install_command.join ' '
25
+ end
26
+
27
+ def uninstall_command
28
+ result = root_user? ? [] : %w[sudo]
29
+ result + %w[rm -f] + target_directories.map { |dir| "#{dir}/#{program}" }
30
+ end
31
+
32
+ def uninstall_command_string
33
+ uninstall_command.join ' '
34
+ end
35
+
36
+ def target_path
37
+ "#{completions_path}/#{program}"
38
+ end
39
+
40
+ def install(force: false)
41
+ unless completions_path
42
+ raise InstallError, 'Cannot determine system completions directory'
43
+ end
44
+
45
+ unless script_exist?
46
+ raise InstallError, "Cannot find script: m`#{script_path}`"
47
+ end
48
+
49
+ if target_exist? && !force
50
+ raise InstallError, "File exists: m`#{target_path}`"
51
+ end
52
+
53
+ system(*install_command)
54
+ end
55
+
56
+ def uninstall
57
+ system(*uninstall_command)
58
+ end
59
+
60
+ private
61
+
62
+ def target_exist?
63
+ File.exist? target_path
64
+ end
65
+
66
+ def script_exist?
67
+ File.exist? script_path
68
+ end
69
+
70
+ def root_user?
71
+ Process.uid.zero?
72
+ end
73
+
74
+ def completions_path
75
+ @completions_path ||= completions_path!
76
+ end
77
+
78
+ def completions_path!
79
+ target_directories.each do |target|
80
+ return target if Dir.exist? target
81
+ end
82
+
83
+ nil
84
+ end
85
+ end
86
+ end
@@ -33,7 +33,7 @@
33
33
  echo "cur: '$cur'" >> 'completely-debug.txt'
34
34
  fi
35
35
 
36
- %end
36
+ % end
37
37
  case "$compline" in
38
38
  % patterns.each do |pattern|
39
39
  % next if pattern.empty?
@@ -1,3 +1,3 @@
1
1
  module Completely
2
- VERSION = '0.5.4'
2
+ VERSION = '0.6.1'
3
3
  end
data/lib/completely.rb CHANGED
@@ -3,6 +3,8 @@ if ENV['BYEBUG']
3
3
  require 'lp'
4
4
  end
5
5
 
6
+ require 'completely/exceptions'
6
7
  require 'completely/pattern'
7
8
  require 'completely/completions'
8
9
  require 'completely/tester'
10
+ require 'completely/installer'
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.4
4
+ version: 0.6.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: 2023-04-21 00:00:00.000000000 Z
11
+ date: 2023-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colsole
@@ -61,17 +61,23 @@ files:
61
61
  - lib/completely/commands/install.rb
62
62
  - lib/completely/commands/preview.rb
63
63
  - lib/completely/commands/test.rb
64
+ - lib/completely/commands/uninstall.rb
64
65
  - lib/completely/completions.rb
66
+ - lib/completely/exceptions.rb
67
+ - lib/completely/installer.rb
65
68
  - lib/completely/pattern.rb
66
69
  - lib/completely/templates/sample.yaml
67
70
  - lib/completely/templates/template.erb
68
71
  - lib/completely/templates/tester-template.erb
69
72
  - lib/completely/tester.rb
70
73
  - lib/completely/version.rb
71
- homepage: https://github.com/dannyben/completely
74
+ homepage: https://github.com/DannyBen/completely
72
75
  licenses:
73
76
  - MIT
74
77
  metadata:
78
+ bug_tracker_uri: https://github.com/DannyBen/completely/issues
79
+ changelog_uri: https://github.com/DannyBen/completely/blob/master/CHANGELOG.md
80
+ source_code_uri: https://github.com/DannyBen/completely
75
81
  rubygems_mfa_required: 'true'
76
82
  post_install_message:
77
83
  rdoc_options: []
@@ -81,14 +87,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
81
87
  requirements:
82
88
  - - ">="
83
89
  - !ruby/object:Gem::Version
84
- version: 2.7.0
90
+ version: '3.0'
85
91
  required_rubygems_version: !ruby/object:Gem::Requirement
86
92
  requirements:
87
93
  - - ">="
88
94
  - !ruby/object:Gem::Version
89
95
  version: '0'
90
96
  requirements: []
91
- rubygems_version: 3.4.12
97
+ rubygems_version: 3.4.14
92
98
  signing_key:
93
99
  specification_version: 4
94
100
  summary: Bash Completions Generator