completely 0.5.3 → 0.6.0

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: a935ee0ae2ceb0c9c7b1f579c876a97068c45f133cfeaebcc2e6a6578216af22
4
- data.tar.gz: 624cc5668dd558f54aa8d66e6b6af765131c2f0a2442fe3c024247a52687a2fa
3
+ metadata.gz: b40f2059243b2820d2ce140394be5551e5ddb131351adb35d26343841f8a54c7
4
+ data.tar.gz: 71e01f5c44395f97023afff5a1822c5fa651efb98155a3b8dd05f750a19a5419
5
5
  SHA512:
6
- metadata.gz: 0a08c66582789427539a284b8b7e037643178cdfc602ea2621366fcd0de37bba34a6bd05a712ac5243e5538ddf19cc042549a9c6ecce1694cf8dabf5189f6e75
7
- data.tar.gz: e654bff7e530d8cb5414a1bcefe52081542041c57387c2b71cf61d8d49f26b2b8b5df96c648b51fa83594c828f597f8f0f814e7f6760fac3cc8f5c8fb5b76aa0
6
+ metadata.gz: 71d90d706eb26933817483395670eb5d5ed516b606b62c1f4b9408afdec92b977142e4b2501ff12b75bb47fa971e558696ef5294a3c569f3856da8cb9904254f
7
+ data.tar.gz: df1e950e2f839a977181521bb09fb917e6d47046f4f6b80d7a8dfc557b2c5d67ee66f962b7a23fd2456137a283bae6ffc9fe38e9ad97355c53c82a1ec84cff7a
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,9 +1,10 @@
1
1
  require 'mister_bin'
2
+ require 'completely/version'
3
+ require 'completely/commands/generate'
2
4
  require 'completely/commands/init'
5
+ require 'completely/commands/install'
3
6
  require 'completely/commands/preview'
4
- require 'completely/commands/generate'
5
7
  require 'completely/commands/test'
6
- require 'completely/version'
7
8
 
8
9
  module Completely
9
10
  class CLI
@@ -16,6 +17,7 @@ module Completely
16
17
  runner.route 'preview', to: Commands::Preview
17
18
  runner.route 'generate', to: Commands::Generate
18
19
  runner.route 'test', to: Commands::Test
20
+ runner.route 'install', to: Commands::Install
19
21
 
20
22
  runner
21
23
  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}`"
@@ -0,0 +1,46 @@
1
+ require 'completely/commands/base'
2
+
3
+ module Completely
4
+ module Commands
5
+ class Install < Base
6
+ summary 'Install a bash completion script'
7
+
8
+ help <<~HELP
9
+ This command will copy the specified file to one of the bash completion directories.
10
+ The target filename will be the program name, and sudo will be used if necessary.
11
+ HELP
12
+
13
+ usage 'completely install PROGRAM [SCRIPT_PATH --force --dry]'
14
+ usage 'completely install (-h|--help)'
15
+
16
+ option '-f --force', 'Overwrite target file if it exists'
17
+ option '-d --dry', 'Show the installation command but do not run it'
18
+
19
+ param 'PROGRAM', 'Name of the program the completions are for.'
20
+ param 'SCRIPT_PATH', 'Path to the source bash script [default: completely.bash].'
21
+
22
+ def run
23
+ if args['--dry']
24
+ puts installer.command_string
25
+ return
26
+ end
27
+
28
+ success = installer.install force: args['--force']
29
+ raise InstallError, "Failed running command:\nnb`#{installer.command_string}`" unless success
30
+
31
+ say "Saved m`#{installer.target_path}`"
32
+ say 'You may need to restart your session to test it'
33
+ end
34
+
35
+ private
36
+
37
+ def installer
38
+ Installer.new program: args['PROGRAM'], script_path: script_path
39
+ end
40
+
41
+ def script_path
42
+ args['SCRIPT_PATH'] || 'completely.bash'
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,4 @@
1
+ module Completely
2
+ class Error < StandardError; end
3
+ class InstallError < Error; end
4
+ end
@@ -0,0 +1,73 @@
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 command
19
+ result = root_user? ? [] : %w[sudo]
20
+ result + %W[cp #{script_path} #{target_path}]
21
+ end
22
+
23
+ def command_string
24
+ command.join ' '
25
+ end
26
+
27
+ def target_path
28
+ "#{completions_path}/#{program}"
29
+ end
30
+
31
+ def install(force: false)
32
+ unless completions_path
33
+ raise InstallError, 'Cannot determine system completions directory'
34
+ end
35
+
36
+ unless script_exist?
37
+ raise InstallError, "Cannot find script: m`#{script_path}`"
38
+ end
39
+
40
+ if target_exist? && !force
41
+ raise InstallError, "File exists: m`#{target_path}`"
42
+ end
43
+
44
+ system(*command)
45
+ end
46
+
47
+ private
48
+
49
+ def target_exist?
50
+ File.exist? target_path
51
+ end
52
+
53
+ def script_exist?
54
+ File.exist? script_path
55
+ end
56
+
57
+ def root_user?
58
+ Process.uid.zero?
59
+ end
60
+
61
+ def completions_path
62
+ @completions_path ||= completions_path!
63
+ end
64
+
65
+ def completions_path!
66
+ target_directories.each do |target|
67
+ return target if Dir.exist? target
68
+ end
69
+
70
+ nil
71
+ end
72
+ end
73
+ 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.3'
2
+ VERSION = '0.6.0'
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.3
4
+ version: 0.6.0
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-01-31 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
@@ -58,19 +58,25 @@ files:
58
58
  - lib/completely/commands/base.rb
59
59
  - lib/completely/commands/generate.rb
60
60
  - lib/completely/commands/init.rb
61
+ - lib/completely/commands/install.rb
61
62
  - lib/completely/commands/preview.rb
62
63
  - lib/completely/commands/test.rb
63
64
  - lib/completely/completions.rb
65
+ - lib/completely/exceptions.rb
66
+ - lib/completely/installer.rb
64
67
  - lib/completely/pattern.rb
65
68
  - lib/completely/templates/sample.yaml
66
69
  - lib/completely/templates/template.erb
67
70
  - lib/completely/templates/tester-template.erb
68
71
  - lib/completely/tester.rb
69
72
  - lib/completely/version.rb
70
- homepage: https://github.com/dannyben/completely
73
+ homepage: https://github.com/DannyBen/completely
71
74
  licenses:
72
75
  - MIT
73
76
  metadata:
77
+ bug_tracker_uri: https://github.com/DannyBen/completely/issues
78
+ changelog_uri: https://github.com/DannyBen/completely/blob/master/CHANGELOG.md
79
+ source_code_uri: https://github.com/DannyBen/completely
74
80
  rubygems_mfa_required: 'true'
75
81
  post_install_message:
76
82
  rdoc_options: []
@@ -80,14 +86,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
86
  requirements:
81
87
  - - ">="
82
88
  - !ruby/object:Gem::Version
83
- version: 2.7.0
89
+ version: '3.0'
84
90
  required_rubygems_version: !ruby/object:Gem::Requirement
85
91
  requirements:
86
92
  - - ">="
87
93
  - !ruby/object:Gem::Version
88
94
  version: '0'
89
95
  requirements: []
90
- rubygems_version: 3.4.5
96
+ rubygems_version: 3.4.14
91
97
  signing_key:
92
98
  specification_version: 4
93
99
  summary: Bash Completions Generator